Class: EBay::API
- Inherits:
-
Object
- Object
- EBay::API
- Defined in:
- lib/eBayAPI.rb
Overview
This is the main class of the eBay4R library. Start by instantiating this class (see below)
Instance Attribute Summary collapse
-
#debug ⇒ Object
writeonly
Sets the attribute debug.
Instance Method Summary collapse
-
#initialize(auth_token, dev_id, app_id, cert_id, opt = {}) ⇒ API
constructor
Creates an eBay caller object.
-
#method_missing(m, *args) ⇒ Object
:nodoc:.
Constructor Details
#initialize(auth_token, dev_id, app_id, cert_id, opt = {}) ⇒ API
Creates an eBay caller object.
You will need this object to make any API calls to eBay’s servers, so instantiation is required before you can use any other part of this library.
:call-seq:
new(auth_token, dev_id, app_id, cert_id)
new(auth_token, dev_id, app_id, cert_id, <em>:sandbox => true</em>)
new(auth_token, dev_id, app_id, cert_id, <em>:sandbox => false, :site_id => 3</em>)
The first four (4) arguments are required (all String’s):
auth_token = Your eBay Authentication Token
dev_id = Your eBay Developer's ID
app_id = Your eBay Application ID
cert_id = Your eBay Certificate ID
The optional fifth argument is a hash where you can pass additional info to refine the caller object.
The key “sandbox”, for example:
eBay = EBay::API.new("my_auth_tok", "dev_id", "cert_id", "app_id", :sandbox => true)
creates a caller that works with the eBay “sandbox” environment. By default, the “live” environment is used.
You may also pass the key “site_id” to specify calls to be routed to international or special (e.g. “eBay Motors”) sites.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/eBayAPI.rb', line 65 def initialize(auth_token, dev_id, app_id, cert_id, opt = {}) @ver = 449 @debug = false @app_id = app_id @header_handler = RequesterCredentialsHandler.new(auth_token, dev_id, app_id, cert_id) # Default to 'US' (SiteID = 0) site @site_id = opt[:site_id] ? opt[:site_id] : '0' shost = opt[:sandbox] ? "sandbox." : "" @endpoint_url = "https://api.#{shost}ebay.com/wsapi" XSD::Charset.encoding = 'UTF8' # Thanks to Ray Hildreth end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
:nodoc:
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/eBayAPI.rb', line 81 def method_missing(m, *args) #:nodoc: call_name = EBay::fix_case_up(m.id2name) # upper first character @callName = call_name.dup args_hash = args[0] if valid_call?(call_name) service = makeService request = eval("#{call_name}RequestType.new") request.version = @ver EBay::assign_args(request, args_hash) EBay::fix_case_down(call_name) resp = eval("service.#{call_name}(request)") # Handle eBay Application-level error if resp.ack == "Failure" err_string = '' if resp.errors.is_a?(Array) # Something tells me there is a better way to do this resp.errors.each do |err| err_string += err.shortMessage.chomp(".") + ", " end err_string = err_string.chop.chop else err_string = resp.errors.shortMessage end raise(Error::ApplicationError.new(resp), "#{@callName} Call Failed: #{err_string}", caller) end return resp else raise(Error::UnknownAPICall, "Unknown API Call: #{call_name}", caller) end end |
Instance Attribute Details
#debug=(value) ⇒ Object (writeonly)
Sets the attribute debug
33 34 35 |
# File 'lib/eBayAPI.rb', line 33 def debug=(value) @debug = value end |