├── lib ├── .document ├── RequesterCredentialsHandler.rb ├── eBayAPI.rb └── eBayDriver.rb ├── examples ├── myCredentials.rb ├── hello_world.rb ├── get_item.rb ├── get_suggested_categories.rb ├── revise_item.rb ├── get_ebay_details.rb ├── get_categories.rb ├── get_account.rb ├── get_categories2.rb ├── get_account2.rb ├── get_category_features.rb ├── get_account3.rb ├── set_notification_preferences.rb ├── get_feedback.rb ├── get_notifications_usage.rb ├── add_item.rb ├── verify_add_item.rb ├── get_notification_preferences.rb └── add_item2.rb ├── Rakefile ├── test ├── TODO ├── tc_hello_world.rb ├── tc_routing.rb └── tc_items.rb ├── ebay4r.gemspec ├── contrib ├── ebay_platform_notifications.txt └── get_and_store_ebay_categories.rb ├── RELEASE_NOTES ├── README └── COPYING /lib/.document: -------------------------------------------------------------------------------- 1 | eBayAPI.rb 2 | -------------------------------------------------------------------------------- /examples/myCredentials.rb: -------------------------------------------------------------------------------- 1 | # Fill these in before running the examples: 2 | 3 | $appId = 'my_app_id' 4 | $devId = 'my_dev_id' 5 | $certId = 'my_cert_id' 6 | $authToken = 'my_auth_token' 7 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | begin 2 | require 'rubygems' 3 | require 'rake/gempackagetask' 4 | rescue Exception 5 | nil 6 | end 7 | 8 | require 'rake/testtask' 9 | 10 | desc "Default Task" 11 | task :default => :test_all 12 | 13 | Rake::TestTask.new(:test_all) do |t| 14 | t.test_files = FileList[ 15 | 'test/tc_*.rb', 16 | ] 17 | t.warning = false 18 | t.verbose = false 19 | end 20 | -------------------------------------------------------------------------------- /test/TODO: -------------------------------------------------------------------------------- 1 | TODO 2 | ---- 3 | 4 | There are many, many more tests that need to be performed. 5 | 6 | The eBay API now has over 100 possible calls, so if you use this library in 7 | your eBay application, please consider giving back to the project by writing 8 | a test case or two. 9 | 10 | Please email test cases to: gdolley@ucla.edu 11 | 12 | Include your full name so I can give you credit and copyright stamp. 13 | 14 | Thanks! 15 | 16 | -- Garry 17 | -------------------------------------------------------------------------------- /examples/hello_world.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # $Id: hello_world.rb,v 1.6 2005/12/27 01:13:46 garrydolley Exp $ 3 | 4 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | 6 | require 'eBayAPI' 7 | 8 | # 9 | # Example of GeteBayOfficialTime call 10 | # 11 | 12 | # Put your credentials in this file 13 | load('myCredentials.rb') 14 | 15 | # Create new eBay caller object. Omit last argument to use live platform. 16 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 17 | 18 | # Call "GetEbayOfficialTime" 19 | resp = eBay.GeteBayOfficialTime 20 | 21 | # Report results 22 | puts "Hello, World!" 23 | puts "The eBay time is now: #{resp.timestamp}" 24 | 25 | # Wasn't that easy?! 26 | -------------------------------------------------------------------------------- /examples/get_item.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # $Id: get_item.rb,v 1.6 2006/01/07 01:29:55 garrydolley Exp $ 3 | 4 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | require 'eBayAPI' 6 | 7 | load('myCredentials.rb') 8 | 9 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 10 | 11 | # Replace ItemID with some item you know exists 12 | resp = eBay.GetItem(:DetailLevel => 'ReturnAll', :ItemID => '110029878327', :IncludeWatchCount => 'true') 13 | 14 | puts "AutoPay: " + resp.item.autoPay.to_s 15 | puts "Country: " + resp.item.country 16 | puts "ItemID: " + resp.item.itemID.to_s 17 | puts "Descr: " + resp.item.description 18 | puts "Location: " + resp.item.location 19 | 20 | puts "Ship To Locations:" 21 | resp.item.shipToLocations.each { |loc| puts loc } 22 | 23 | # Many more fields are present, see eBay's SOAP API Guide or GetItemResponseType class in "../lib/eBay.rb" 24 | 25 | -------------------------------------------------------------------------------- /examples/get_suggested_categories.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 4 | 5 | require 'eBayAPI' 6 | 7 | # 8 | # Example of GetSuggestedCategories call 9 | # 10 | 11 | # Put your credentials in this file 12 | load('myCredentials.rb') 13 | 14 | # Create new eBay caller object. Omit last argument to use live platform. 15 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 16 | 17 | # Call "GetSuggestedCategories" 18 | resp = eBay.GetSuggestedCategories(:Query => "stuff") 19 | 20 | # Report results 21 | 22 | if resp.categoryCount.to_i > 0 23 | resp.suggestedCategoryArray.suggestedCategory.each do |cat| 24 | puts " Category ID : " + cat.category.categoryID.to_s 25 | puts " Category Name : " + cat.category.categoryName + " (" + cat.percentItemFound.to_s + "%)" 26 | puts "" 27 | end 28 | else 29 | puts "No suggested categories found." 30 | end 31 | -------------------------------------------------------------------------------- /examples/revise_item.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # $Id: revise_item.rb,v 1.2 2006/01/07 07:34:27 garrydolley Exp $ 3 | 4 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | require 'eBayAPI' 6 | 7 | load('myCredentials.rb') 8 | 9 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 10 | 11 | # I want to revise Item #110029878327 -- replace this with an Item # that you know exists and is active 12 | item = EBay.Item(:ItemID => '110029878327', :Location => 'Brave New World', :Title => 'My new title') 13 | 14 | resp = eBay.ReviseItem(:DetailLevel => 'ReturnAll', :Item => item, 15 | :ModifiedFields => [ {:Field => 'Item.Location', :ModifyType => 'Modify'}, 16 | {:Field => 'Item.Title', :ModifyType => 'Modify'} ]) 17 | # Note :Field is case insensitive, so 'item.title' would work also 18 | 19 | puts "ItemID: " + resp.itemID 20 | -------------------------------------------------------------------------------- /ebay4r.gemspec: -------------------------------------------------------------------------------- 1 | # $Id: ebay4r.gemspec,v 1.8 2006/10/10 08:04:49 garrydolley Exp $ 2 | 3 | require 'rubygems' 4 | 5 | spec = Gem::Specification.new do |s| 6 | s.name = "ebay" 7 | s.version = "1.1" 8 | s.author = "Garry Dolley" 9 | s.email = "gdolley@ucla.edu" 10 | s.homepage = "http://ebay4r.rubyforge.org" 11 | s.platform = Gem::Platform::RUBY 12 | s.summary = "eBay4R is a Ruby wrapper for eBay's Web Services SOAP API. Emphasis is on ease of use and small footprint." 13 | 14 | candidates = Dir.glob("{examples,lib,test,contrib}/**/*") + Dir.glob("./**/.document") 15 | s.files = candidates.delete_if do |item| 16 | item.include?("CVS") || item.include?("rdoc") 17 | end 18 | 19 | s.require_path = "lib" 20 | s.autorequire = "eBayAPI" 21 | s.has_rdoc = true 22 | s.extra_rdoc_files = ["README"] 23 | end 24 | 25 | if $0 == __FILE__ 26 | Gem::manage_gems 27 | Gem::Builder.new(spec).build 28 | end 29 | -------------------------------------------------------------------------------- /examples/get_ebay_details.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # $Id: get_ebay_details.rb,v 1.1 2006/05/01 09:32:17 garrydolley Exp $ 3 | 4 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | 6 | require 'eBayAPI' 7 | 8 | # 9 | # Example of GeteBayDetails call 10 | # 11 | 12 | # Put your credentials in this file 13 | load('myCredentials.rb') 14 | 15 | # Create new eBay caller object. Omit last argument to use live platform. 16 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 17 | 18 | # Call "GeteBayDetails" 19 | resp = eBay.GeteBayDetails(:DetailName => ['ShippingLocationDetails', 'ShippingServiceDetails']) 20 | 21 | # Report results 22 | 23 | if resp.respond_to? 'shippingLocationDetails' 24 | puts "Seller Ship-To choices:\n\n" 25 | 26 | [resp.shippingLocationDetails].flatten.each do |s| 27 | puts s.shippingLocation + ": " + s.description 28 | end 29 | 30 | puts "\n" 31 | end 32 | 33 | if resp.respond_to? 'shippingServiceDetails' 34 | puts "Shipping service codes:\n\n" 35 | 36 | [resp.shippingServiceDetails].flatten.each do |s| 37 | puts s.shippingService + ": " + s.description + " (" + s.shippingServiceID.to_s + ")" 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /examples/get_categories.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # $Id: get_categories.rb,v 1.2 2006/01/16 09:52:56 garrydolley Exp $ 3 | 4 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | 6 | require 'eBayAPI' 7 | 8 | # 9 | # Example of GetCategories call 10 | # 11 | 12 | # Put your credentials in this file 13 | load('myCredentials.rb') 14 | 15 | # Create new eBay caller object. Omit last argument to use live platform. 16 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 17 | 18 | # Call "GetCategories" 19 | resp = eBay.GetCategories(:DetailLevel => 'ReturnAll', # Return all available info 20 | :CategorySideID => 0, # US site 21 | :LevelLimit => 1) # Only 1 level deep 22 | 23 | # Report results 24 | 25 | puts "eBay Top Level Categories for US site (Cat. Version " + resp.categoryVersion + "):" 26 | puts "" 27 | 28 | resp.categoryArray.each do |cat| 29 | puts " Category Name : " + cat.categoryName 30 | puts " Category ID : " + cat.categoryID 31 | puts " Category Level: " + cat.categoryLevel.to_s 32 | puts " Is Leaf? : " + cat.leafCategory.to_s 33 | puts " Parent ID : " + cat.categoryParentID.to_s 34 | puts "" 35 | end 36 | -------------------------------------------------------------------------------- /examples/get_account.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # $Id: get_account.rb,v 1.7 2005/12/27 01:17:01 garrydolley Exp $ 3 | 4 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | require 'eBayAPI' 6 | 7 | # 8 | # Example of GetAccount call requesting the last monthly statement 9 | # 10 | 11 | load('myCredentials.rb') 12 | 13 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 14 | 15 | resp = eBay.GetAccount(:AccountHistorySelection => 'LastInvoice') 16 | 17 | puts "AccountID: " + resp.accountID 18 | puts "Account Summary -- Account State: " + resp.accountSummary.accountState 19 | 20 | # Not all statements will have an , so we only print it if present 21 | puts "Account Summary -- Account State: " + resp.accountSummary.accountState if resp.accountSummary.respond_to?(:accountState) 22 | 23 | # Some statements may not have any entries in them (no sales that month?), so 24 | # we must test to make sure "accountEntries" exists before we traverse it. 25 | if resp.respond_to?(:accountEntries) 26 | resp.accountEntries.each do |entry| 27 | puts "Account Entries -- Description: " + entry.description 28 | end 29 | end 30 | 31 | # Many more fields may be present, see eBay's SOAP API Guide or GetAccountResponseType class in "../lib/eBay.rb" 32 | -------------------------------------------------------------------------------- /examples/get_categories2.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # $Id: get_categories2.rb,v 1.3 2006/01/16 09:54:08 garrydolley Exp $ 3 | 4 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | 6 | require 'eBayAPI' 7 | 8 | # 9 | # Example of GetCategories call for eBay Motors 10 | # 11 | 12 | # Put your credentials in this file 13 | load('myCredentials.rb') 14 | 15 | # Create new eBay caller object. Omit last argument to use live platform. 16 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true, :site_id => 100) 17 | 18 | # Call "GetCategories" 19 | resp = eBay.GetCategories(:DetailLevel => 'ReturnAll', # Return all available info 20 | :CategorySideID => 100, # US eBay Motors Site 21 | :LevelLimit => 2) # 2 Levels Deep 22 | 23 | # Report results 24 | 25 | puts "eBay Motors Top Level Categories (Cat. Version " + resp.categoryVersion + "):" 26 | puts "" 27 | 28 | resp.categoryArray.each do |cat| 29 | puts " Category Name : " + cat.categoryName 30 | puts " Category ID : " + cat.categoryID 31 | puts " Category Level: " + cat.categoryLevel.to_s 32 | puts " Is Leaf? : " + cat.leafCategory.to_s 33 | puts " Parent ID : " + cat.categoryParentID.to_s 34 | puts "" 35 | end 36 | -------------------------------------------------------------------------------- /examples/get_account2.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # $Id: get_account2.rb,v 1.5 2005/12/27 01:17:01 garrydolley Exp $ 3 | 4 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | require 'eBayAPI' 6 | 7 | # 8 | # Example of GetAccount call requesting a specific monthly statement 9 | # 10 | 11 | load('myCredentials.rb') 12 | 13 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 14 | 15 | resp = eBay.GetAccount(:AccountHistorySelection => 'SpecifiedInvoice', :InvoiceDate => '2008-03-01') 16 | 17 | puts "AccountID: " + resp.accountID 18 | puts "Account Summary -- Invoice Balance: " + resp.accountSummary.invoiceBalance 19 | 20 | # Not all statements will have an , so we only print it if present 21 | puts "Account Summary -- Account State: " + resp.accountSummary.accountState if resp.accountSummary.respond_to?(:accountState) 22 | 23 | # Some statements may not have any entries in them (no sales that month?), so 24 | # we must test to make sure "accountEntries" exists before we traverse it. 25 | if resp.respond_to?(:accountEntries) 26 | resp.accountEntries.each do |entry| 27 | puts "Account Entries -- Description: " + entry.description 28 | end 29 | end 30 | 31 | # Many more fields may be present, see eBay's SOAP API Guide or GetAccountResponseType class in "../lib/eBay.rb" 32 | -------------------------------------------------------------------------------- /examples/get_category_features.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # $Id: get_category_features.rb,v 1.1 2006/04/30 07:37:52 garrydolley Exp $ 3 | 4 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | 6 | require 'eBayAPI' 7 | 8 | # 9 | # Example of GetCategoryFeatures call 10 | # 11 | 12 | # Put your credentials in this file 13 | load('myCredentials.rb') 14 | 15 | # Create new eBay caller object. Omit last argument to use live platform. 16 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 17 | 18 | # Call "GetCategoryFeatures" 19 | resp = eBay.GetCategoryFeatures(:DetailLevel => 'ReturnAll', # Return all available info 20 | :CategoryID => '1', 21 | :FeatureID => 'ListingDurations') # Tell us about listing durations 22 | 23 | # Report results 24 | 25 | durationHash = {} 26 | 27 | [resp.featureDefinitions.listingDurations.listingDuration].flatten.each do |ld| 28 | durationHash[ld.xmlattr_durationSetID] = ld.duration 29 | end 30 | 31 | puts "Site wide defaults for listing durations given listing type:\n\n" 32 | 33 | [resp.siteDefaults.listingDuration].flatten.each do |duration| 34 | puts duration.xmlattr_type # This is an example of how we read an XML attribute, just prepend "xmlattr_" to the name 35 | [durationHash[duration.to_i]].flatten.each do |c| 36 | puts " " + c 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /examples/get_account3.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # $Id: get_account3.rb,v 1.5 2005/12/27 01:17:01 garrydolley Exp $ 3 | 4 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | require 'eBayAPI' 6 | 7 | # 8 | # Example of GetAccount call requesting all statements in a date range 9 | # 10 | 11 | load('myCredentials.rb') 12 | 13 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 14 | 15 | resp = eBay.GetAccount(:AccountHistorySelection => 'BetweenSpecifiedDates', :BeginDate => '2005-10-01', :EndDate => '2005-11-01') 16 | 17 | puts "AccountID: " + resp.accountID 18 | puts "Account Summary -- Invoice Balance: " + resp.accountSummary.invoiceBalance if resp.accountSummary.respond_to?(:invoiceBalance) 19 | 20 | # Not all statements will have an , so we only print it if present 21 | puts "Account Summary -- Account State: " + resp.accountSummary.accountState if resp.accountSummary.respond_to?(:accountState) 22 | 23 | # Some statements may not have any entries in them (no sales that month?), so 24 | # we must test to make sure "accountEntries" exists before we traverse it. 25 | if resp.respond_to?(:accountEntries) 26 | resp.accountEntries.each do |entry| 27 | puts "Account Entries -- Description: " + entry.description 28 | end 29 | end 30 | 31 | # Many more fields may be present, see eBay's SOAP API Guide or GetAccountResponseType class in "../lib/eBay.rb" 32 | -------------------------------------------------------------------------------- /examples/set_notification_preferences.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 4 | require 'eBayAPI' 5 | 6 | # 7 | # Example of SetNotificationPreferences call 8 | # 9 | 10 | # Put your credentials in this file 11 | load('myCredentials.rb') 12 | 13 | # Create new eBay caller object. Omit last argument to use live platform. 14 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 15 | 16 | resp = eBay.SetNotificationPreferences(:ApplicationDeliveryPreferences => EBay.ApplicationDeliveryPreferences({ 17 | :ApplicationEnable => 'Enable', 18 | :ApplicationURL => 'http://www.xyz.com/my_script', 19 | :NotificationPayloadType => 'eBLSchemaSOAP' }), 20 | :UserDeliveryPreferenceArray => [ 21 | EBay.NotificationEnable( 22 | :EventEnable => 'Enable', 23 | :EventType => 'EndOfAuction'), 24 | EBay.NotificationEnable( 25 | :EventEnable => 'Enable', 26 | :EventType => 'Feedback') 27 | ] 28 | ) 29 | -------------------------------------------------------------------------------- /test/tc_hello_world.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | #-- 4 | # $Id: tc_hello_world.rb,v 1.2 2006/01/07 07:57:15 garrydolley Exp $ 5 | # 6 | # Copyright (c) 2005 Garry C. Dolley 7 | # 8 | # This file is part of eBay4R. 9 | # 10 | # eBay4R is free software; you can redistribute it and/or modify it under the 11 | # terms of the GNU General Public License as published by the Free Software 12 | # Foundation; either version 2 of the License, or (at your option) any later 13 | # version. 14 | # 15 | # eBay4R is distributed in the hope that it will be useful, but WITHOUT ANY 16 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 17 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 18 | # details. 19 | # 20 | # You should have received a copy of the GNU General Public License along with 21 | # eBay4R; if not, write to the Free Software Foundation, Inc., 51 Franklin 22 | # Street, Fifth Floor, Boston, MA 02110-1301, USA 23 | # 24 | #++ 25 | 26 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 27 | 28 | require 'test/unit' 29 | require 'eBayAPI' 30 | 31 | # This file must be in the current directory your $RUBYLIB environment var. 32 | load('myCredentials.rb') 33 | 34 | class TestHelloWorld < Test::Unit::TestCase 35 | @@eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 36 | 37 | def test_simplest_call 38 | resp = @@eBay.GeteBayOfficialTime 39 | 40 | assert_respond_to(resp, "timestamp") 41 | assert_respond_to(resp, "ack") 42 | assert_equal(resp.ack, "Success") 43 | 44 | assert(resp.timestamp != "") 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /examples/get_feedback.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # $Id: get_feedback.rb,v 1.3 2006/01/25 08:38:42 garrydolley Exp $ 3 | 4 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | require 'eBayAPI' 6 | 7 | # 8 | # Example of GetFeedback call 9 | # 10 | 11 | # Put your credentials in this file 12 | load('myCredentials.rb') 13 | 14 | # Create new eBay caller object. Omit last argument to use live platform. 15 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 16 | 17 | resp = eBay.GetFeedback # No arguments = current user, otherwise pass :UserID 18 | 19 | puts "Aggregate Feedback Score: #{resp.feedbackScore}" 20 | puts "Neutral Comment Count from Suspended Users: #{resp.feedbackSummary.neutralCommentCountFromSuspendedUsers}" 21 | puts "Unique Positive Feedbacks: #{resp.feedbackSummary.uniquePositiveFeedbackCount}" 22 | puts "Unique Negative Feedbacks: #{resp.feedbackSummary.uniqueNegativeFeedbackCount}" 23 | 24 | puts "Bid Retractions:" 25 | resp.feedbackSummary.bidRetractionFeedbackPeriodArray.each do |fb| 26 | puts " Last #{fb.periodInDays} Days: #{fb.count}" 27 | end 28 | 29 | puts "Positive Feedback:" 30 | resp.feedbackSummary.positiveFeedbackPeriodArray.each do |fb| 31 | puts " Last #{fb.periodInDays} Days: #{fb.count}" 32 | end 33 | 34 | puts "Negative Feedback:" 35 | resp.feedbackSummary.negativeFeedbackPeriodArray.each do |fb| 36 | puts " Last #{fb.periodInDays} Days: #{fb.count}" 37 | end 38 | 39 | puts "Neutral Feedback:" 40 | resp.feedbackSummary.neutralFeedbackPeriodArray.each do |fb| 41 | puts " Last #{fb.periodInDays} Days: #{fb.count}" 42 | end 43 | 44 | puts "Total Feedback:" 45 | resp.feedbackSummary.totalFeedbackPeriodArray.each do |fb| 46 | puts " Last #{fb.periodInDays} Days: #{fb.count}" 47 | end 48 | 49 | -------------------------------------------------------------------------------- /test/tc_routing.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | #-- 4 | # $Id: tc_routing.rb,v 1.1 2006/01/07 08:15:48 garrydolley Exp $ 5 | # 6 | # Copyright (c) 2005 Garry C. Dolley 7 | # 8 | # This file is part of eBay4R. 9 | # 10 | # eBay4R is free software; you can redistribute it and/or modify it under the 11 | # terms of the GNU General Public License as published by the Free Software 12 | # Foundation; either version 2 of the License, or (at your option) any later 13 | # version. 14 | # 15 | # eBay4R is distributed in the hope that it will be useful, but WITHOUT ANY 16 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 17 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 18 | # details. 19 | # 20 | # You should have received a copy of the GNU General Public License along with 21 | # eBay4R; if not, write to the Free Software Foundation, Inc., 51 Franklin 22 | # Street, Fifth Floor, Boston, MA 02110-1301, USA 23 | # 24 | #++ 25 | 26 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 27 | 28 | require 'test/unit' 29 | require 'eBayAPI' 30 | 31 | # This file must be in the current directory your $RUBYLIB environment var. 32 | load('myCredentials.rb') 33 | 34 | class TestRouting < Test::Unit::TestCase 35 | @@eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true, :site_id => 100) 36 | 37 | # If our routing works correctly, the GetCategories call should go to eBay Motors instead of default US site 38 | def test_ebay_motors_categories 39 | 40 | # Call "GetCategories" 41 | resp = @@eBay.GetCategories(:DetailLevel => 'ReturnAll', :CategorySideID => 100, :LevelLimit => 1) 42 | 43 | assert_respond_to(resp, "timestamp") 44 | assert_respond_to(resp, "ack") 45 | assert_equal(resp.ack, "Success") 46 | 47 | assert_equal(resp.categoryArray[0].categoryName, "eBay Motors") 48 | end 49 | 50 | end 51 | -------------------------------------------------------------------------------- /examples/get_notifications_usage.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 4 | require 'eBayAPI' 5 | 6 | # 7 | # Example of GetNotificationsUsage call 8 | # 9 | 10 | # Put your credentials in this file 11 | load('myCredentials.rb') 12 | 13 | # Create new eBay caller object. Omit last argument to use live platform. 14 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 15 | 16 | # Fill this in with a real item number to get more info about notifications 17 | item_no = '110029878327' 18 | 19 | if !item_no.empty? 20 | resp = eBay.GetNotificationsUsage(:ItemID => item_no) 21 | 22 | resp.notificationDetailsArray.each do |notif| 23 | puts "Delivery Status: " + notif.deliveryStatus 24 | puts "Delivery Time: " + notif.deliveryTime if notif.respond_to? 'deliveryTime' 25 | puts "Delivery URL: " + notif.deliveryURL 26 | puts "Error Message: " + notif.errorMessage 27 | puts "Expiration Time: " + notif.expirationTime 28 | puts "Next Retry Time: " + notif.nextRetryTime 29 | puts "Retries: " + notif.retries if notif.respond_to?('retries') && notif.retries 30 | # puts "Type: " + notif.type # Mmmm... "type" is already a method of Object 31 | end if resp.notificationDetailsArray.respond_to? 'notificationDetails' 32 | end 33 | 34 | resp = eBay.GetNotificationsUsage 35 | 36 | ns = resp.notificationStatistics 37 | 38 | puts "Current Counters: " 39 | puts " Delivered: " + ns.deliveredCount.to_s 40 | puts " Errors: " + ns.errorCount.to_s 41 | puts " Expired: " + ns.expiredCount.to_s 42 | puts " Queued New: " + ns.queuedNewCount.to_s 43 | puts " Queued Pending: " + ns.queuedPendingCount.to_s 44 | 45 | # More fields are present, see eBay's SOAP API Guide 46 | # 47 | # If you add on to this example with more fields, please send it to 48 | # gdolley@ucla.edu so I can include it with the next release :) 49 | -------------------------------------------------------------------------------- /examples/add_item.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # $Id: add_item.rb,v 1.11 2006/01/13 09:56:29 garrydolley Exp $ 3 | 4 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | require 'eBayAPI' 6 | 7 | # 8 | # Example of AddItem call 9 | # 10 | 11 | load('myCredentials.rb') 12 | 13 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 14 | 15 | # Shorter way of passing complex types (implied by hashing) than when we did in v0.5.2 and prior 16 | resp = eBay.AddItem(:Item => EBay.Item({ :PrimaryCategory => EBay.Category({ :CategoryID => 57882 }), 17 | :Title => 'Mouse Pad', 18 | :Description => 'A really cool mouse pad, you know you want it...', 19 | :Location => 'On Earth', 20 | :StartPrice => '12.0', 21 | :Quantity => 1, 22 | :ListingDuration => "Days_7", 23 | :Country => "US", 24 | :Currency => "USD", 25 | :PaymentMethods => ["VisaMC", "PersonalCheck"] })) 26 | 27 | puts "New Item #" + resp.itemID + " added." 28 | puts "You spent:\n" 29 | 30 | 31 | # The fees part of the response looks like this: 32 | # 33 | # 34 | # 35 | # AuctionLengthFee 36 | # 0.0 37 | # 38 | # 39 | # BoldFee 40 | # 0.0 41 | # 42 | # ... 43 | # 44 | # InsertionFee 45 | # 0.6 46 | # 47 | # ... 48 | # 49 | # 50 | # So this is now we traverse it: 51 | resp.fees.each do |fee| 52 | puts fee.name + ": " + fee.fee + " " + fee.fee.xmlattr_currencyID 53 | end 54 | 55 | # Notice how the object names reflect the XML element names, and any element 56 | # that is repeated automatically becomes an array, so you can run "each" on 57 | # it. 58 | -------------------------------------------------------------------------------- /examples/verify_add_item.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # $Id: verify_add_item.rb,v 1.9 2006/01/13 09:56:29 garrydolley Exp $ 3 | 4 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | require 'eBayAPI' 6 | 7 | # 8 | # Example of VerifyAddItem call 9 | # 10 | 11 | # Note: This example is almost exactly the same as AddItem, with the exception that an item doesn't 12 | # really get added to eBay's database, but all other relevant values are returned. 13 | 14 | load('myCredentials.rb') 15 | 16 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 17 | 18 | # Shorter way of passing complex types (implied by hashing) than when we did in v0.5.2 and prior 19 | resp = eBay.VerifyAddItem(:Item => EBay.Item({ :PrimaryCategory => EBay.Category(:CategoryID => 57882), 20 | :Title => 'Mouse Pad', 21 | :Description => 'A really cool mouse pad, you know you want it...', 22 | :Location => 'On Earth', 23 | :StartPrice => '12.0', 24 | :Quantity => 1, 25 | :ListingDuration => "Days_7", 26 | :Country => "US", 27 | :Currency => "USD", 28 | :PaymentMethods => ["VisaMC", "PersonalCheck"] })) 29 | 30 | puts "You would spend, if you really called AddItem, the following eBay fees:\n" 31 | 32 | 33 | # The fees part of the response looks like this: 34 | # 35 | # 36 | # 37 | # AuctionLengthFee 38 | # 0.0 39 | # 40 | # 41 | # BoldFee 42 | # 0.0 43 | # 44 | # ... 45 | # 46 | # InsertionFee 47 | # 0.6 48 | # 49 | # ... 50 | # 51 | # 52 | # So this is now we traverse it: 53 | resp.fees.each do |fee| 54 | puts fee.name + ": " + fee.fee + " " + fee.fee.xmlattr_currencyID 55 | end 56 | 57 | # Notice how the object names reflect the XML element names, and any element 58 | # that is repeated automatically becomes an array, so you can run "each" on 59 | # it. 60 | -------------------------------------------------------------------------------- /lib/RequesterCredentialsHandler.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # 3 | # $Id: RequesterCredentialsHandler.rb,v 1.3 2005/12/21 02:12:20 garrydolley Exp $ 4 | # 5 | # Copyright (c) 2005 Garry C. Dolley 6 | # 7 | # This file is part of eBay4R. 8 | # 9 | # eBay4R is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License as published by the Free Software 11 | # Foundation; either version 2 of the License, or (at your option) any later 12 | # version. 13 | # 14 | # eBay4R is distributed in the hope that it will be useful, but WITHOUT ANY 15 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 | # details. 18 | # 19 | # You should have received a copy of the GNU General Public License along with 20 | # eBay4R; if not, write to the Free Software Foundation, Inc., 51 Franklin 21 | # Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | # 23 | #++ 24 | 25 | require 'soap/header/simplehandler' 26 | 27 | module EBay 28 | 29 | class RequesterCredentialsHandler < SOAP::Header::SimpleHandler 30 | HeaderName = XSD::QName.new('urn:ebay:apis:eBLBaseComponents', 'RequesterCredentials') 31 | Credentials = XSD::QName.new('urn:ebay:apis:eBLBaseComponents', 'Credentials') 32 | 33 | EbayAuthToken = XSD::QName.new(nil, 'n1:eBayAuthToken') 34 | DevId = XSD::QName.new(nil, 'n1:DevId') 35 | AppId = XSD::QName.new(nil, 'n1:AppId') 36 | AuthCert = XSD::QName.new(nil, 'n1:AuthCert') 37 | 38 | def initialize(eBayAuthToken, devId, appId, authCert) 39 | super(HeaderName) 40 | @token, @devId, @appId, @cert = eBayAuthToken, devId, appId, authCert 41 | end 42 | 43 | def on_simple_outbound 44 | creds = { Credentials => { DevId => @devId, AppId => @appId, AuthCert => @cert } } 45 | 46 | # In a handful of calls mostly related to generating tokens in 47 | # multiple-user applications (ex. GetSessionID), you don't want to pass 48 | # in a token (or an empty eBayAuthToken node) 'cuz you're still in the 49 | # process of getting one. 50 | creds.merge!({ EbayAuthToken => @token }) unless @token.nil? || @token.empty? 51 | 52 | return creds 53 | end 54 | end 55 | 56 | end 57 | -------------------------------------------------------------------------------- /examples/get_notification_preferences.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 4 | require 'eBayAPI' 5 | 6 | # 7 | # Example of GetNotificationPreferences call 8 | # 9 | 10 | # Put your credentials in this file 11 | load('myCredentials.rb') 12 | 13 | # Create new eBay caller object. Omit last argument to use live platform. 14 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 15 | 16 | resp = eBay.GetNotificationPreferences(:PreferenceLevel => 'User') 17 | 18 | if resp.respond_to?('userDeliveryPreferenceArray') && resp.userDeliveryPreferenceArray 19 | resp.userDeliveryPreferenceArray.each do |pref| 20 | puts "Event Enable: " + pref.eventEnable 21 | puts "Event Type: " + pref.eventType 22 | end 23 | end 24 | 25 | begin 26 | resp = eBay.GetNotificationPreferences(:PreferenceLevel => 'Application') 27 | 28 | if resp.respond_to?('applicationDeliveryPreferences') 29 | [resp.applicationDeliveryPreferences].flatten.each do |pref| 30 | puts "Alert Email: " + pref.alertEmail.to_s if pref.respond_to? 'alertEmail' 31 | puts "Alert Enable: " + pref.alertEnable if pref.respond_to? 'alertEnable' 32 | puts "Application Enable: " + pref.applicationEnable if pref.respond_to? 'applicationEnable' 33 | puts "Application URL: " + pref.applicationURL.to_s if pref.respond_to? 'applicationURL' 34 | puts "Device Type: " + pref.deviceType if pref.respond_to? 'deviceType' 35 | puts "Notification Payload: " + pref.notificationPayloadType if pref.respond_to? 'notificationPayloadType' 36 | end 37 | end 38 | rescue EBay::Error::ApplicationError => boom 39 | puts boom.message 40 | end 41 | 42 | begin 43 | resp = eBay.GetNotificationPreferences(:PreferenceLevel => 'Event') 44 | 45 | if resp.respond_to?('eventProperty') && resp.eventProperty 46 | [resp.eventProperty].flatten.each do |e| 47 | puts "Event Type: " + e.eventType 48 | puts "Name: " + e.name 49 | puts "Value: " + e.value 50 | end 51 | end 52 | rescue EBay::Error::ApplicationError => boom 53 | puts boom.message 54 | end 55 | 56 | # More fields are present, see eBay's SOAP API Guide 57 | # 58 | # If you add on to this example with more fields, please send it to 59 | # gdolley@ucla.edu so I can include it with the next release :) 60 | -------------------------------------------------------------------------------- /examples/add_item2.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # $Id: add_item.rb,v 1.11 2006/01/13 09:56:29 garrydolley Exp $ 3 | 4 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 5 | require 'eBayAPI' 6 | 7 | # 8 | # Example of AddItem call 9 | # 10 | 11 | load('myCredentials.rb') 12 | 13 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 14 | 15 | # Added some shipping options 16 | 17 | resp = eBay.AddItem(:Item => EBay.Item({ :PrimaryCategory => EBay.Category(:CategoryID => 57882), 18 | :Title => 'Mouse Pad', 19 | :Description => 'A really cool mouse pad, you know you want it...', 20 | :Location => 'USA', 21 | :StartPrice => '0.50', 22 | :BuyItNowPrice => '9.50', 23 | :Quantity => 1, 24 | :ShippingDetails => EBay.ShippingDetails( 25 | :ShippingServiceOptions => [ 26 | EBay.ShippingServiceOptions( 27 | :ShippingService => ShippingServiceCodeType::USPSPriority, 28 | :ShippingServiceCost => '0.0', 29 | :ShippingServiceAdditionalCost => '0.0'), 30 | EBay.ShippingServiceOptions( 31 | :ShippingService => ShippingServiceCodeType::USPSPriorityFlatRateBox, 32 | :ShippingServiceCost => '7.0', 33 | :ShippingServiceAdditionalCost => '0.0')]), 34 | :ShippingTermsInDescription => false, 35 | :ShipToLocations => "US", 36 | :ShipToLocations => "CA", 37 | :ListingDuration => "Days_7", 38 | :Country => "US", 39 | :Currency => "USD", 40 | :PayPalEmailAddress => "foobar@example.com", 41 | :PaymentMethods => ["VisaMC", "PayPal"] })) 42 | 43 | 44 | puts "New Item #" + resp.itemID + " added." 45 | puts "You spent:\n" 46 | 47 | 48 | # The fees part of the response looks like this: 49 | # 50 | # 51 | # 52 | # AuctionLengthFee 53 | # 0.0 54 | # 55 | # 56 | # BoldFee 57 | # 0.0 58 | # 59 | # ... 60 | # 61 | # InsertionFee 62 | # 0.6 63 | # 64 | # ... 65 | # 66 | # 67 | # So this is now we traverse it: 68 | resp.fees.each do |fee| 69 | puts fee.name + ": " + fee.fee + " " + fee.fee.xmlattr_currencyID 70 | end 71 | 72 | # Notice how the object names reflect the XML element names, and any element 73 | # that is repeated automatically becomes an array, so you can run "each" on 74 | # it. 75 | -------------------------------------------------------------------------------- /contrib/ebay_platform_notifications.txt: -------------------------------------------------------------------------------- 1 | [Author's note: the example code for SetNotificationPreferences below is old 2 | and won't work with eBay4R v1.0 or above. See 3 | examples/set_notification_preferences.rb for a more up-to-date code sample] 4 | 5 | Below is a bit of documentation contributed by David Balatero regarding eBay 6 | Platform Notifications: 7 | 8 | Tips on how to handle eBay Platform Notifications within a Rails app 9 | ==================================================================== 10 | 11 | One quick way to handle incoming notifications from eBay is to setup a Rails 12 | controller to receive them. There are a few tricks you need to do in order to 13 | receive them, however. 14 | 15 | 1. First, you need to create a controller. 16 | 17 | script/generate controller Ebay 18 | 19 | 2. Next, you need to tell eBay to send all notifications to this new controller. 20 | You can do this from script/console, if you want (just make sure that in the 21 | console, you load the appropriate eBay4r classes) 22 | 23 | {{{ 24 | @ebay = EBay::API.new('auth_token', 'dev_id', 'app_id', 'cert_id', :sandbox => true) 25 | resp = @ebay.SetNotificationPreferences(:ApplicationDeliveryPreferences => { 26 | :ApplicationEnable => 'Enable', 27 | :ApplicationURL => 'http://' + request.env["SERVER_NAME"] + '/ebay/notification', 28 | :NotificationPayloadType => 'eBLSchemaSOAP' }, 29 | :UserDeliveryPreferenceArray => { 30 | :NotificationEnable => [ 31 | { :EventEnable => 'Enable', 32 | :EventType => 'EndOfAuction' }, 33 | { :EventEnable => 'Enable', 34 | :EventType => 'Feedback' }, 35 | { :EventEnable => 'Enable', 36 | :EventType => 'AskSellerQuestion' } 37 | ] 38 | }) 39 | }}} 40 | 41 | 3. Finally, you need to write some controller methods to handle the incoming notifications. 42 | 43 | {{{ 44 | def notification 45 | # Grab the raw SOAP XML into a string 46 | post_data = request.raw_post 47 | 48 | # Unmarshal the XML into a SOAP object 49 | resp = SOAP::Marshal.unmarshal(post_data) 50 | 51 | # Now it's business as usual -- use the resp object like you would 52 | # use any outgoing eBay call object. 53 | 54 | case resp.notificationEventName 55 | when 'AskSellerQuestion' 56 | # code here 57 | when 'EndOfAuction' 58 | # end of auction code 59 | when 'Feedback' 60 | # feedback received code 61 | end 62 | end 63 | }}} 64 | 65 | 66 | Hope this helps! 67 | 68 | - David Balatero ezwelty [at] NOSPAM- u.washington.edu 69 | -------------------------------------------------------------------------------- /RELEASE_NOTES: -------------------------------------------------------------------------------- 1 | RELEASE NOTES 2 | ------------- 3 | 4 | pending v1.2: 5 | 6 | * Upgraded to eBay API 583 7 | 8 | * Added support for calling the API without a user token, which is necessary 9 | to ask for tokens in multiple user applications via the 10 | GetSessionID/FetchToken flow 11 | 12 | * Added a Rakefile. Tests can now be run by just running 'rake'. This was 13 | late in coming, I know. 14 | 15 | v1.1: 16 | 17 | * Upgraded to eBay API 555 18 | 19 | * See the very important changes in v1.0 below. 20 | 21 | v1.0: 22 | 23 | * Upgraded to eBay API 529 24 | 25 | * I never made a tarball/gem of this release, but if you really want API 529 26 | instead of the newer 555, grab the "releases/1.0" tag from the git repo. 27 | 28 | **IMPORTANT** 29 | 30 | For all but the simplest of calls to eBay's API, you will need to make 31 | changes to your code if you are upgrading from previous versions of eBay4R. 32 | 33 | There were some subtle, but very important, changes. The version of SOAP4R 34 | needed to use eBay's newer API versions changes the way we interact with 35 | certain data types. 36 | 37 | * AmountType fields must be strings, implicit conversion from float no longer 38 | occurs in SOAP4R 1.5.7+. For example, previously you could have:: 39 | 40 | :StartPrice => 12.0 41 | 42 | but now it must be:: 43 | 44 | :StartPrice => '12.0' 45 | 46 | * Dependency SOAP4R 1.5.7+ has better support for arrays. Notice how the 47 | test/tc_routing.rb test had to be changed:: 48 | 49 | - assert_equal(resp.categoryArray.category.categoryName, "eBay Motors") 50 | + assert_equal(resp.categoryArray[0].categoryName, "eBay Motors") 51 | 52 | When single element arrays are returned in the SOAP response, you now 53 | access them with the familiar Ruby array index, instead of following the 54 | XML tree and putting "." in between each node. 55 | 56 | Another example of before/after (from examples/add_item.rb): 57 | 58 | Old:: 59 | 60 | resp.fees.fee.each do |fee| 61 | 62 | New:: 63 | 64 | resp.fees.each do |fee| 65 | 66 | * Short-hand way of creating complex data types no longer works. I think 67 | older SOAP4R's gave me this for free, but upon looking at the XML dump a 68 | second time, it doesn't create the objects correctly. Not sure if eBay's 69 | API in the 4xx range silently ignored these bad values. If anyone can get 70 | this working again, send me a patch. 71 | 72 | Old:: 73 | 74 | resp = eBay.AddItem(:Item => { :PrimaryCategory => { :CategoryID => 57882 }, 75 | ... 76 | ... 77 | }) 78 | 79 | New:: 80 | 81 | resp = eBay.AddItem(:Item => EBay.Item(:PrimaryCategory => EBay.Category(:CategoryID => 57882), 82 | ... 83 | ... 84 | }) 85 | 86 | * SetNotificationPreferences suffers the most (of the examples) from the 87 | above changes. See examples/set_notification_preferences.rb to see how 88 | it's done now. 89 | -------------------------------------------------------------------------------- /test/tc_items.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | #-- 4 | # $Id: tc_items.rb,v 1.3 2006/01/07 07:57:15 garrydolley Exp $ 5 | # 6 | # Copyright (c) 2005 Garry C. Dolley 7 | # 8 | # This file is part of eBay4R. 9 | # 10 | # eBay4R is free software; you can redistribute it and/or modify it under the 11 | # terms of the GNU General Public License as published by the Free Software 12 | # Foundation; either version 2 of the License, or (at your option) any later 13 | # version. 14 | # 15 | # eBay4R is distributed in the hope that it will be useful, but WITHOUT ANY 16 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 17 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 18 | # details. 19 | # 20 | # You should have received a copy of the GNU General Public License along with 21 | # eBay4R; if not, write to the Free Software Foundation, Inc., 51 Franklin 22 | # Street, Fifth Floor, Boston, MA 02110-1301, USA 23 | # 24 | #++ 25 | 26 | $:.unshift File.join(File.dirname(__FILE__), "..", "lib") 27 | 28 | require 'test/unit' 29 | require 'eBayAPI' 30 | 31 | # This file must be in the current directory your $RUBYLIB environment var. 32 | load('myCredentials.rb') 33 | 34 | class TestItems < Test::Unit::TestCase 35 | @@item_title = 'eBay4R Test Case Item'; 36 | @@item_descr = 'eBay API for Ruby @ http://ebay4r.rubyforge.org/'; 37 | 38 | @@eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 39 | 40 | def test_add_item 41 | resp = @@eBay.AddItem(:Item => EBay.Item(:PrimaryCategory => EBay.Category(:CategoryID => 57882), 42 | :Title => @@item_title, 43 | :Description => @@item_descr, 44 | :Location => 'RubyForge', 45 | :StartPrice => '12.0', 46 | :Quantity => 1, 47 | :ListingDuration => "Days_7", 48 | :Country => "US", 49 | :Currency => "USD", 50 | :PaymentMethods => ["VisaMC", "PersonalCheck"], 51 | :ShippingDetails => EBay.ShippingDetails( 52 | :ShippingType => 'Flat', 53 | :ShippingServiceOptions => EBay.ShippingServiceOptions( 54 | :ShippingService => "USPSMedia", 55 | :ShippingServiceCost => '2.50')))) 56 | 57 | assert_respond_to(resp, "timestamp") 58 | assert_respond_to(resp, "ack") 59 | assert_equal(resp.ack, "Success") 60 | 61 | assert_respond_to(resp, "itemID") 62 | assert_not_nil(resp.itemID) 63 | 64 | @@item_id = resp.itemID 65 | 66 | assert_respond_to(resp, "fees") 67 | end 68 | 69 | def test_add_item_no_params 70 | assert_raise(EBay::Error::ApplicationError) { @@eBay.AddItem() } 71 | end 72 | 73 | def test_get_item 74 | resp = @@eBay.GetItem(:DetailLevel => 'ReturnAll', :ItemID => @@item_id) 75 | 76 | assert_respond_to(resp, "timestamp") 77 | assert_respond_to(resp, "ack") 78 | assert_equal(resp.ack, "Success") 79 | 80 | assert_equal(resp.item.title, @@item_title) 81 | assert_equal(resp.item.description, @@item_descr) 82 | end 83 | 84 | end 85 | -------------------------------------------------------------------------------- /lib/eBayAPI.rb: -------------------------------------------------------------------------------- 1 | #-- 2 | # $Id: eBayAPI.rb,v 1.31 2006/10/10 08:04:52 garrydolley Exp $ 3 | # 4 | # Copyright (c) 2005,2006 Garry C. Dolley 5 | # 6 | # This file is part of eBay4R. 7 | # 8 | # eBay4R is free software; you can redistribute it and/or modify it under the 9 | # terms of the GNU General Public License as published by the Free Software 10 | # Foundation; either version 2 of the License, or (at your option) any later 11 | # version. 12 | # 13 | # eBay4R is distributed in the hope that it will be useful, but WITHOUT ANY 14 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 | # details. 17 | # 18 | # You should have received a copy of the GNU General Public License along with 19 | # eBay4R; if not, write to the Free Software Foundation, Inc., 51 Franklin 20 | # Street, Fifth Floor, Boston, MA 02110-1301, USA 21 | # 22 | #++ 23 | 24 | #:main: README 25 | 26 | # Load SOAP4R from gem if it is available, suitable for most users. 27 | # 28 | # The gem will most likely be newer than the Ruby built-in SOAP4R and so we 29 | # want to avoid the error: 30 | # 31 | # uninitialized constant SOAP::Mapping::EncodedRegistry 32 | # 33 | # If you have a different version of SOAP4R in a directory included in $RUBYLIB 34 | # *and* you want to use that version instead of the gem you also have 35 | # installed, you will most likely have to comment out this block. 36 | begin 37 | require 'rubygems' 38 | gem 'soap4r' 39 | rescue Exception 40 | nil 41 | end 42 | 43 | require 'eBayDriver.rb' 44 | require 'RequesterCredentialsHandler.rb' 45 | 46 | module EBay 47 | 48 | # This is the main class of the eBay4R library. Start by instantiating this class (see below) 49 | class API 50 | attr_writer :debug 51 | 52 | # Creates an eBay caller object. 53 | # 54 | # You will need this object to make any API calls to eBay's servers, so instantiation is required 55 | # before you can use any other part of this library. 56 | # 57 | # :call-seq: 58 | # new(auth_token, dev_id, app_id, cert_id) 59 | # new(auth_token, dev_id, app_id, cert_id, :sandbox => true) 60 | # new(auth_token, dev_id, app_id, cert_id, :sandbox => false, :site_id => 3) 61 | # 62 | # The first four (4) arguments are required (all String's): 63 | # 64 | # auth_token = Your eBay Authentication Token 65 | # dev_id = Your eBay Developer's ID 66 | # app_id = Your eBay Application ID 67 | # cert_id = Your eBay Certificate ID 68 | # 69 | # The optional fifth argument is a hash where you can pass additional info to refine the caller 70 | # object. 71 | # 72 | # The key "sandbox", for example: 73 | # 74 | # eBay = EBay::API.new("my_auth_tok", "dev_id", "cert_id", "app_id", :sandbox => true) 75 | # 76 | # creates a caller that works with the eBay "sandbox" environment. By default, the "live" 77 | # environment is used. 78 | # 79 | # You may also pass the key "site_id" to specify calls to be routed to international or 80 | # special (e.g. "eBay Motors") sites. 81 | # 82 | def initialize(auth_token, dev_id, app_id, cert_id, opt = {}) 83 | @ver = 583 84 | @debug = false 85 | @app_id = app_id 86 | @header_handler = RequesterCredentialsHandler.new(auth_token, dev_id, app_id, cert_id) 87 | 88 | # Default to 'US' (SiteID = 0) site 89 | @site_id = opt[:site_id] ? opt[:site_id] : '0' 90 | 91 | shost = opt[:sandbox] ? "sandbox." : "" 92 | 93 | @endpoint_url = "https://api.#{shost}ebay.com/wsapi" 94 | 95 | XSD::Charset.encoding = 'UTF8' # Thanks to Ray Hildreth 96 | end 97 | 98 | def method_missing(m, *args) #:nodoc: 99 | call_name = EBay::fix_case_up(m.id2name) # upper first character 100 | 101 | @callName = call_name.dup 102 | args_hash = args[0] 103 | 104 | if valid_call?(call_name) 105 | service = makeService 106 | request = eval("#{call_name}RequestType.new") 107 | 108 | request.version = @ver 109 | 110 | EBay::assign_args(request, args_hash) 111 | EBay::fix_case_down(call_name) 112 | 113 | verbose_obj_save = $VERBOSE 114 | $VERBOSE = nil # Suppress "warning: peer certificate won't be verified in this SSL session" 115 | 116 | resp = eval("service.#{call_name}(request)") 117 | 118 | $VERBOSE = verbose_obj_save # Restore verbosity to previous state 119 | 120 | # Handle eBay Application-level error 121 | if resp.ack == "Failure" 122 | err_string = '' 123 | 124 | if resp.errors.is_a?(Array) # Something tells me there is a better way to do this 125 | resp.errors.each do |err| 126 | err_string += err.shortMessage.chomp(".") + ", " 127 | end 128 | err_string = err_string.chop.chop 129 | else 130 | err_string = resp.errors.shortMessage 131 | end 132 | 133 | raise(Error::ApplicationError.new(resp), "#{@callName} Call Failed: #{err_string}", caller) 134 | end 135 | 136 | return resp 137 | else 138 | raise(Error::UnknownAPICall, "Unknown API Call: #{call_name}", caller) 139 | end 140 | end 141 | 142 | private 143 | def requestURL 144 | "#{@endpoint_url}?callname=#{@callName}&siteid=#{@site_id}&appid=#{@app_id}&version=#{@ver}&routing=default" 145 | end 146 | 147 | def makeService 148 | service = EBayAPIInterface.new(requestURL()) 149 | service.headerhandler << @header_handler 150 | service.wiredump_dev = STDOUT if @debug 151 | 152 | # I believe the line below will work after we get the kinks worked out w/ http-access2 153 | # service.options['protocol.http.ssl_config.verify_mode'] = OpenSSL::SSL::VERIFY_NONE 154 | 155 | return service 156 | end 157 | 158 | def valid_call?(call) 159 | call = EBay::fix_case_down(String.new(call)) # lower first character 160 | EBayAPIInterface::Methods.each { |defs| return true if defs[1] == call } 161 | 162 | return false 163 | end 164 | 165 | end 166 | 167 | # Exception container 168 | class Error 169 | #:stopdoc: 170 | class Error < StandardError; end 171 | #:startdoc: 172 | 173 | # Raised if a call is made to a method that does not exist in the eBay SOAP API 174 | class UnknownAPICall < Error; end 175 | 176 | # Raised if an attempt is made to instantiate a type that does not exist in the eBay SOAP API 177 | class UnknownType < Error; end 178 | 179 | # Raised if a call returns with Failure. The _resp_ attribute contains the full failed response. 180 | class ApplicationError < Error; 181 | attr_reader :resp 182 | 183 | def initialize(response) 184 | @resp = response 185 | end 186 | end 187 | end 188 | 189 | #:enddoc: 190 | 191 | # These class module methods are for creating complex types (e.g. ItemType, CategoryType, etc...) 192 | # and also include some helper functions 193 | class < true) 155 | eBay.debug = true if debug 156 | 157 | parents_to_process = [ :id => '', :depth => 0 ] 158 | 159 | # 160 | # Traverse entire category tree and import into our database 161 | # 162 | 163 | puts "Starting import... Go get some coffee, this is going to take a while..." 164 | 165 | imported_site_wide_info = false 166 | i = 0 167 | while (some_parents = parents_to_process.first(concurrency)).length > 0 168 | seek_depth = some_parents.max { |a,b| a[:depth] <=> b[:depth] } 169 | seek_depth = seek_depth[:depth] + 1 170 | 171 | if debug 172 | puts "Current process queue:" 173 | p parents_to_process 174 | puts "Up next:" 175 | p some_parents 176 | end 177 | 178 | resp = eBay.GetCategories(:DetailLevel => 'ReturnAll', # Return all available info 179 | :CategorySideID => site_id, 180 | :CategoryParent => (some_parents[0][:id] == '' && some_parents.length == 1) ? '' : some_parents.collect { |a| a[:id] }, 181 | :ViewAllNotes => true, 182 | :LevelLimit => seek_depth) 183 | 184 | parents_to_process -= some_parents 185 | 186 | if !imported_site_wide_info 187 | mysql.query("DELETE FROM #{table_name}_info WHERE site_id = #{site_id}") 188 | 189 | mysql.query("INSERT INTO #{table_name}_info VALUES (null, '#{site_id}', '#{resp.categoryVersion}', '#{resp.minimumReservePrice}', #{resp.reduceReserveAllowed}, 190 | #{resp.reservePriceAllowed}, '#{resp.updateTime}')") 191 | 192 | imported_site_wide_info = true 193 | end 194 | 195 | if resp.categoryCount.to_i > 0 196 | resp.categoryArray.each do |cat| 197 | if cat.categoryLevel.to_i == seek_depth 198 | if cat.leafCategory == "false" 199 | parents_to_process << { :id => cat.categoryID, :depth => cat.categoryLevel.to_i } 200 | puts "Added Category ##{cat.categoryID} to process queue..." if debug 201 | end 202 | end 203 | 204 | # Make sure we don't try to INSERT a category we already have 205 | r = mysql.query("SELECT category_id FROM #{table_name} WHERE category_id = #{cat.categoryID} AND site_id = #{site_id}") 206 | 207 | if r.num_rows < 1 208 | if cat.categoryID == cat.categoryParentID 209 | cat.categoryParentID = "null" 210 | else 211 | cat.categoryParentID = "'#{cat.categoryParentID}'" 212 | end 213 | 214 | cat.categoryName = mysql.escape_string(cat.categoryName) 215 | 216 | # Determine values of conditional fields 217 | auto_pay = cat.respond_to?(:autoPayEnabled) ? cat.autoPayEnabled : false 218 | b2b_vat = cat.respond_to?(:b2BVATEnabled) ? cat.b2BVATEnabled : false 219 | best_offer = cat.respond_to?(:bestOfferEnabled) ? cat.bestOfferEnabled : false 220 | orra = cat.respond_to?(:oRRA) ? cat.oRRA : false 221 | sge = cat.respond_to?(:sellerGuaranteeEligible) ? cat.sellerGuaranteeEligible : false 222 | 223 | puts "Inserting Category ##{cat.categoryID}: #{cat.categoryName}..." if debug 224 | 225 | # 226 | # Do the actual writing to the database 227 | # 228 | mysql.query("INSERT INTO #{table_name} 229 | VALUES (null, '#{site_id}', '#{cat.categoryID}', #{cat.categoryParentID}, '#{cat.categoryName}', '#{cat.categoryLevel}', #{cat.leafCategory}, 230 | #{cat.expired}, #{cat.virtual}, #{auto_pay}, #{b2b_vat}, #{best_offer}, #{cat.intlAutosFixedCat}, #{cat.lSD}, #{cat.oRPA}, #{orra}, 231 | #{sge})") 232 | 233 | i += 1 234 | puts "Imported #{i} categories so far..." if i % 100 == 0 235 | end 236 | end 237 | end 238 | end 239 | 240 | mysql.close 241 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | ================= 2 | Welcome to eBay4R 3 | ================= 4 | 5 | :Author: Garry Dolley 6 | :Date: 03-28-2008 7 | :Version: v1.1 8 | :eBay API: 583 9 | 10 | eBay4R is a Ruby wrapper for eBay's Web Services SOAP API (v583). Emphasis is 11 | on ease of use and small footprint. 12 | 13 | Please report bugs and other problems, see "Author" section at the bottom. 14 | 15 | Current release can be downloaded from: 16 | 17 | http://rubyforge.org/projects/ebay4r 18 | 19 | The latest code is available at both RubyForge and GitHub: 20 | 21 | * git://rubyforge.org/ebay4r.git 22 | * git://github.com/up_the_irons/ebay4r.git 23 | 24 | 25 | Requirements 26 | ------------ 27 | 28 | * SOAP4R library v1.5.7 or newer. The specific version I'm using for testing 29 | is soap4r-1.5.7.90.20070921. 30 | 31 | 32 | Optionals 33 | --------- 34 | 35 | * RubyGems 36 | 37 | 38 | Installation 39 | ------------ 40 | 41 | tar/gzip 42 | ~~~~~~~~ 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 | 51 | * To install a gem you already downloaded:: 52 | 53 | gem install ebay-.gem 54 | 55 | * For the latest release with no fuss (previous download not required):: 56 | 57 | gem install -r ebay 58 | 59 | Git 60 | ~~~ 61 | 62 | You can download the latest and greatest code using Git, just type:: 63 | 64 | git clone git://github.com/up_the_irons/ebay4r.git 65 | 66 | 67 | Important Note about Using eBay4R and Ruby on Rails 68 | --------------------------------------------------- 69 | 70 | If you installed SOAP4R as a gem you must put the following two lines at the 71 | very top of your config/environment.rb:: 72 | 73 | require 'rubygems' 74 | gem 'soap4r' 75 | 76 | This must be done before Rails starts auto-loading things. 77 | 78 | Additionally, you have to put those two lines in *every* Rails app you have 79 | on your machine, even if it doesn't use SOAP4R! This is, allegedly, because 80 | ActiveSupport (in dependency.rb) wrongly loads the SOAP4R included with Ruby 81 | instead of your Gem. More details can be found here: 82 | 83 | http://dev.ctor.org/soap4r/ticket/433 84 | 85 | If you get this error, or similar, in every Rails app:: 86 | 87 | [...]/activesupport-1.4.2/lib/active_support/dependencies.rb:477:in `const_missing': uninitialized constant XSD::NS::KNOWN_TAG (NameError?) 88 | 89 | you've hit this problem. 90 | 91 | 92 | Getting Started 93 | --------------- 94 | 95 | If you installed eBay4R from a tarball or git repo, you will want to add the 96 | ebay4r/lib directory to your Ruby include path ($RUBYLIB). Then put 97 | 98 | :: 99 | 100 | require 'eBayAPI' 101 | 102 | at the top of your programs. 103 | 104 | If you installed eBay4R with RubyGems, you don't have to add anything to 105 | Ruby's include path, just put 106 | 107 | :: 108 | 109 | require 'rubygems' 110 | gem 'ebay' 111 | 112 | at the top of your programs. 113 | 114 | Examples 115 | -------- 116 | 117 | Look at the examples/ directory. Edit the file myCredentials.rb and insert 118 | the appropriate values. Then you can run any of the example programs. 119 | 120 | Hello, World! 121 | ~~~~~~~~~~~~~ 122 | 123 | The simplest eBay API call is "GeteBayOfficialTime". Here's how to call it 124 | with eBay4R:: 125 | 126 | require 'rubygems' 127 | gem 'ebay' 128 | 129 | # Put your credentials in this file 130 | load('myCredentials.rb') 131 | 132 | # Create new eBay caller object. Omit last argument to use live platform. 133 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 134 | 135 | resp = eBay.GeteBayOfficialTime 136 | 137 | puts "Hello, World!" 138 | puts "The eBay time is now: #{resp.timestamp}" 139 | 140 | # Wasn't that easy?! 141 | 142 | Adding an Item 143 | ~~~~~~~~~~~~~~ 144 | 145 | This is a more complex example that performs a real (useful) function:: 146 | 147 | require 'rubygems' 148 | gem 'ebay' 149 | 150 | load('myCredentials.rb') 151 | 152 | eBay = EBay::API.new($authToken, $devId, $appId, $certId, :sandbox => true) 153 | 154 | # Notice how we nest hashes to mimic the XML structure of an AddItem request 155 | resp = eBay.AddItem(:Item => EBay.Item(:PrimaryCategory => EBay.Category(:CategoryID => 57882), 156 | :Title => 'Mouse Pad', 157 | :Description => 'A really cool mouse pad, you know you want it...', 158 | :Location => 'On Earth', 159 | :StartPrice => '12.0', 160 | :Quantity => 1, 161 | :ListingDuration => "Days_7", 162 | :Country => "US", 163 | :Currency => "USD", 164 | :PaymentMethods => ["VisaMC", "PersonalCheck"])) 165 | 166 | puts "New Item #" + resp.itemID + " added." 167 | 168 | 169 | Don't worry too much about EBay.Item and EBay.Category calls for now, they are 170 | explained in the "Creating Complex Data Types" section below. 171 | 172 | 173 | Format of Requests 174 | ~~~~~~~~~~~~~~~~~~ 175 | 176 | If ``eBay`` is your caller object, then you can issue any eBay API call 177 | by doing:: 178 | 179 | eBay.( ... hash of named-arguments ... ) 180 | 181 | For example, to issue the GetItem call for Item #4503432058 and return all 182 | information, you do:: 183 | 184 | eBay.GetItem(:DetailLevel => 'ReturnAll', :ItemID => '4503432058') 185 | 186 | or to see your last invoice using the GetAccount call, you do:: 187 | 188 | eBay.GetAccount(:AccountHistorySelection => 'LastInvoice') 189 | 190 | See the "eBay Web Services SOAP API Guide" for acceptable parameters and values 191 | for each API call. This guide can be downloaded at eBay's 192 | `SOAP Development Center `_. 193 | 194 | Creating Complex Data Types 195 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 196 | 197 | A number of elements in eBay's schema are XML Schema simple types. For 198 | example, CategoryID, Title, and Description are all strings. But many 199 | elements, like Item and Seller, are of types "ItemType" and "SellerType", 200 | respectively. These are complex data types, meaning they are structures 201 | composed of collections of simple types. 202 | 203 | "How do I make a complex type object?", you ask. Simple:: 204 | 205 | EBay.( ... hash of named-arguments ... ) 206 | 207 | creates a new `` element of type ``Type``. For 208 | example, 209 | 210 | :: 211 | 212 | EBay.Item(:Title => 'Mouse Pad', :Description => '...') 213 | 214 | creates a new ``ItemType`` object. Please note, these factory methods are class 215 | methods of module EBay, so the upper-case "E" in "EBay" is not a typo. A 216 | more common way to see this is:: 217 | 218 | EBay::Item( ... ) 219 | 220 | The only difference is if you do not pass any arguments to the factory method 221 | and do not explicitly put empty parentheses (), Ruby will assume it is a 222 | constant, not a method. 223 | 224 | Setting XML Attributes 225 | ~~~~~~~~~~~~~~~~~~~~~~ 226 | 227 | The symbol you use to set an XML attribute on an element is:: 228 | 229 | :xmlattr_ 230 | 231 | For example, to create a