module TorgMailruApi::Connection

Public Instance Methods

connection() click to toggle source
# 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) click to toggle source
# File lib/torg_mailru_api.rb, line 40
def get resource, params=nil
  response = connection.get "#{resource}.json", params
  response.body
end