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.
-
#debug_io ⇒ Object
writeonly
Sets the attribute debug_io.
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.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/eBayAPI.rb', line 83 def initialize(auth_token, dev_id, app_id, cert_id, opt = {}) @ver = 925 @debug = false @debug_io = STDOUT @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:
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/eBayAPI.rb', line 100 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) verbose_obj_save = $VERBOSE $VERBOSE = nil # Suppress "warning: peer certificate won't be verified in this SSL session" resp = eval("service.#{call_name}(request)") $VERBOSE = verbose_obj_save # Restore verbosity to previous state # 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.longMessage.chomp(".") + ", " end err_string = err_string.chop.chop else err_string = resp.errors.longMessage 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
50 51 52 |
# File 'lib/eBayAPI.rb', line 50 def debug=(value) @debug = value end |
#debug_io=(value) ⇒ Object (writeonly)
Sets the attribute debug_io
51 52 53 |
# File 'lib/eBayAPI.rb', line 51 def debug_io=(value) @debug_io = value end |