Class: EbayProducts
- Inherits:
-
Object
- Object
- EbayProducts
- Includes:
- HTTParty
- Defined in:
- lib/ebay_products.rb,
lib/ebay_products/data.rb
Defined Under Namespace
Classes: Data, ProductInformation
Instance Attribute Summary collapse
-
#appid ⇒ Object
readonly
Returns the value of attribute appid.
-
#product_id ⇒ Object
readonly
Returns the value of attribute product_id.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
-
#initialize(args, appid) ⇒ EbayProducts
constructor
A new instance of EbayProducts.
- #options ⇒ Object
- #product ⇒ Object
- #products ⇒ Object
- #search ⇒ Object
Constructor Details
#initialize(args, appid) ⇒ EbayProducts
Returns a new instance of EbayProducts.
15 16 17 18 19 |
# File 'lib/ebay_products.rb', line 15 def initialize(args, appid) @query = args[:keywords] @product_id = args[:product_id] @appid = appid end |
Instance Attribute Details
#appid ⇒ Object (readonly)
Returns the value of attribute appid.
13 14 15 |
# File 'lib/ebay_products.rb', line 13 def appid @appid end |
#product_id ⇒ Object (readonly)
Returns the value of attribute product_id.
13 14 15 |
# File 'lib/ebay_products.rb', line 13 def product_id @product_id end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
13 14 15 |
# File 'lib/ebay_products.rb', line 13 def query @query end |
Instance Method Details
#options ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ebay_products.rb', line 44 def hash = {:appid => @appid} if @product_id hash['ProductID.value'.to_sym] = @product_id hash['ProductID.type'.to_sym] = 'Reference' # assumes product id is of type reference else hash[:QueryKeywords] = @query end hash end |
#product ⇒ Object
40 41 42 |
# File 'lib/ebay_products.rb', line 40 def product products.first end |
#products ⇒ Object
36 37 38 |
# File 'lib/ebay_products.rb', line 36 def products @products ||= search.collect {|product| ProductInformation.new(product) } end |
#search ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ebay_products.rb', line 21 def search if @search.blank? response = self.class.get("/shopping", :query => , :format => :xml)["FindProductsResponse"] errors = response['Errors'] if errors raise SearchFailure, errors['LongMessage'] end @search = response["Product"] if @search.is_a? Hash @search = [@search] end end @search end |