Sha256: 6be5dbd4a150141701a17b5779e61b3045b08a20299c6510906409dc907bf5a1

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

module CoinMarketCap
  module Cloud
    module Connection
      private

      def headers
        {}
      end

      def connection
        @connection ||= begin
          options = {}

          options[:headers] = {}
          options[:headers]['Accept'] = 'application/json; charset=utf-8'
          options[:headers]['Content-Type'] = 'application/json; charset=utf-8'
          options[:headers]['User-Agent'] = user_agent if user_agent
          options[:headers]['X-CMC_PRO_API_KEY'] = api_key || ''

          request_options = {}
          request_options[:params_encoder] = Faraday::FlatParamsEncoder
          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 ::CoinMarketCap::Cloud::Response::RaiseError
            connection.use ::FaradayMiddleware::ParseJson, content_type: /\bjson$/
            connection.response(:logger, logger.instance, logger.options, &logger.proc) if logger.instance
            connection.adapter ::Faraday.default_adapter
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
coinmarketcap-ruby-client-1.1.1 lib/coinmarketcap/cloud/connection.rb
coinmarketcap-ruby-client-1.1.0 lib/coinmarketcap/cloud/connection.rb
coinmarketcap-ruby-client-1.0.0 lib/coinmarketcap/cloud/connection.rb