Sha256: 924cda6f6cd3cd53075567c429ed32bb1c1cbe4e91f2fb107455d81393d59ecd

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

# encoding: utf-8
require 'forwardable'
require 'viglink_api/request'
require 'viglink_api/product'
require 'viglink_api/deal'
require 'viglink_api/merchant'
require 'viglink_api/country'

module ViglinkApi
  class Client
    extend Forwardable

    include Request
    include Product
    include Deal
    include Merchant
    include Country

    attr_reader :api_key, :api_url, :api_full_response

    ##
    # Create a new Viglink::Client object
    #
    # @params options [Hash]
    def initialize(options={})
      @api_key = options[:api_key] || ViglinkApi.api_key
      @api_url = options[:api_url] || ViglinkApi.api_url
      @api_full_response = options[:api_full_response] || ViglinkApi.api_full_response
    end

    ##
    # Create a Faraday::Connection object
    #
    # @return [Faraday::Connection]
    def connection
      params = {}
      @connection = Faraday.new(url: api_url, params: params, headers: default_headers) do |faraday|
        faraday.use FaradayMiddleware::Mashify
        faraday.use FaradayMiddleware::ParseXml, content_type: /\bxml$/
        # faraday.request :url_encoded
        faraday.adapter Faraday.default_adapter
      end
    end

    private

    def default_headers
      headers = {
        accept: '*/*',
        content_type: 'text/xml',
        user_agent: "Ruby Gem #{ViglinkApi::VERSION}"
      }
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
viglink-api-0.1.1 lib/viglink_api/client.rb
viglink-api-0.1.0 lib/viglink_api/client.rb