Sha256: 5cfeba1f77f7526f8d1238511ed3489d357dd529144621c249f28de80ef08ea1

Contents?: true

Size: 870 Bytes

Versions: 2

Compression:

Stored size: 870 Bytes

Contents

# frozen_string_literal: true

module FunTranslations
  # This module prepares a connection object
  module Connection
    BASE_URL = 'https://api.funtranslations.com'

    # Prepares a new connection object
    # @param client [FunTranslations::Client]
    def connection(client)
      Faraday.new(options(client)) do |faraday|
        faraday.adapter Faraday.default_adapter
        faraday.request :url_encoded
      end
    end

    private

    def options(client)
      headers = {
        accept: 'application/json',
        'Content-Type' => 'application/x-www-form-urlencoded',
        user_agent: "fun_translations gem/#{FunTranslations::VERSION}"
      }

      headers['X-Funtranslations-Api-Secret'] = client.token unless client.token.nil?

      {
        headers: headers,
        url: BASE_URL
      }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fun_translations-0.0.1 lib/fun_translations/connection.rb
fun_translations-0.0.1.rc1 lib/fun_translations/connection.rb