Sha256: a2019e2717ed1b1002b305dad14a716fb4e17e911d6eabcffb0673256969d850

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true
module FinApps
  module REST
    module Connection # :nodoc:
      # @return [Faraday::Connection]
      def faraday(config, logger)
        options = {
          url: "#{config.host}/v#{Defaults::API_VERSION}/",
          request: {open_timeout: config.timeout,
                    timeout: config.timeout}
        }

        Faraday.new(options) do |conn|
          conn.request :accept_json
          conn.request :user_agent
          conn.request :tenant_authentication, config.tenant_identifier, config.tenant_token
          conn.request :json
          conn.request :retry
          conn.request :multipart
          conn.request :url_encoded
          conn.request :basic_auth, config.user_identifier, config.user_token if config.valid_user_credentials?

          conn.use FinApps::Middleware::RaiseError
          conn.response :rashify
          conn.response :json, content_type: /\bjson$/
          conn.response :logger, logger, bodies: (ENV['RSPEC'] != 'true')

          # Adapter (ensure that the adapter is always last.)
          conn.adapter :typhoeus
        end
      end
      module_function :faraday # becomes available as a *private instance method* to classes that mix in the module
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
finapps-2.0.13 lib/finapps/rest/connection.rb
finapps-2.0.12 lib/finapps/rest/connection.rb