Sha256: c4eb462778319ccd9de26a18546a4e28234ed4e674e6b3ac6fa1839c2cebcee6

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require "forwardable"
require "sqoot/offer"
require "sqoot/category"
require "sqoot/provider"
require "sqoot/commission"
require "sqoot/click"
require "sqoot/request"
require "sqoot/response/parse_gzip"

module Sqoot
  class Client
    extend Forwardable

    include Offer
    include Category
    include Provider
    include Commission
    include Click
    include Request

    attr_reader :affiliate_token, :authentication_token, :api_url

    def initialize(options={})
      @affiliate_token        = options[:affiliate_token] || Sqoot.affiliate_token
      @authentication_token   = options[:authentication_token] || Sqoot.authentication_token
      @api_url                = options[:api_url] || Sqoot.api_url
    end

    # Raw HTTP connection with Faraday::Connection
    #
    # @return [Faraday::Connection]
    def connection
      params = {}
      @connection = Faraday.new(:url => api_url, :params => params, :headers => default_headers) do |builder|
        builder.use Faraday::Response::ParseGzip
        builder.use FaradayMiddleware::FollowRedirects
        builder.adapter Faraday.default_adapter
      end
    end

    private

    def default_headers
      headers = {
        :authorization => @authentication_token,
        :accept => '*/*',
        :accept_encoding => 'gzip',
        :user_agent => 'Ruby gem'
      }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sqoot-1.0.0 lib/sqoot/client.rb