Sha256: 05d779519763dffa96dfa62f5a35007945b74a8fb729c01a4b06077669eadf3f

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

require 'tango/version'
require 'tango/error'
require 'tango/request/json_encoded'
require 'tango/response/parse_json'
require 'tango/response/raise_error'
require 'faraday'

module Tango
  module Default
    INTEGRATION_ENDPOINT = 'https://int.tangocard.com' unless defined?(::Tango::Default::INTEGRATION_ENDPOINT)
    PRODUCTION_ENDPOINT = 'https://api.tangocard.com' unless defined?(::Tango::Default::PRODUCTION_ENDPOINT)

    ENDPOINT = INTEGRATION_ENDPOINT unless defined?(::Tango::Default::ENDPOINT)

    MIDDLEWARE = Faraday::Builder.new do |builder|
      # Encode request params into JSON for PUT/POST requests
      builder.use ::Tango::Request::JsonEncoded

      builder.use ::Tango::Response::RaiseError, ::Tango::Error::ClientError

      # Parse response JSON
      builder.use ::Tango::Response::ParseJson

      builder.use ::Tango::Response::RaiseError, ::Tango::Error::ServerError

      builder.adapter Faraday.default_adapter

    end unless defined?(::Tango::Default::MIDDLEWARE)

    CONNECTION_OPTIONS = {
      :headers => {
        :accept => 'application/json',
        :user_agent => "TangoClient Ruby Gem #{::Tango::VERSION}"
      },
      :open_timeout => 5,
      :raw => true,
      :ssl => {
        :ca_file => File.expand_path('../ssl/cacert.pem')
      },
      :timeout => 10,
    } unless defined?(::Tango::Default::CONNECTION_OPTIONS)

    VERSION = 'Version2' unless defined?(::Tango::Default::VERSION)

    def self.options
      @options ||= {
        :username => ENV['TANGO_USERNAME'] || 'third_party_int@tangocard.com',
        :password => ENV['TANGO_PASSWORD'] || 'integrateme',
        :endpoint => ENV['TANGO_ENDPOINT'] || ENDPOINT,
        :version => VERSION,
        :middleware => MIDDLEWARE.dup,
        :connection_options => CONNECTION_OPTIONS.clone
      }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tango-client-1.0.1 lib/tango/default.rb
tango-client-1.0.0 lib/tango/default.rb