Sha256: 8aa1a6b9b26c014d0cbbb148567aac57495a84852d7c2f4d4805f3bf165b5ade

Contents?: true

Size: 754 Bytes

Versions: 3

Compression:

Stored size: 754 Bytes

Contents

require 'faraday'
require 'faraday_middleware'
require 'cortex/faraday_middleware'

module Cortex
  module Connection
    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.use Cortex::FaradayMiddleware
        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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cortex-client-0.9.0 lib/cortex/connection.rb
cortex-client-0.8.2 lib/cortex/connection.rb
cortex-client-0.8.0 lib/cortex/connection.rb