Sha256: a685b81bc74ec2a278451fa6993a54e5102d8b6e8abce0e9d5f1de986205a62a
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
require 'faraday' require 'faraday_middleware' require 'hashie/mash' require 'cortex/faraday_middleware/response_failures' require 'cortex/faraday_middleware/normalize_uri_path' 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::Utils.default_uri_parser = Addressable::URI Faraday.new options do |conn| ## Request middleware first: conn.use Cortex::FaradayMiddleware::NormalizeURIPath conn.request :oauth2, access_token.is_a?(OAuth2::AccessToken) ? access_token.token : access_token conn.request :json ## Response middleware second: conn.response :mashify conn.use Cortex::FaradayMiddleware::ResponseFailures conn.response :json, :content_type => /\bjson$/ ## Adapter always last: conn.adapter Faraday.default_adapter end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cortex-client-0.10.2 | lib/cortex/connection.rb |
cortex-client-0.10.1 | lib/cortex/connection.rb |