dpickett-ramazon_advertising 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -21,6 +21,8 @@ Currently only supports product search and retrieval. Requests are signed proper
21
21
  #you can also use a nokogiri search string to get elements that don't have built-in accessors
22
22
  @products[0].get("ItemAttributes Actor").collect{|a| a.content}
23
23
 
24
+ More documentation at http://rdoc.info/projects/dpickett/ramazon_advertising
25
+
24
26
  == What's under the hood?
25
27
 
26
28
  * HTTParty
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -7,6 +7,7 @@ Feature: Retrieving a product
7
7
  Given I have a valid access key
8
8
  And I have a valid secret key
9
9
 
10
+ Scenario: Finding a DVD
10
11
  When I try to find the asin "B000NU2CY4"
11
12
  Then I should get a product
12
13
  And the product should have the "title" "Gladiator [Blu-ray]"
@@ -19,5 +20,13 @@ Feature: Retrieving a product
19
20
  And the product should have a "lowest_new_price"
20
21
  And the product should have a "new_count"
21
22
  And the product should have a "used_count"
22
-
23
23
 
24
+ Scenario: Finding a Video Game with a deep category tree
25
+ When I try to find the asin "B001COQW14"
26
+ Then I should get a product
27
+ And the product should have a category tree for "Categories"
28
+
29
+ Scenario: Finding a Movie with a Genre tree
30
+ When I try to find the asin "B002CMLIJ6"
31
+ Then I should get a product
32
+ And the product should have a category tree for "Genres"
@@ -1,5 +1,5 @@
1
1
  When /^I try to find the asin "([^\"]*)"$/ do |asin|
2
- @products = Ramazon::Product.find(:item_id => asin, :response_group => "Medium")
2
+ @products = Ramazon::Product.find(:item_id => asin, :response_group => ["Medium", "BrowseNodes"])
3
3
  @product = @products[0]
4
4
  end
5
5
 
@@ -46,3 +46,7 @@ Then /^the product should have a "([^\"]*)"$/ do |attr|
46
46
  @product.send(attr).should_not be_nil
47
47
  end
48
48
 
49
+ Then /^the product should have a category tree for "([^\"]*)"$/ do |category_name|
50
+ @product.category_tree[category_name].should_not be_nil
51
+ end
52
+
@@ -1,8 +1,18 @@
1
1
  module Ramazon
2
2
  class BrowseNode
3
3
  include HTTParty
4
+ include HappyMapper
4
5
 
6
+ tag "BrowseNode"
7
+
8
+ element :name, String, :tag => "Name"
9
+ element :node_id, String, :tag => "BrowseNodeId"
10
+ element :is_category_root, Boolean, :tag => "IsCategoryRoot"
11
+
12
+ attr_accessor :child
13
+
5
14
  DEFAULT_ROOT_FILE = File.join(File.dirname(__FILE__), '..', 'root_nodes.yml')
15
+
6
16
  def self.generate_root_nodes(file_name = DEFAULT_ROOT_FILE)
7
17
  if Ramazon::Configuration.locale == :us
8
18
  doc = Nokogiri::HTML(get('http://www.amazon.com').body)
@@ -28,5 +38,9 @@ module Ramazon
28
38
  def self.root_nodes(file_name = DEFAULT_ROOT_FILE)
29
39
  @root_nodes ||= File.open(file_name) { |yf| YAML::load(yf) }
30
40
  end
41
+
42
+ def self.parse(xml, options = {})
43
+ super
44
+ end
31
45
  end
32
46
  end
@@ -41,12 +41,12 @@ module Ramazon
41
41
  # +original_release_date+::
42
42
  # The original release date of the product
43
43
  # @example find an individual item
44
- # @products = Ramazon::Product.find(:item_id => "B000NU2CY4", :response_group => "Medium")
45
- # @products[0].title
46
- # @products[0].asin
47
- # @products[0].upc
48
- # @products[0].large_image.url
49
- # @products[0].url
44
+ # @products = Ramazon::Product.find(:item_id => "B000NU2CY4", :response_group => "Medium")
45
+ # @products[0].title
46
+ # @products[0].asin
47
+ # @products[0].upc
48
+ # @products[0].large_image.url
49
+ # @products[0].url
50
50
  #
51
51
 
52
52
  class Product
@@ -140,5 +140,39 @@ module Ramazon
140
140
  def get(*args)
141
141
  result = @xml_doc.search(args)
142
142
  end
143
+
144
+ # returns a hash of category browse nodes from the top down
145
+ def category_tree
146
+ @category_tree = {}
147
+ get_category_browse_nodes.each do |n|
148
+ build_category_tree(n)
149
+ end
150
+ @category_tree
151
+ end
152
+
153
+ private
154
+ # recursive function used to generate a topdown category tree
155
+ def build_category_tree(n, child = nil)
156
+ amz_node = BrowseNode.parse(n.to_s)
157
+ amz_node.child = child unless child.nil?
158
+
159
+ if n.search("./IsCategoryRoot").size > 0
160
+ @category_tree[amz_node.name] ||= []
161
+ @category_tree[amz_node.name] << amz_node
162
+ else
163
+ parents = n.search("./Ancestors/BrowseNode")
164
+ if parents.size > 0
165
+ build_category_tree(parents[0], amz_node)
166
+ end
167
+ end
168
+
169
+
170
+ end
171
+
172
+ def get_category_browse_nodes
173
+ self.get("BrowseNodes BrowseNode IsCategoryRoot").collect do |n|
174
+ n.ancestors("//BrowseNodes/BrowseNode")
175
+ end
176
+ end
143
177
  end
144
178
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ramazon_advertising}
5
- s.version = "0.1.1"
5
+ s.version = "0.2.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Dan Pickett"]
9
- s.date = %q{2009-09-08}
9
+ s.date = %q{2009-09-09}
10
10
  s.description = %q{TODO: longer description of your gem}
11
11
  s.email = %q{dpickett@enlightsolutions.com}
12
12
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dpickett-ramazon_advertising
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Pickett
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-08 00:00:00 -07:00
12
+ date: 2009-09-09 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency