bjjb / ebayr

A small library to help using the eBay Trading API with Ruby
MIT License
60 stars 49 forks source link

Requester credentials are conditionally included in the XML request body #13

Closed jasonschock closed 9 years ago

jasonschock commented 9 years ago

... only if an auth token is present.

The problem is that sending empty requester credentials for a request that doesn’t require them can cause that request to fail, e.g. GetSessionID.

For example:

<?xml version="1.0" encoding="utf-8"?>
    <GetSessionIDRequest xmlns="urn:ebay:apis:eBLBaseComponents">
    <RequesterCredentials>
        <eBayAuthToken></eBayAuthToken>
    </RequesterCredentials>
    <RuName>MY_RUNAME</RuName>
</GetSessionIDRequest>

Returns:

<?xml version="1.0" encoding="UTF-8"?>
<GetSessionIDResponse 
    xmlns="urn:ebay:apis:eBLBaseComponents">
    <Timestamp>2015-07-04T06:29:40.490Z</Timestamp>
    <Ack>Failure</Ack>
    <Errors>
        <ShortMessage>Auth token is invalid.</ShortMessage>
        <LongMessage>Validation of the authentication token in API request failed.</LongMessage>
        <ErrorCode>931</ErrorCode>
        <SeverityCode>Error</SeverityCode>
        <ErrorClassification>RequestError</ErrorClassification>
    </Errors>
    <Version>921</Version>
    <Build>E921_CORE_API_17506731_R1</Build>
</GetSessionIDResponse>

Whereas

<?xml version="1.0" encoding="utf-8"?>
  <GetSessionIDRequest xmlns="urn:ebay:apis:eBLBaseComponents">
  <RuName>MY_RUNAME</RuName>
</GetSessionIDRequest>

Returns:

<?xml version="1.0" encoding="UTF-8"?>
<GetSessionIDResponse 
    xmlns="urn:ebay:apis:eBLBaseComponents">
    <Timestamp>2015-07-04T06:31:59.657Z</Timestamp>
    <Ack>Success</Ack>
    <Version>929</Version>
    <Build>E929_CORE_APISIGNIN_17569042_R1</Build>
    <SessionID>L94CAA**57c3b1a914e0a624f91002c0ffffeb6e</SessionID>
</GetSessionIDResponse>
achadee commented 9 years ago

AHahahahahah i coded this up just then, you beat me to it!

achadee commented 9 years ago

on another note, can we do a version bump with this patch, ty :)

bjjb commented 9 years ago

Weird, I've never had a problem with GetSessionID. Still, looks like a potential improvement. Nice work.

bjjb commented 9 years ago

@achadee You're welcome.