Sha256: 4d8c47cf4ee04ecaf63e94ce907586ad001dd9d12ec96f902d0d8bd5b5dfb318

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module FinAppsCore
  module REST
    module Connection # :nodoc:
      # @return [Faraday::Connection]
      def faraday(config, logger)
        options = connection_options config

        Faraday.new(options) do |conn|
          conn.request :accept_json
          conn.request :user_agent
          if config.valid_user_credentials?
            conn.request :no_encoding_basic_authentication, config.user_token
          else
            conn.request :tenant_authentication, config.tenant_token
          end
          conn.request :json
          conn.request :retry
          conn.request :multipart
          conn.request :url_encoded
          conn.request :request_id, config.request_id if config.request_id

          conn.use FinAppsCore::Middleware::RaiseError
          conn.response :json,
                        content_type: /\bjson$/,
                        parser_options: { symbolize_names: true }
          conn.response :logger, logger, bodies: true

          # Adapter (ensure that the adapter is always last.)
          conn.adapter Faraday.default_adapter
        end
      end
      module_function :faraday

      def connection_options(config)
        {
          url: "#{config.host}/v#{Defaults::API_VERSION}/",
          request: { open_timeout: config.timeout,
                     timeout: config.timeout }
        }
      end
      module_function :connection_options
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
finapps_core-5.0.6 lib/finapps_core/rest/connection.rb
finapps_core-5.0.5 lib/finapps_core/rest/connection.rb
finapps_core-5.0.4 lib/finapps_core/rest/connection.rb
finapps_core-5.0.3 lib/finapps_core/rest/connection.rb
finapps_core-5.0.2 lib/finapps_core/rest/connection.rb
finapps_core-5.0.1 lib/finapps_core/rest/connection.rb