Module: Footrest::Connection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection


10
11
12
# File 'lib/footrest/connection.rb', line 10

def connection
  @connection
end

Instance Method Details

#set_connection(config) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/footrest/connection.rb', line 12

def set_connection(config)
  config[:logger] = config[:logging] if config[:logging]
  @connection = Faraday.new(url: config[:prefix]) do |faraday|
    faraday.request                     :multipart
    faraday.request                     :url_encoded
    if config[:logger] == true
      faraday.response :logger
    elsif config[:logger]
      faraday.use Faraday::Response::Logger, config[:logger]
    end
    faraday.use                         Footrest::FollowRedirects
    faraday.use                         Footrest::ParseJson, :content_type => /\bjson$/
    faraday.use                         Footrest::RaiseFootrestErrors
    faraday.use                         Footrest::Pagination
    faraday.headers[:accept]          = "application/json"
    faraday.headers[:authorization]   = "Bearer #{config[:token]}" if config[:token]
    faraday.headers[:user_agent]      = "Footrest"
    faraday.adapter                     Faraday.default_adapter
  end
end