Module: TorgMailruApi::Connection

Included in:
TorgMailruApi
Defined in:
lib/torg_mailru_api.rb

Instance Method Summary collapse

Instance Method Details

#connectionObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/torg_mailru_api.rb', line 20

def connection
  raise "No access token" if access_token.nil?
  @connection ||= begin
    conn = Faraday.new ENDPOINT_URI do |c|
      c.use Faraday::Response::RaiseError
      c.use :instrumentation
      c.response :json, content_type: 'application/json'
      c.response :caching, cache, strip_params: access_token unless cache.nil?
      c.response :logger, logger unless logger.nil?
      c.adapter adapter.nil? ? Faraday.default_adapter : adapter
      c.proxy proxy if not proxy.nil?
      c.headers = {
        'Accept' => 'application/json',
        'Authorization' => access_token
      }
    end
    conn
  end
end

#get(resource, params = nil) ⇒ Object



40
41
42
43
# File 'lib/torg_mailru_api.rb', line 40

def get resource, params=nil
  response = connection.get "#{resource}.json", params
  response.body
end