Class: Ramazon::BrowseNode

Inherits:
Object
  • Object
show all
Includes:
HTTParty, HappyMapper
Defined in:
lib/ramazon/browse_node.rb

Constant Summary collapse

DEFAULT_ROOT_FILE =
File.join(File.dirname(__FILE__), '..', 'root_nodes.yml')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#childObject

Returns the value of attribute child.



12
13
14
# File 'lib/ramazon/browse_node.rb', line 12

def child
  @child
end

Class Method Details

.generate_root_nodes(file_name = DEFAULT_ROOT_FILE) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ramazon/browse_node.rb', line 16

def self.generate_root_nodes(file_name = DEFAULT_ROOT_FILE)
  if Ramazon::Configuration.locale == :us
    doc = Nokogiri::HTML(get('http://www.amazon.com').body)
    root_nodes = {}
    doc.search(".navSaMenu .navSaChildItem a").each do |element|
      if element["href"] =~ /node=(\d+)\&/
        root_nodes[element.content] = $1
      end
    end

    unless root_nodes.empty?
      FileUtils.rm_f(file_name)
      File.open(file_name, 'w') do |f|
        f.write(root_nodes.to_yaml)
      end
    end
  else
    #todo correlate ECS locales to actual amazon.* urls
    raise "generating root nodes for locale's other than the US is not supported"
  end
end

.parse(xml, options = {}) ⇒ Object



42
43
44
# File 'lib/ramazon/browse_node.rb', line 42

def self.parse(xml, options = {})
  super
end

.root_nodes(file_name = DEFAULT_ROOT_FILE) ⇒ Object



38
39
40
# File 'lib/ramazon/browse_node.rb', line 38

def self.root_nodes(file_name = DEFAULT_ROOT_FILE)
  @root_nodes ||= File.open(file_name) { |yf| YAML::load(yf) }
end