File: amazon.rb

package info (click to toggle)
ruby-roxml 4.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 800 kB
  • sloc: ruby: 4,133; xml: 1,013; makefile: 7
file content (35 lines) | stat: -rwxr-xr-x 1,045 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env ruby
require_relative './../spec/spec_helper'

# The document `pita.xml` contains both a default namespace and the 'georss'
# namespace (for the 'point' xml_reader).
module PITA
  class Base
    include ROXML
    xml_convention :camelcase
  end

  class Item < Base
    xml_reader :asin, :from => 'ASIN'
    xml_reader :detail_page_url, :from => 'DetailPageURL'
    xml_reader :manufacturer, :in => 'ItemAttributes'
    # this is the only xml_reader that exists in a different namespace, so it
    # must be explicitly specified
    xml_reader :point, :namespace => 'georss'
  end

  class ItemSearchResponse < Base
    xml_reader :total_results, :as => Integer, :in => 'Items'
    xml_reader :total_pages, :as => Integer, :in => 'Items'
    xml_reader :items, :as => [Item]
  end
end

unless defined?(RSpec)
  response = PITA::ItemSearchResponse.from_xml(xml_for('amazon'))
  p response.total_results
  p response.total_pages 
  response.items.each do |i|
    puts i.asin, i.detail_page_url, i.manufacturer, i.point, ''
  end
end