Module: Simplewoo::Connection

Included in:
Client
Defined in:
lib/simplewoo/connection.rb

Defined Under Namespace

Classes: AppSecretMiddleware, ErrorMiddleware, TrustedAppMiddleware

Instance Method Summary collapse

Instance Method Details

#connection(options = {}) ⇒ Object



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

def connection(options = {})
  connection ||= Faraday.new(options) do |faraday|
    faraday.request :url_encoded
    if basic_authenticated?
      faraday.request :basic_auth, self.email, self.password
    elsif token_authenticated?
      faraday.request :basic_auth, "", self.api_token
    end
    faraday.use AppSecretMiddleware, app_secret: self.app_secret
    faraday.use TrustedAppMiddleware, trusted: self.trusted
    faraday.response :logger if self.debug
    faraday.use ErrorMiddleware
    faraday.response :mashify
    faraday.response :json, :content_type => /\bjson$/
    faraday.adapter Faraday.default_adapter
  end

  connection
end