Sha256: 5738f22f701800752aebb05ef1282d7fb8839cddd7613708a074a39ade595ac0

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module RatingChgkV2
  module Connection
    BASE_URL = 'https://api.rating.chgk.net/'

    def connection(client)
      Faraday.new(options(client), request_params_for(client)) do |faraday|
        faraday.adapter Faraday.default_adapter
        faraday.request :gzip
      end
    end

    private

    def options(client)
      headers = {
        accept: 'application/json',
        user_agent: "rating-chgk-v2 gem/#{RatingChgkV2::VERSION}",
        'Content-Type': 'application/json',
        accept_encoding: 'gzip,deflate,br'
      }

      headers = headers.merge({Authorization: "Bearer #{client.token}"}) unless client.token.to_s.empty?

      {headers: headers, url: BASE_URL}
    end

    # Allows to customize request params per-client
    def request_params_for(client)
      {request: {
        timeout: client.timeout,
        open_timeout: client.open_timeout,
        params_encoder: Faraday::FlatParamsEncoder
      }}
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rating-chgk-v2-1.6.0 lib/rating_chgk_v2/connection.rb
rating-chgk-v2-1.5.0 lib/rating_chgk_v2/connection.rb