Module: DesignerNews::Connection

Included in:
Client
Defined in:
lib/designer_news/mixins/connection.rb

Instance Method Summary collapse

Instance Method Details

#connectionObject



8
9
10
11
12
13
# File 'lib/designer_news/mixins/connection.rb', line 8

def connection
  @connection ||= Faraday.new(url: @api_endpoint, builder: @middleware) do |conn|
    conn.headers[:user_agent]     = user_agent
    conn.headers[:Authorization]  = "Bearer #{access_token}"
  end
end

#request(method, path, data, options = {}) ⇒ Object



3
4
5
6
# File 'lib/designer_news/mixins/connection.rb', line 3

def request(method, path, data, options={})
  @last_response = response = connection.send(method, URI.encode(path.to_s), data, options)
  JSON.parse(response.body)
end