Module: Subordinate::Connection

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

Defined Under Namespace

Classes: ErrorMiddleware

Instance Method Summary collapse

Instance Method Details

#connection(options = {}) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/subordinate/connection.rb', line 8

def connection(options = {})
  options = {
    :ssl              => { :verify => false }
  }.merge(options)

  connection = Faraday.new(options) do |build|
    build.request :url_encoded
    if authenticated?
      build.request :basic_auth, self.username, self.api_token
    end
    build.response :mashify
    build.response :json, :content_type => /\bjson$/
    build.use ErrorMiddleware
    build.adapter  Faraday.default_adapter
  end

  connection
end