Class: AmazonRequest
- Inherits:
-
Object
- Object
- AmazonRequest
- Includes:
- HTTParty
- Defined in:
- lib/river/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, ecs_to_rss_wishlist, amazon_associate_tag = nil, locale = :us) ⇒ AmazonRequest
constructor
Initialize Amazon Request.
Constructor Details
#initialize(amazon_access_key_id, amazon_secret_access_key, ecs_to_rss_wishlist, 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) ecs_to_rss_wishlist: url for ecs_to_rss_wishlist stylesheet ie www.example.com/ecs_to_rss-wishlist.xslt locale: Locale for the specific amazon site to use valid values are :ca, :de, :fr, :jp, :uk, :us (optional, default is us)
12 13 14 15 16 17 18 |
# File 'lib/river/amazon_request.rb', line 12 def initialize(amazon_access_key_id, amazon_secret_access_key, ecs_to_rss_wishlist, 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 @ecs_to_rss_wishlist = ecs_to_rss_wishlist end |
Instance Method Details
#generate_wishlist_rss(wishlist_ids) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/river/amazon_request.rb', line 57 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=#{@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.
23 24 25 26 27 28 29 30 |
# File 'lib/river/amazon_request.rb', line 23 def get_amazon_feeds(email) wishlists = get_customer_wishlists(email) if !wishlists.blank? wishlists = [wishlists] unless wishlists.is_a?(Array) 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.
35 36 37 38 39 40 41 |
# File 'lib/river/amazon_request.rb', line 35 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
44 45 46 47 |
# File 'lib/river/amazon_request.rb', line 44 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
50 51 52 53 54 55 |
# File 'lib/river/amazon_request.rb', line 50 def get_customer_wishlists(email) query = "Operation=ListSearch&ListType=WishList&Email=#{email}" result = make_request(query) check_errors(result) result['ListSearchResponse']['Lists']['List'] end |