Consume SOAP WebServices Using Ruby With Savon

Recently, we had a task of consuming a SOAP based web serivces which sends and receive complex objects.

We started taking Amazon Commerce webserices whose WSDL can be found at

Now the fun part, you can find lots of ruby example for consuming simple datatype but very few for complete datatypes or objects.

Here is the worked out example posted it at GITHub Please feel free to improve and send me a pull request.

Impatient to open github and see the core code, here is the snippet for you.

[source language=”ruby”]
module Aws
class Consumer
attr_reader :aws_access_key_id, :aws_secret_key, :search_index, :keyword
@@url = “”
def initialize(aws_access_key_id, aws_secret_key, sIndex, keyword)
@aws_access_key_id = aws_access_key_id
@aws_secret_key = aws_secret_key
@search_index = sIndex
@keyword = keyword
@client =

def timestamp_and_signature(operation)
timestamp =
hmac =
# chomp to get rid of the newline
signature = Base64.encode64(hmac.digest).chomp
[timestamp, signature]

def search
operation = “ItemSearch”
timestamp, signature = timestamp_and_signature(operation)
@client.request :item_search do |soap|
soap.body= {
“Request” => {“Keywords” => @keyword, “SearchIndex” => @search_index},
“AssociateTag” => ‘Keywords’,
“Timestamp” => timestamp,
“AWSAccessKeyId” => @aws_access_key_id,
“Signature” => signature

Related Posts

Leave a comment