Calling SetReturnURL from ebay4r

Garry Dolley’s ebay4r gem provides a Ruby interface to eBay’s SOAP API.

The following script extends it to allow the calling of eBay’s SetReturnURL method - required on a one-off basis to define redirect URLs for any eBay application authenticating users over the web.

ebay4r attempts to authenticate itself using the standard authToken, but this is one of the few calls which requires a username and password to be supplied instead of the token. The following script fixes the problem by inserting the required data into the header of the SOAP request before sending.

If there is a more straightforward way of doing this, I’d like to know - extensive delving into the ebay4r docs and examples revealed nothing.

require 'rubygems'
require 'ebayapi'

# your API details
appId = 'RobinWat-xxxx-xxxx-a9a5-b2a1e596xxxx'
devId = 'a696b358-xxxx-xxxx-b2e0-100b3fa8xxxx'
certId = '0c2d9022-xxxx-xxxx-9684-9082e9a2xxxx'
authToken = ''     # not needed for this call

# I had to use a sandbox test user here
username = 'testuser_xxx1'
password = 'xxxxxx'

accepturl = 'https://www.example.com/accept'
rejecturl = 'https://www.example.com/reject'
runame = 'developer-appname-auth'
action = 'Add'       # or 'Update'
application = 'yourappname'					

########################

ebay = EBay::API.new(authToken, devId, appId, certId, :sandbox => true)
ebay.debug = true

class EBay::RequesterCredentialsHandler
  Username = XSD::QName.new(nil, 'n1:Username')
  Password = XSD::QName.new(nil, 'n1:Password')

  def on_simple_outbound
    { EbayAuthToken => @token,
      Credentials => { DevId => @devId, AppId => @appId, AuthCert => @cert, Username => @username, Password => @password } }
  end
end

ebay.instance_eval do
  @header_handler.instance_eval { @username, @password = username, password }
end

ebay.SetReturnURL(
  :AuthenticationEntry => EBay.AuthenticationEntry({
    :AcceptURL => accepturl,
    :RejectURL => rejecturl,
    :PrivacyPolicyURL => nil,
    :RuName => runame,
    :TokenReturnMethod => 'FetchToken'}),
  :Action => action,
  :ApplicationDisplayName => application
)
Bookmark it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • Reddit
  • StumbleUpon
  • Technorati
  • Facebook

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*