Sha256: d3e9c575a713efaedf3b8ae1c4422476f4a414a285f1cff36b0ffbe61fe6d01a

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

require 'faraday_middleware'
require 'faraday/request/gateway'
require 'faraday/request/basic_auth'
require 'faraday/response/raise_http_4xx'
require 'faraday/response/raise_http_5xx'
require 'faraday/response/strip_card_numbers'

module Cashstar
  # @private
  module Connection
    private

    def connection(options={})
      merged_options = faraday_options.merge({
        :headers => {
          'Accept'       => "application/json",
          'User-Agent'   => user_agent,
          'Content-Type' => "application/json"
        },
        :ssl => {:verify => false},
        :url => options.fetch(:endpoint, api_endpoint)
      })

      Faraday.new(merged_options) do |builder|
        builder.use Faraday::Request::BasicAuth, authentication if authenticated?
        builder.use Faraday::Request::UrlEncoded
        builder.use Faraday::Response::RaiseHttp4xx
        unless return_card_numbers
          builder.use Faraday::Response::StripCardNumbers 
        end
        unless options[:raw]
          case options.fetch(:format, format).to_s.downcase
          when 'json'
            builder.use Faraday::Response::Mashify
            builder.use Faraday::Response::ParseJson
          when 'xml'
            builder.use Faraday::Response::Mashify
            builder.use Faraday::Response::ParseXml
          end
        end
        builder.use Faraday::Response::RaiseHttp5xx
        builder.adapter(adapter)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cashstar-ruby-0.2.4 lib/cashstar/connection.rb
cashstar-ruby-0.2.3 lib/cashstar/connection.rb
cashstar-ruby-0.2.2 lib/cashstar/connection.rb
cashstar-ruby-0.2.1 lib/cashstar/connection.rb
cashstar-ruby-0.2.0 lib/cashstar/connection.rb
cashstar-ruby-0.1.8 lib/cashstar/connection.rb
cashstar-ruby-0.1.7 lib/cashstar/connection.rb