Class: AmazonProductAdvertisingApi::Operations::BrowseNode::BrowseNodeLookup
- Inherits:
-
AmazonProductAdvertisingApi::Operations::Base::Request
- Object
- AmazonProductAdvertisingApi::Operations::Base::Request
- AmazonProductAdvertisingApi::Operations::BrowseNode::BrowseNodeLookup
- Defined in:
- lib/amazon_product_advertising_api/operations/browse_node.rb
Overview
A class to represent the BrowseNodeLookup Operation. See AmazonProductAdvertisingApi::Operations::Base::Request for info relating to all Requests.
Constant Summary collapse
- REQUEST_PARAMETERS =
:browse_node_id, :response_group
Constants inherited from AmazonProductAdvertisingApi::Operations::Base::Request
AmazonProductAdvertisingApi::Operations::Base::Request::API_VERSION, AmazonProductAdvertisingApi::Operations::Base::Request::SERVICE_URLS
Instance Attribute Summary
Attributes inherited from AmazonProductAdvertisingApi::Operations::Base::Request
#errors, #hpricot_data, #is_valid, #operation, #raw_data, #region, #request_uri, #response
Instance Method Summary collapse
-
#initialize(browse_node_id, region = :uk) ⇒ BrowseNodeLookup
constructor
BrowseNodeLookup only requires a browse_node_id to be specified.
-
#parse ⇒ Object
BrowseNode methods return xml consisting of a BrowseNodes tag with several BrowseNode tags inside.
Methods inherited from AmazonProductAdvertisingApi::Operations::Base::Request
Constructor Details
#initialize(browse_node_id, region = :uk) ⇒ BrowseNodeLookup
BrowseNodeLookup only requires a browse_node_id to be specified.
15 16 17 18 19 20 21 |
# File 'lib/amazon_product_advertising_api/operations/browse_node.rb', line 15 def initialize(browse_node_id, region = :uk) super() self.browse_node_id = browse_node_id self.operation = "BrowseNodeLookup" self.region = region end |
Instance Method Details
#parse ⇒ Object
BrowseNode methods return xml consisting of a BrowseNodes tag with several BrowseNode tags inside.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/amazon_product_advertising_api/operations/browse_node.rb', line 24 def parse self.response.add_element("BrowseNodes", AmazonProductAdvertisingApi::Operations::Base::Element.new) (self.hpricot_data/'BrowseNodes > BrowseNode').each do |element| new_element = AmazonProductAdvertisingApi::Operations::Base::Element.new self.response.browse_nodes << new_element queue = [] queue << [new_element, element.containers] queue.each do |pair| current_element = pair[0] current_children = pair[1] current_children.each do |child| if child.containers.size == 0 current_element.add_element(child.name, child.inner_html) else if parent_a_container?(child) new_element = AmazonProductAdvertisingApi::Operations::Base::Element.new current_element << new_element queue << [new_element, child.containers] else new_element = current_element.add_element(child.name, AmazonProductAdvertisingApi::Operations::Base::Element.new) queue << [new_element, child.containers] end end end end end end |