Sha256: d3bf497894ef8804a07b40e77122935d8cc27a9c4044ba477879017990df0cf6

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 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,
        :connection_options => CONNECTION_OPTIONS
      }
    end

    def self.template
      template = options.dup
      template[:middleware] = options[:middleware].dup
      template[:connection_options] = options[:connection_options].dup

      template
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tango-client-1.0.2 lib/tango/default.rb