Module: Bigcommerce::Connection

Defined in:
lib/bigcommerce/connection.rb

Constant Summary collapse

HEADERS =
{
  'accept' => 'application/json',
  'content-type' => 'application/json',
  'user-agent' => 'bigcommerce-api-ruby',
  'accept-encoding' => 'gzip'
}.freeze

Class Method Summary collapse

Class Method Details

.build(config) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bigcommerce/connection.rb', line 10

def self.build(config)
  ssl_options = config.ssl || {}
  Faraday.new(url: config.api_url, ssl: ssl_options) do |conn|
    conn.request :json
    conn.headers = HEADERS
    if config.auth == 'legacy'
      conn.use Faraday::Request::BasicAuthentication, config.username, config.api_key
    else
      conn.use Bigcommerce::Middleware::Auth, config
    end
    conn.use Bigcommerce::Middleware::HttpException
    conn.use FaradayMiddleware::Gzip
    conn.adapter Faraday.default_adapter
  end
end