Trying to build Amazon Web Service class using SOAP4R

Hello-

I’m working on a class to provide easy access to the Amazon Web Service
API (http://www.amazon.com/webservices/), and am having some weird
results using SOAP4R. Admittedly, this is the first time I’ve done
anything with SOAP, so I have limtied understanding, but I believe I’m
getting some sort of error in the SOAP4R library, rather than an error
from Amazon’s interface.

Here’s a simple program that I’ve written to access the interface:

#!/usr/local/bin/ruby
require ‘soap/driver’

soap = SOAP::Driver.new(nil, nil, ‘http://soap.amazon.com’,
http://soap.amazon.com/onca/soap2’)
soap.addMethodWithSOAPAction(‘KeywordSearchRequest’,
http://soap.amazon.com’,
‘type’, ‘tag’, ‘devtag’,
‘mode’, ‘keyword’)
r = soap.send(‘KeywordSearchRequest’, ‘soap’, ‘cyalchemy’,
‘D3OSAD7T5NR887’, ‘books’, ‘dogs’)

p r

My response ends up being:

: Can’t use string (“soap”) as a HASH ref while “strict refs” in use
(SOAP::FaultError)

Does this make any sense to anybody?

FYI- The WSDL for Amazon’s Web Service API can be found at:
http://soap.amazon.com/schemas/AmazonWebServices.wsdl

Any help would be greatly appreciated.

bs.

Sorry, it appears I had the address wrong for that WSDL, its actually
at: http://soap.amazon.com/schemas2/AmazonWebServices.wsdl

Cheers,

bs.

Ben Schumacher wrote:

···

Hello-

I’m working on a class to provide easy access to the Amazon Web Service
API (Cloud Computing Services - Amazon Web Services (AWS)), and am having some weird
results using SOAP4R. Admittedly, this is the first time I’ve done
anything with SOAP, so I have limtied understanding, but I believe I’m
getting some sort of error in the SOAP4R library, rather than an error
from Amazon’s interface.

Here’s a simple program that I’ve written to access the interface:

#!/usr/local/bin/ruby
require ‘soap/driver’

soap = SOAP::Driver.new(nil, nil, ‘http://soap.amazon.com’,
http://soap.amazon.com/onca/soap2’)
soap.addMethodWithSOAPAction(‘KeywordSearchRequest’,
http://soap.amazon.com’,
‘type’, ‘tag’, ‘devtag’,
‘mode’, ‘keyword’)
r = soap.send(‘KeywordSearchRequest’, ‘soap’, ‘cyalchemy’,
‘D3OSAD7T5NR887’, ‘books’, ‘dogs’)

p r

My response ends up being:

: Can’t use string (“soap”) as a HASH ref while “strict refs” in use
(SOAP::FaultError)

Does this make any sense to anybody?

FYI- The WSDL for Amazon’s Web Service API can be found at:
http://soap.amazon.com/schemas/AmazonWebServices.wsdl

Any help would be greatly appreciated.

bs.

After further investigation, I was able to use the WSDLDriverFactory to
build a class for accessing Amazon’s Web Services. The only problem with
this is that it appears that Amazon uses messages with complexType
parts, which I haven’t figured out how to build. I’m working my way
through the library right now, but I was hoping somebody could help me
speed the process.

Thanks for your help,

bs.

Ben Schumacher wrote:

···

Hello-

I’m working on a class to provide easy access to the Amazon Web Service
API (Cloud Computing Services - Amazon Web Services (AWS)), and am having some weird
results using SOAP4R. Admittedly, this is the first time I’ve done
anything with SOAP, so I have limtied understanding, but I believe I’m
getting some sort of error in the SOAP4R library, rather than an error
from Amazon’s interface.

Here’s a simple program that I’ve written to access the interface:

#!/usr/local/bin/ruby
require ‘soap/driver’

soap = SOAP::Driver.new(nil, nil, ‘http://soap.amazon.com’,
http://soap.amazon.com/onca/soap2’)
soap.addMethodWithSOAPAction(‘KeywordSearchRequest’,
http://soap.amazon.com’,
‘type’, ‘tag’, ‘devtag’,
‘mode’, ‘keyword’)
r = soap.send(‘KeywordSearchRequest’, ‘soap’, ‘cyalchemy’,
‘D3OSAD7T5NR887’, ‘books’, ‘dogs’)

p r

My response ends up being:

: Can’t use string (“soap”) as a HASH ref while “strict refs” in use
(SOAP::FaultError)

Does this make any sense to anybody?

FYI- The WSDL for Amazon’s Web Service API can be found at:
http://soap.amazon.com/schemas/AmazonWebServices.wsdl

Any help would be greatly appreciated.

bs.

My response ends up being:
: Can’t use string (“soap”) as a HASH ref while “strict refs” in use

(SOAP::FaultError)

That’s a Perl error-- so I think the following is false:

···

On Monday 10 February 2003 05:21 pm, Ben Schumacher wrote:

I believe I’m
getting some sort of error in the SOAP4R library, rather than an error
from Amazon’s interface.


Bruce R. Williams :: [iusris/#ruby-lang] :: http://www.codedbliss.com

‘It does not require a majority to prevail, but rather an irate,
tireless minority keen to set brush fires in people’s minds.’
– Samuel Adams

Hi,

From: “Ben Schumacher” ben@blahr.com
Sent: Tuesday, February 11, 2003 8:49 AM

After further investigation, I was able to use the WSDLDriverFactory to
build a class for accessing Amazon’s Web Services. The only problem with
this is that it appears that Amazon uses messages with complexType
parts, which I haven’t figured out how to build. I’m working my way
through the library right now, but I was hoping somebody could help me
speed the process.

Oops. I found that I didn’t commit soap4r/sample/Amazon/* files before
releasing soap4r/1.4.8…

Try
$ /bin/wsdl2ruby.rb --wsdl http://soap.amazon.com/schemas2/AmazonWebServices.wsdl --classDef --force

It should create AmazonSearch.rb in the current directory.

Regards,
// NaHi

NAKAMURA, Hiroshi wrote:

Oops. I found that I didn’t commit soap4r/sample/Amazon/* files before
releasing soap4r/1.4.8…

Try
$ /bin/wsdl2ruby.rb --wsdl http://soap.amazon.com/schemas2/AmazonWebServices.wsdl --classDef --force

It should create AmazonSearch.rb in the current directory.

Regards,
// NaHi

So I just fill in the details on these classes and send it along as part
of my query? Sounds nifty. Thanks for your help.

Cheers,

bs.

Hi,

From: “Ben Schumacher” ben@blahr.com
Sent: Thursday, February 13, 2003 2:08 AM

Oops. I found that I didn’t commit soap4r/sample/Amazon/* files before
releasing soap4r/1.4.8…

Try
$ /bin/wsdl2ruby.rb --wsdl http://soap.amazon.com/schemas2/AmazonWebServices.wsdl --classDef --force

It should create AmazonSearch.rb in the current directory.

So I just fill in the details on these classes and send it along as part
of my query? Sounds nifty. Thanks for your help.

Yes. And you don’t have to change the class definitions.

$ wsdl2ruby.rb --wsdl http://soap.amazon.com/schemas2/AmazonWebServices.wsdl --classDef --force
I, [2003-02-13T08:46:02.776531 #3204] INFO – app: Start of app.
I, [2003-02-13T08:46:04.956531 #3204] INFO – app: Creating class definition.
I, [2003-02-13T08:46:04.968531 #3204] INFO – app: Creates file ‘AmazonSearch.rb’.
I, [2003-02-13T08:46:05. 62531 #3204] INFO – app: End of app. (status: 0)

$ cat wsdlDriver.rb
require ‘soap/wsdlDriver’

searchBook = ARGV.shift || “Ruby”

require ‘AmazonSearch.rb’

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”)).read.chomp

AMAZON_WSDL = ‘http://soap.amazon.com/schemas2/AmazonWebServices.wsdl
amazon = SOAP::WSDLDriverFactory.new(AMAZON_WSDL).createDriver
amazon.generateEncodeType = true
#amazon.setWireDumpDev(STDERR)

Show sales rank.

req = KeywordRequest.new(searchBook, “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

$ ruby wsdlDriver.rb “Ruby language”
== Programming Ruby: A Pragmatic Programmer’s Guide
Author: David Thomas, Andrew Hunt, Dave Thomas
Release date: 15 December, 2000
List price: $42.95, our price: $42.95

== The Ruby Way
Author: Hal Fulton
Release date: 17 December, 2001
List price: $39.99, our price: $27.99

== Ruby In A Nutshell
Author: Yukihiro Matsumoto
Release date: November, 2001
List price: $24.95, our price: $17.47

== Ruby Developer’s Guide
Author: Robert Feldt, Lyle Johnson, Michael Neumann, Lyle Johnson, Jonothon Ortiz
Release date: 18 January, 2002
List price: $49.95, our price: $34.97

== Making Use of Ruby
Author: Suresh Mahadevan, Rashi Gupta, Shweta Bhasin, Madhushree Ganguly, Ashok Appu
Release date: 15 July, 2002
List price: $35.00, our price: $24.50

== Sams Teach Yourself Ruby in 21 Days
Author: Mark Slagell
Release date: 22 March, 2002
List price: $39.99, our price: $27.99

== Writing and Grammar: Communication in Action: Ruby Grade 11
Author: Joyce Armstrong Carroll, Edward E. Wilson, Gary Forlini
Release date: January, 2001
List price: $71.00, our price: $71.00

== Teacher’s Guide for an Introduction to Kings, Later Prophets and Writings
Author: Shirley Newman, Myra Yedwab, Lillian Adler, Ruby G. Strauss
Release date: October, 1996
List price: $14.95, our price: $14.95

== The Puerto Ricans: Culture Change and Language Deviance (Viking Fund Publications in Anthropology, No. 51)
Author: Ruby Rohrlich, Ruby Rohrlich-Leavitt
Release date: June, 1974
List price: $11.95, our price: $11.95

== The Hebrew Primer
Author: Ahuva Schuller, Lillian Adler, Ruby G. Strauss, Guy Brison-Stack
Release date: October, 1996
List price: $9.50, our price: $9.50

$

Hmm. It seems that “Lyle Johnson”-san is doubled at
“Ruby Developer’s Guide” in Amazon’s DB…

Regards,
// NaHi