ebay 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +346 -0
- data/examples/add_item.rb +56 -0
- data/examples/get_account.rb +30 -0
- data/examples/get_account2.rb +30 -0
- data/examples/get_account3.rb +30 -0
- data/examples/get_feedback.rb +46 -0
- data/examples/get_item.rb +23 -0
- data/examples/hello_world.rb +24 -0
- data/examples/myCredentials.rb +6 -0
- data/examples/test.rb +15 -0
- data/examples/verify_add_item.rb +58 -0
- data/lib/.document +1 -0
- data/lib/RequesterCredentialsHandler.rb +47 -0
- data/lib/eBay.rb +21602 -0
- data/lib/eBayAPI.rb +200 -0
- data/lib/eBayDriver.rb +773 -0
- data/test/TODO +16 -0
- data/test/tc_hello_world.rb +45 -0
- data/test/tc_items.rb +78 -0
- metadata +63 -0
data/README
ADDED
@@ -0,0 +1,346 @@
|
|
1
|
+
|
2
|
+
== Welcome to eBay4R
|
3
|
+
|
4
|
+
eBay4R is a Ruby wrapper for eBay's Web Services SOAP API (v433). Emphasis is
|
5
|
+
on ease of use and small footprint.
|
6
|
+
|
7
|
+
<b>This code is currently alpha stage</b>.
|
8
|
+
|
9
|
+
Please report bugs and other problems, see "Author" section at the bottom.
|
10
|
+
|
11
|
+
Current releases and CVS snapshots can be downloaded from:
|
12
|
+
|
13
|
+
http://rubyforge.org/projects/ebay4r
|
14
|
+
|
15
|
+
|
16
|
+
== Requirements
|
17
|
+
|
18
|
+
* SOAP4R library newer than v1.5.5. At the time of this writing, the latest
|
19
|
+
version was v1.5.5, which will not work. You have to get a snapshot that is
|
20
|
+
dated 11-06-2005 or newer. You can find development snapshots here:
|
21
|
+
|
22
|
+
http://dev.ctor.org/download
|
23
|
+
|
24
|
+
So, for example, to download the 11-06-2005 snapshot (the one I personally
|
25
|
+
used during development), go here:
|
26
|
+
|
27
|
+
http://dev.ctor.org/download/archive/soap4r-20051106.tar.gz
|
28
|
+
|
29
|
+
Note: I _have_ seen one instance of SOAP4R v1.5.5 work out-of-the-box, and
|
30
|
+
that was on a Ruby v1.8.3 source install on NetBSD 2.1. On my Debian 3.1
|
31
|
+
box, however, I had to install the newer snapshot. Go figure, I don't
|
32
|
+
know what the diff is...
|
33
|
+
|
34
|
+
|
35
|
+
== Optionals
|
36
|
+
|
37
|
+
* RubyGems
|
38
|
+
|
39
|
+
|
40
|
+
== Installation
|
41
|
+
|
42
|
+
=== tar/gzip
|
43
|
+
|
44
|
+
Just unzip the archive anywhere you like, and see "Getting Started" below
|
45
|
+
(you will need to add the ebay4r/lib path to your $RUBYLIB environment
|
46
|
+
variable)
|
47
|
+
|
48
|
+
=== RubyGems
|
49
|
+
|
50
|
+
* To install a gem you already downloaded:
|
51
|
+
|
52
|
+
gem install ebay-<version>.gem
|
53
|
+
|
54
|
+
* For the latest release with no fuss (previous download not required):
|
55
|
+
|
56
|
+
gem install -r ebay4r
|
57
|
+
|
58
|
+
=== CVS
|
59
|
+
|
60
|
+
You can download the latest and greatest code using anonymous CVS, just type:
|
61
|
+
|
62
|
+
cvs -d :pserver:anonymous@rubyforge.org:/var/cvs/ebay4r login
|
63
|
+
cvs -d :pserver:anonymous@rubyforge.org:/var/cvs/ebay4r checkout ebay4r
|
64
|
+
|
65
|
+
|
66
|
+
== Getting Started
|
67
|
+
|
68
|
+
If you installed eBay4R from a tarball or CVS, you will want to add the
|
69
|
+
ebay4r/lib directory to your Ruby include path ($RUBYLIB). Then put
|
70
|
+
|
71
|
+
require 'eBayAPI'
|
72
|
+
|
73
|
+
at the top of your programs.
|
74
|
+
|
75
|
+
If you installed eBay4R with RubyGems, you don't have to add anything to
|
76
|
+
Ruby's include path, just put
|
77
|
+
|
78
|
+
require 'rubygems'
|
79
|
+
require_gem 'ebay'
|
80
|
+
|
81
|
+
at the top of your programs.
|
82
|
+
|
83
|
+
=== Examples
|
84
|
+
|
85
|
+
Look at the examples/ directory. Edit the file myCredentials.rb and insert
|
86
|
+
the appropriate values. Then you can run any of the example programs.
|
87
|
+
|
88
|
+
==== Hello, World!
|
89
|
+
|
90
|
+
The simplest eBay API call is "GeteBayOfficialTime". Here's how to call it
|
91
|
+
with eBay4R:
|
92
|
+
|
93
|
+
require 'rubygems'
|
94
|
+
require_gem 'ebay'
|
95
|
+
|
96
|
+
# Put your credentials in this file
|
97
|
+
load('myCredentials.rb')
|
98
|
+
|
99
|
+
# Create new eBay caller object. Omit last argument to use live platform.
|
100
|
+
eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true)
|
101
|
+
|
102
|
+
resp = eBay.GeteBayOfficialTime
|
103
|
+
|
104
|
+
puts "Hello, World!"
|
105
|
+
puts "The eBay time is now: #{resp.timestamp}"
|
106
|
+
|
107
|
+
# Wasn't that easy?!
|
108
|
+
|
109
|
+
==== Adding an Item
|
110
|
+
|
111
|
+
This is a more complex example that performs a real (useful) function:
|
112
|
+
|
113
|
+
require 'rubygems'
|
114
|
+
require_gem 'ebay'
|
115
|
+
|
116
|
+
load('myCredentials.rb')
|
117
|
+
|
118
|
+
eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true)
|
119
|
+
|
120
|
+
# New method of generating complex types, needs some more testing...
|
121
|
+
resp = eBay.AddItem(:Item => EBay.Item(:PrimaryCategory => EBay.Category(:CategoryID => 57882),
|
122
|
+
:Title => 'Mouse Pad',
|
123
|
+
:Description => 'A really cool mouse pad, you know you want it...',
|
124
|
+
:Location => 'On Earth',
|
125
|
+
:StartPrice => 12.0,
|
126
|
+
:Quantity => 1,
|
127
|
+
:ListingDuration => "Days_7",
|
128
|
+
:Country => "US",
|
129
|
+
:Currency => "USD",
|
130
|
+
:PaymentMethods => ["VisaMC", "PersonalCheck"]))
|
131
|
+
|
132
|
+
puts "New Item #" + resp.itemID + " added."
|
133
|
+
|
134
|
+
|
135
|
+
=== Format of Requests
|
136
|
+
|
137
|
+
If <tt>eBay</tt> is your caller object, then you can issue any eBay API call
|
138
|
+
by doing:
|
139
|
+
|
140
|
+
eBay.<call_name>( ... hash of named-arguments ... )
|
141
|
+
|
142
|
+
For example, to issue the GetItem call for Item ##4503432058 and return all
|
143
|
+
information, you do:
|
144
|
+
|
145
|
+
eBay.GetItem(:DetailLevel => 'ReturnAll', :ItemID => '4503432058')
|
146
|
+
|
147
|
+
or to see your last invoice using the GetAccount call, you do:
|
148
|
+
|
149
|
+
eBay.GetAccount(:AccountHistorySelection => 'LastInvoice')
|
150
|
+
|
151
|
+
See the "eBay Web Services SOAP API Guide" for acceptable parameters and values
|
152
|
+
for each API call. This guide can be downloaded at eBay's
|
153
|
+
{SOAP Development Center}[http://developer.ebay.com/soap/].
|
154
|
+
|
155
|
+
==== Passing Complex Data Types
|
156
|
+
|
157
|
+
A number of elements in eBay's schema are XML Schema simple types. For
|
158
|
+
example, CategoryID, Title, and Description are all strings. But many
|
159
|
+
elements, like Item and Seller, are of types "ItemType" and "SellerType",
|
160
|
+
respectively. These are complex data types, meaning they are structures
|
161
|
+
composed of collections of simple types.
|
162
|
+
|
163
|
+
"How do I make a complex type object?", you ask. Simple:
|
164
|
+
|
165
|
+
EBay.<element_name>( ... hash of named-arguments ... )
|
166
|
+
|
167
|
+
creates a new <em><element_name></em> element of type <em><element_name></em>Type. For
|
168
|
+
example,
|
169
|
+
|
170
|
+
EBay.Item(:Title => 'Mouse Pad', :Description => '...')
|
171
|
+
|
172
|
+
creates a new ItemType object. Please note, these factory methods are class
|
173
|
+
methods of module EBay, so the upper-case "E" in "EBay" is not a typo. A
|
174
|
+
more common way to see this is:
|
175
|
+
|
176
|
+
EBay::Item( ... )
|
177
|
+
|
178
|
+
The only difference is if you do not pass any arguments to the factory method
|
179
|
+
and do not explicitly put empty parentheses (), Ruby will assume it is a
|
180
|
+
constant, not a method.
|
181
|
+
|
182
|
+
|
183
|
+
=== Format of Responses
|
184
|
+
|
185
|
+
There is a one-to-one correspondence between the XML returned by eBay and the
|
186
|
+
way you access the values contained therein using the response object returned
|
187
|
+
by the call. For example, let's say you issued a "GetItem" call:
|
188
|
+
|
189
|
+
resp = eBay.GetItem(:DetailLevel => 'ReturnAll', :ItemID => '4503432058')
|
190
|
+
|
191
|
+
and eBay returned the following XML (abbreviated where appropriate):
|
192
|
+
|
193
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
194
|
+
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
|
195
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
196
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
197
|
+
<soapenv:Body>
|
198
|
+
<GetItemResponse xmlns="urn:ebay:apis:eBLBaseComponents">
|
199
|
+
<Timestamp>2005-12-09T09:40:41.602Z</Timestamp>
|
200
|
+
<Ack>Success</Ack>
|
201
|
+
<Version>437</Version>
|
202
|
+
<Build>e437_core_Bundled_2119808_R1</Build>
|
203
|
+
<Item>
|
204
|
+
...
|
205
|
+
|
206
|
+
<AutoPay>false</AutoPay>
|
207
|
+
<BuyerProtection>ItemIneligible</BuyerProtection>
|
208
|
+
<BuyItNowPrice currencyID="USD">0.0</BuyItNowPrice>
|
209
|
+
<Country>US</Country>
|
210
|
+
<Currency>USD</Currency>
|
211
|
+
<Description>Fund. of Physics, 5th, by Halliday, Resnick, Walker</Description>
|
212
|
+
<Escrow>None</Escrow>
|
213
|
+
<GiftIcon>0</GiftIcon>
|
214
|
+
...
|
215
|
+
|
216
|
+
<ShipToLocations>US</ShipToLocations>
|
217
|
+
<ShipToLocations>CA</ShipToLocations>
|
218
|
+
</Item>
|
219
|
+
</GetItemResponse>
|
220
|
+
</soapenv:Body>
|
221
|
+
</soapenv:Envelope>
|
222
|
+
|
223
|
+
|
224
|
+
The "resp" object is of type
|
225
|
+
|
226
|
+
SOAP::Mapping::Object
|
227
|
+
|
228
|
+
and contains all the XML elements between <tt><GetItemResponse> ... </GetItemResponse></tt>.
|
229
|
+
|
230
|
+
So, if you want to print the item description, just do:
|
231
|
+
|
232
|
+
puts resp.item.description
|
233
|
+
|
234
|
+
and you will see:
|
235
|
+
|
236
|
+
"Fund. of Physics, 5th, by Halliday, Resnick, Walker"
|
237
|
+
|
238
|
+
Repeated XML elements automatically become arrays of the same name, so to see
|
239
|
+
all the locations this item can ship to, just do:
|
240
|
+
|
241
|
+
resp.item.shipToLocations.each { |loc| puts loc }
|
242
|
+
|
243
|
+
and you will see:
|
244
|
+
|
245
|
+
US
|
246
|
+
CA
|
247
|
+
|
248
|
+
It's that easy! (Are any Java or C# developers reading this? Don't be
|
249
|
+
jealous... ;)
|
250
|
+
|
251
|
+
=== A Note about Case
|
252
|
+
|
253
|
+
Astute readers (all of you, right?) will notice that the first letter of every
|
254
|
+
element contained within the response object is lower-case, even though in the
|
255
|
+
XML it is upper-case. This is currently the way things are and you will have
|
256
|
+
to remember to lower the first character in your code.
|
257
|
+
|
258
|
+
Ruby's convention is that only classes, modules, and constants begin with
|
259
|
+
upper-case letters. The author of the SOAP4R library (which contains
|
260
|
+
wsdl2ruby.rb) respected this convention, and as a result, the eBay.rb
|
261
|
+
file I use (generated from eBay's WSDL) has this mapping.
|
262
|
+
|
263
|
+
I haven't come up with any Ruby magic to dynamically allow upper-case first
|
264
|
+
characters to work also, so if you happen to want to take a crack at it and
|
265
|
+
get it working, please send me your patches (see "Author" section at the
|
266
|
+
bottom).
|
267
|
+
|
268
|
+
Please note, the opposite does _not_ apply. That is, you can *submit* a call
|
269
|
+
using either case of the first character, and your arguments can also have
|
270
|
+
either case letter first. For example, this:
|
271
|
+
|
272
|
+
resp = eBay.GetItem(:DetailLevel => 'ReturnAll', :ItemID => '4503432058')
|
273
|
+
|
274
|
+
is the same as:
|
275
|
+
|
276
|
+
resp = eBay.getItem(:detailLevel => 'ReturnAll', :itemID => '4503432058')
|
277
|
+
|
278
|
+
|
279
|
+
== Debugging
|
280
|
+
|
281
|
+
If "eBay" is your eBay caller object, as in:
|
282
|
+
|
283
|
+
eBay = EBay::API.new( ... )
|
284
|
+
|
285
|
+
You can see XML wiredumps by doing:
|
286
|
+
|
287
|
+
eBay.debug = true
|
288
|
+
|
289
|
+
before you issue any eBay API calls. This is useful to see the raw XML of
|
290
|
+
what eBay is sending back to you.
|
291
|
+
|
292
|
+
|
293
|
+
== Files
|
294
|
+
|
295
|
+
examples/
|
296
|
+
Examples of eBay API calls using this library. You will want to check out
|
297
|
+
these examples before making your own calls.
|
298
|
+
|
299
|
+
lib/eBayAPI.rb
|
300
|
+
The heart of this library
|
301
|
+
|
302
|
+
lib/eBayDriver.rb
|
303
|
+
Autogenerated by wsdl2ruby.rb
|
304
|
+
|
305
|
+
lib/eBay.rb
|
306
|
+
Autogenerated by wsdl2ruby.rb
|
307
|
+
|
308
|
+
lib/RequesterCredentialsHandler.rb
|
309
|
+
Helper for generating the eBay Authentication header for each call
|
310
|
+
|
311
|
+
test/
|
312
|
+
Unit and functional tests
|
313
|
+
|
314
|
+
|
315
|
+
== To Do
|
316
|
+
|
317
|
+
* Add many more examples
|
318
|
+
* Add more unit and functional tests
|
319
|
+
|
320
|
+
|
321
|
+
== Author
|
322
|
+
|
323
|
+
Garry C. Dolley
|
324
|
+
|
325
|
+
gdolley [at] ucla.edu
|
326
|
+
|
327
|
+
AIM: garry97531
|
328
|
+
|
329
|
+
|
330
|
+
== Copyright
|
331
|
+
|
332
|
+
Copyright (c) 2005 Garry C. Dolley
|
333
|
+
|
334
|
+
eBay4R is free software; you can redistribute it and/or modify it under the
|
335
|
+
terms of the GNU General Public License as published by the Free Software
|
336
|
+
Foundation; either version 2 of the License, or (at your option) any later
|
337
|
+
version.
|
338
|
+
|
339
|
+
eBay4R is distributed in the hope that it will be useful, but WITHOUT ANY
|
340
|
+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
341
|
+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
342
|
+
details.
|
343
|
+
|
344
|
+
You should have received a copy of the GNU General Public License along with
|
345
|
+
eBay4R; if not, write to the Free Software Foundation, Inc., 51 Franklin
|
346
|
+
Street, Fifth Floor, Boston, MA 02110-1301, USA
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
4
|
+
require 'eBayAPI'
|
5
|
+
|
6
|
+
#
|
7
|
+
# Example of AddItem call
|
8
|
+
#
|
9
|
+
|
10
|
+
load('myCredentials.rb')
|
11
|
+
|
12
|
+
eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true)
|
13
|
+
|
14
|
+
# New method of generating complex types, needs some more testing...
|
15
|
+
resp = eBay.AddItem(:Item => EBay.Item(:PrimaryCategory => EBay.Category(:CategoryID => 57882),
|
16
|
+
:Title => 'Mouse Pad',
|
17
|
+
:Description => 'A really cool mouse pad, you know you want it...',
|
18
|
+
:Location => 'On Earth',
|
19
|
+
:StartPrice => 12.0,
|
20
|
+
:Quantity => 1,
|
21
|
+
:ListingDuration => "Days_7",
|
22
|
+
:Country => "US",
|
23
|
+
:Currency => "USD",
|
24
|
+
:PaymentMethods => ["VisaMC", "PersonalCheck"]))
|
25
|
+
|
26
|
+
puts "New Item #" + resp.itemID + " added."
|
27
|
+
puts "You spent:\n"
|
28
|
+
|
29
|
+
|
30
|
+
# The fees part of the response looks like this:
|
31
|
+
#
|
32
|
+
# <Fees>
|
33
|
+
# <Fee>
|
34
|
+
# <Name>AuctionLengthFee</Name>
|
35
|
+
# <Fee currencyID="USD">0.0</Fee>
|
36
|
+
# </Fee>
|
37
|
+
# <Fee>
|
38
|
+
# <Name>BoldFee</Name>
|
39
|
+
# <Fee currencyID="USD">0.0</Fee>
|
40
|
+
# </Fee>
|
41
|
+
# ...
|
42
|
+
# <Fee>
|
43
|
+
# <Name>InsertionFee</Name>
|
44
|
+
# <Fee currencyID="USD">0.6</Fee>
|
45
|
+
# </Fee>
|
46
|
+
# ...
|
47
|
+
# </Fees>
|
48
|
+
#
|
49
|
+
# So this is now we traverse it:
|
50
|
+
resp.fees.fee.each do |fee|
|
51
|
+
puts fee.name + ": " + fee.fee + " " + fee.fee.xmlattr_currencyID
|
52
|
+
end
|
53
|
+
|
54
|
+
# Notice how the object names reflect the XML element names, and any element
|
55
|
+
# that is repeated automatically becomes an array, so you can run "each" on
|
56
|
+
# it.
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
4
|
+
require 'eBayAPI'
|
5
|
+
|
6
|
+
#
|
7
|
+
# Example of GetAccount call requesting the last monthly statement
|
8
|
+
#
|
9
|
+
|
10
|
+
load('myCredentials.rb')
|
11
|
+
|
12
|
+
eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true)
|
13
|
+
|
14
|
+
resp = eBay.GetAccount(:AccountHistorySelection => 'LastInvoice')
|
15
|
+
|
16
|
+
puts "AccountID: " + resp.accountID
|
17
|
+
puts "Account Summary -- Account State: " + resp.accountSummary.accountState
|
18
|
+
|
19
|
+
# Not all statements will have an <AccountState>, so we only print it if present
|
20
|
+
puts "Account Summary -- Account State: " + resp.accountSummary.accountState if resp.accountSummary.respond_to?(:accountState)
|
21
|
+
|
22
|
+
# Some statements may not have any entries in them (no sales that month?), so
|
23
|
+
# we must test to make sure "accountEntries" exists before we traverse it.
|
24
|
+
if resp.respond_to?(:accountEntries)
|
25
|
+
resp.accountEntries.accountEntry.each do |entry|
|
26
|
+
puts "Account Entries -- Description: " + entry.description
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Many more fields may be present, see eBay's SOAP API Guide or GetAccountResponseType class in "../lib/eBay.rb"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
4
|
+
require 'eBayAPI'
|
5
|
+
|
6
|
+
#
|
7
|
+
# Example of GetAccount call requesting a specific monthly statement
|
8
|
+
#
|
9
|
+
|
10
|
+
load('myCredentials.rb')
|
11
|
+
|
12
|
+
eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true)
|
13
|
+
|
14
|
+
resp = eBay.GetAccount(:AccountHistorySelection => 'SpecifiedInvoice', :InvoiceDate => '2005-11-01')
|
15
|
+
|
16
|
+
puts "AccountID: " + resp.accountID
|
17
|
+
puts "Account Summary -- Invoice Balance: " + resp.accountSummary.invoiceBalance
|
18
|
+
|
19
|
+
# Not all statements will have an <AccountState>, so we only print it if present
|
20
|
+
puts "Account Summary -- Account State: " + resp.accountSummary.accountState if resp.accountSummary.respond_to?(:accountState)
|
21
|
+
|
22
|
+
# Some statements may not have any entries in them (no sales that month?), so
|
23
|
+
# we must test to make sure "accountEntries" exists before we traverse it.
|
24
|
+
if resp.respond_to?(:accountEntries)
|
25
|
+
resp.accountEntries.accountEntry.each do |entry|
|
26
|
+
puts "Account Entries -- Description: " + entry.description
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Many more fields may be present, see eBay's SOAP API Guide or GetAccountResponseType class in "../lib/eBay.rb"
|