Sha256: 2d48e6fd3af5d7b69e1972c646bf5a0087c42a7721b2b76146d7f56de1c0580f

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

module Shoppr
  class Client
    include HTTParty
    format :xml
    
    attr_reader :api_key, :tracking_id, :sandboxed, :api_version
    
    # Get your api_key found here http://developer.shopping.com/docs/Getting_Started
    def initialize(sandboxed=false)
      @api_key ||= Shoppr.api_key
      @tracking_id ||= Shoppr.tracking_id
      
      @sandboxed = sandboxed
      
      base_uri = (self.sandboxed? ? 'sandbox.api.shopping.com/publisher/3.0/rest' : 'publisher.usb.api.shopping.com/publisher/3.0/rest')
      self.class.base_uri base_uri
    end
    
    def sandboxed?
      !!@sandboxed
    end
    
    def generic_response
      @generic_response ||= GenericResponse.new()
    end
    
    def api_version
      # self.class.parser Proc.new {|response| GenericResponse.from_xml(response)}
      # @api_version ||= self.class.get('/').server_detail.api_version
      @api_version ||= generic_response.server_detail.api_version
      
    end
    
    def search(options={})
      # self.class.parser Proc.new {|response| GeneralSearchResponse.parse_search_results(response)}
      response = GeneralSearchResponse.new(default_options.merge(prep_query_options(options))) 
    end
    
    
    private
      def default_options
        {:apiKey => self.api_key, :trackingId => self.tracking_id, :groupItemsByCategory => true}
      end
      
      def prep_query_options(options)
        opts = {}
        options.each do |key, value|
          opts[key.to_s.camelize(:lower)] = value
        end
        opts
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoppr-0.2.3 lib/shoppr/client.rb