Class: Sterling::API::Product
- Inherits:
-
Object
- Object
- Sterling::API::Product
- Defined in:
- lib/sterling/api/product.rb
Instance Attribute Summary collapse
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#distance ⇒ Object
readonly
Returns the value of attribute distance.
-
#inventory ⇒ Object
readonly
Returns the value of attribute inventory.
-
#lastUpdated ⇒ Object
readonly
Returns the value of attribute lastUpdated.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#price ⇒ Object
readonly
Returns the value of attribute price.
-
#product ⇒ Object
readonly
Returns the value of attribute product.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(object) ⇒ Product
constructor
A new instance of Product.
Constructor Details
#initialize(object) ⇒ Product
Returns a new instance of Product.
28 29 30 31 32 33 |
# File 'lib/sterling/api/product.rb', line 28 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 |
Instance Attribute Details
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
4 5 6 |
# File 'lib/sterling/api/product.rb', line 4 def currency @currency end |
#distance ⇒ Object (readonly)
Returns the value of attribute distance.
4 5 6 |
# File 'lib/sterling/api/product.rb', line 4 def distance @distance end |
#inventory ⇒ Object (readonly)
Returns the value of attribute inventory.
4 5 6 |
# File 'lib/sterling/api/product.rb', line 4 def inventory @inventory end |
#lastUpdated ⇒ Object (readonly)
Returns the value of attribute lastUpdated.
4 5 6 |
# File 'lib/sterling/api/product.rb', line 4 def lastUpdated @lastUpdated end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
4 5 6 |
# File 'lib/sterling/api/product.rb', line 4 def location @location end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
4 5 6 |
# File 'lib/sterling/api/product.rb', line 4 def price @price end |
#product ⇒ Object (readonly)
Returns the value of attribute product.
4 5 6 |
# File 'lib/sterling/api/product.rb', line 4 def product @product end |
Class Method Details
.search(client, params) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sterling/api/product.rb', line 6 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']['results'] && parsed['RetailigenceSearchResult']['results'].size > 0 products = parsed['RetailigenceSearchResult']['results'].map do |product| Product.new(product['SearchResult']) end else [] end end |