[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Adding a header to a SOAP request

David Teare

6/27/2005 6:13:00 PM

Hi all,

I want to use ruby to integrate my site with PayPal's new Website
Direct Pro API. I tried the code below, and it seems to work once I
upgraded to soap4r-1_5_4:

require 'soap/wsdlDriver'
server = SOAP::WSDLDriverFactory.new("http://
www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl")
@driver = server.createDriver

One problem I'm having is Paypal requires that I set a header in the
request (user id & password). How do I add this before performing a
request?

Any help or pointers to some SOAP/WSDL ruby documentation would be
greatly appreciated.

Thanks!
--Dave.


1 Answer

Patrick Chanezon

7/2/2005 8:47:00 AM

0

something like that works: that's what I use for the Google Adwords API.
The soap4r sample for adwords has a bug, but the code below works.
Just adapt it to your needs for the paypal headers.
In my code headers is a hash with tag, value pairs.
I load it from a yaml file but you can set it up the way you want.
I hope this helps.

---
wsdl = 'https://adwords.google.com/api/adwords/v2/CampaignService...

class HeaderHandler < SOAP::Header::SimpleHandler
def initialize(tag, value)
super(XSD::QName.new(nil, tag))
@tag = tag
@value = value
end

#the initial handler from the sample was wrong, it generated 2 level of tags
def on_simple_outbound
@value
end
end

require 'defaultDriver.rb'
require 'yaml'

prefs = YAML::load( File.open('adwords.yaml', 'r'))
headers = prefs['headers']

drv = CampaignService.new()

#problem: http protocol properties set in soap/property from rubyhome
are not picked up
drv.loadproperty('soap/property')
#problem: wiredump_dev does not output anything when running in SSL mode
#drv.wiredump_dev = STDOUT
#the file based logger works
drv.wiredump_file_base = "log"

headers.each {|key, value| drv.headerhandler << HeaderHandler.new(key, value)}
---

P@

On 6/27/05, David Teare <dteare@tearesolutions.com> wrote:
> Hi all,
>
> I want to use ruby to integrate my site with PayPal's new Website
> Direct Pro API. I tried the code below, and it seems to work once I
> upgraded to soap4r-1_5_4:
>
> require 'soap/wsdlDriver'
> server = SOAP::WSDLDriverFactory.new("http://
> www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl")
> @driver = server.createDriver
>
> One problem I'm having is Paypal requires that I set a header in the
> request (user id & password). How do I add this before performing a
> request?
>
> Any help or pointers to some SOAP/WSDL ruby documentation would be
> greatly appreciated.
>
> Thanks!
> --Dave.
>
>