Class: AmazonRequest
- Inherits:
-
Object
- Object
- AmazonRequest
- Includes:
- HTTParty
- Defined in:
- app/models/amazon_request.rb
Instance Method Summary collapse
- #generate_wishlist_rss(wishlist_ids) ⇒ Object
-
#get_amazon_feeds(email) ⇒ Object
Generate rss feeds for the give email Parameters: email: email for which to find feeds.
-
#get_customer_id(email) ⇒ Object
Get matching id for the given email Parameters: email: customer’s email.
-
#get_customer_information(customer_id) ⇒ Object
Get information for the given customer id.
-
#get_customer_wishlists(email) ⇒ Object
Get customer’s wishlist ids.
-
#initialize(amazon_access_key_id, amazon_secret_access_key, amazon_associate_tag = nil, locale = :us) ⇒ AmazonRequest
constructor
Initialize Amazon Request.
Constructor Details
#initialize(amazon_access_key_id, amazon_secret_access_key, amazon_associate_tag = nil, locale = :us) ⇒ AmazonRequest
Initialize Amazon Request. Obtain valid Amazon credentials from your developer account Parameters: amazon_access_key_id: Valid Amazon access key amazon_secret_access_key: Valid Amazon secret access key amazon_associate_tag: Valid Amazon associates tag (optional) locale: Locale for the specific amazon site to use valid values are :ca, :de, :fr, :jp, :uk, :us (optional, default is us)
11 12 13 14 15 16 |
# File 'app/models/amazon_request.rb', line 11 def initialize(amazon_access_key_id, amazon_secret_access_key, amazon_associate_tag = nil, locale = :us) @amazon_access_key_id = amazon_access_key_id @amazon_secret_access_key = amazon_secret_access_key @amazon_associate_tag = amazon_associate_tag @locale = locale end |
Instance Method Details
#generate_wishlist_rss(wishlist_ids) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'app/models/amazon_request.rb', line 54 def generate_wishlist_rss(wishlist_ids) feeds = [] wishlist_ids.each do |wishlist_id| query = "Operation=ListLookup&ListType=WishList&ListId=#{wishlist_id}&ResponseGroup=ItemAttributes,ListItems,ListInfo,Offers&Sort=DateAdded&Style=#{Amazon::ECS_TO_RSS_WISHLIST}" feeds << make_xslt_request(query) end feeds end |
#get_amazon_feeds(email) ⇒ Object
Generate rss feeds for the give email Parameters: email: email for which to find feeds.
21 22 23 24 25 26 27 |
# File 'app/models/amazon_request.rb', line 21 def get_amazon_feeds(email) wishlists = get_customer_wishlists(email) if !wishlists.blank? wishlist_ids = wishlists.collect{|list| list['ListId']} generate_wishlist_rss(wishlist_ids) end end |
#get_customer_id(email) ⇒ Object
Get matching id for the given email Parameters: email: customer’s email.
32 33 34 35 36 37 38 |
# File 'app/models/amazon_request.rb', line 32 def get_customer_id(email) query = "Operation=CustomerContentSearch&Email=#{email}" result = make_request(query) if result['CustomerContentSearchResponse']['Customers']['TotalResults'].to_i > 0 result['CustomerContentSearchResponse']['Customers']['Customer'][0] end end |
#get_customer_information(customer_id) ⇒ Object
Get information for the given customer id
41 42 43 44 |
# File 'app/models/amazon_request.rb', line 41 def get_customer_information(customer_id) query = "Operation=CustomerContentLookup&ResponseGroup=CustomerLists&CustomerId=#{customer_id}" make_request(query) end |
#get_customer_wishlists(email) ⇒ Object
Get customer’s wishlist ids
47 48 49 50 51 52 |
# File 'app/models/amazon_request.rb', line 47 def get_customer_wishlists(email) query = "Operation=ListSearch&ListType=WishList&Email=#{email}" result = make_request(query) check_errors(result) result['ListSearchResponse']['Lists']['List'] end |