Sha256: fc3940789030667462d82ab0f6d919fcbd03f06eebaf149540b394193145db07
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
module Sterling module API class Product attr_reader :product, :distance, :location, :inventory, :price, :currency, :inventory, :lastUpdated def self.search(client, params) return [] unless params[:keywords] && params[:user_location] && params[:requestor_id] response = client.conn.get do |req| req.url 'products' req.params['apikey'] = client.config.api_key req.params['userlocation'] = params[:user_location] req.params['requestorid'] = params[:requestor_id] req.params['keywords'] = params[:keywords] end parsed = JSON.parse(response.body) if !parsed['RetailigenceSearchResult'].nil? && parsed['RetailigenceSearchResult']['results'] && parsed['RetailigenceSearchResult']['results'].size > 0 products = parsed['RetailigenceSearchResult']['results'].map do |product| Product.new(product['SearchResult']) end else [] end end def initialize(object) object.each do |k,v| self.class.class_eval { attr_reader k.to_sym } instance_variable_set "@#{k}", object[k] end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sterling-1.1.2 | lib/sterling/api/product.rb |