summaryrefslogtreecommitdiff
path: root/sample/wsdl/amazon/wsdlDriver.rb
blob: 6b2dce376ba448db7c4ccdc6d36f5f81fb5fcd74 (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'soap/wsdlDriver'

book = ARGV.shift || "Ruby"

# AmazonSearch.rb is generated from WSDL.
# Run "wsdl2ruby.rb --wsdl http://soap.amazon.com/schemas3/AmazonWebServices.wsdl --classdef --force"
# http://soap.amazon.com/schemas3/AmazonWebServices.wsdl
require 'AmazonSearch.rb'

=begin
Or, define the class by yourself like this.

class KeywordRequest
  def initialize(keyword = nil,
      page = nil,
      mode = nil,
      tag = nil,
      type = nil,
      devtag = nil,
      sort = nil)
    @keyword = keyword
    @page = page
    @mode = mode
    @tag = tag
    @type = type
    @devtag = devtag
    @sort = sort
  end
end
=end

# You must get 'developer's token" from http://associates.amazon.com/exec/panama/associates/ntg/browse/-/1067662 to use Amazon Web Services 2.0.
#devtag = File.open(File.expand_path("~/.amazon_key")) { |f| f.read }.chomp
devtag = nil

# v2: AMAZON_WSDL = 'http://soap.amazon.com/schemas2/AmazonWebServices.wsdl'
AMAZON_WSDL = 'http://soap.amazon.com/schemas3/AmazonWebServices.wsdl'
amazon = SOAP::WSDLDriverFactory.new(AMAZON_WSDL).create_driver
p "WSDL loaded"
amazon.generate_explicit_type = true
#amazon.wiredump_dev = STDERR

# Show sales rank.
req = KeywordRequest.new(book, "1", "books", "webservices-20", "lite", devtag, "+salesrank")
amazon.KeywordSearchRequest(req).Details.each do |detail|
  puts "== #{detail.ProductName}"
  puts "Author: #{detail.Authors.join(", ")}"
  puts "Release date: #{detail.ReleaseDate}"
  puts "List price: #{detail.ListPrice}, our price: #{detail.OurPrice}"
  puts
end