Sha256: 3dc79a0aa07d3f913b605a8b9843b626ff2e655f7a1d9c721d5d9a098c7fa1fc

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

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.use ::Faraday::Request::Multipart
            connection.use ::Faraday::Request::UrlEncoded
            connection.use ::Strava::Web::Response::RaiseError
            connection.use ::FaradayMiddleware::ParseJson, content_type: /\bjson$/
            connection.response :logger, logger if logger
            connection.adapter ::Faraday.default_adapter
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
strava-ruby-client-0.4.2 lib/strava/web/connection.rb
strava-ruby-client-0.4.1 lib/strava/web/connection.rb
strava-ruby-client-0.4.0 lib/strava/web/connection.rb