Module: F00px::Connection

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

Instance Method Summary collapse

Instance Method Details

#connectionObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/f00px/connection.rb', line 4

def connection
  options = {
    headers: {'Accept' => "application/json"},
    url: "#{endpoint}/#{api_version}"
  }

  Faraday.new(options) do |builder|

    if middleware?
      args = Array(middleware)
      if args.first == ::FaradayMiddleware::OAuth
        tokens = credentials.dup
        tokens.merge!(args.last) if args.length > 1
        builder.use(args.first, tokens)
      else
        builder.use(*middleware)
      end
    end

    builder.request :url_encoded

    builder.use Faraday::Response::Logger, logger if logger?

    builder.adapter *faraday_adapter
  end
end