Module: Cortex::Connection

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

Instance Method Summary collapse

Instance Method Details

#connectionObject



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

def connection
  options = {
    :headers => {
      :user_agent => "cortex-client (Ruby) - #{Cortex::VERSION}"
    },
    :url => base_url
  }

  if access_token.is_a?(OAuth2::AccessToken) && access_token.expired?
    @access_token = get_cc_token
  end

  Faraday.new options do |conn|
    conn.request :oauth2, access_token.is_a?(OAuth2::AccessToken) ? access_token.token : access_token
    conn.request :json
    conn.response :json, :content_type => /\bjson$/
    conn.adapter Faraday.default_adapter
  end
end