Sha256: f9ef61bb010e150587b457dcfbdb10b14b0a7bfad37406af64d4025b9594dece

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Strava
  module Web
    module Connection
      private

      def headers
        {}
      end

      def connection
        @connection ||= begin
          options = {
            headers: headers.merge('Accept' => 'application/json; charset=utf-8')
          }

          options[:headers]['User-Agent'] = user_agent if user_agent
          options[:proxy] = proxy if proxy
          options[:ssl] = { ca_path: ca_path, ca_file: ca_file } if ca_path || ca_file

          request_options = {}
          request_options[:timeout] = timeout if timeout
          request_options[:open_timeout] = open_timeout if open_timeout
          options[:request] = request_options if request_options.any?

          ::Faraday::Connection.new(endpoint, options) do |connection|
            connection.request :multipart
            connection.request :url_encoded
            connection.use Strava::Web::RaiseResponseError
            connection.response :json
            connection.response :logger, logger if logger
            connection.adapter ::Faraday.default_adapter
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
strava-ruby-client-2.2.0 lib/strava/web/connection.rb
strava-ruby-client-2.1.0 lib/strava/web/connection.rb
strava-ruby-client-2.0.0 lib/strava/web/connection.rb
strava-ruby-client-1.1.0 lib/strava/web/connection.rb
strava-ruby-client-1.0.1 lib/strava/web/connection.rb
strava-ruby-client-1.0.0 lib/strava/web/connection.rb