Class: EBay::API

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/eBayAPI.rb', line 82

def initialize(auth_token, dev_id, app_id, cert_id, opt = {})
  @ver = 529
  @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:



98
99
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
# File 'lib/eBayAPI.rb', line 98

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.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

Parameters:

  • value

    the value to set the attribute debug to.



50
51
52
# File 'lib/eBayAPI.rb', line 50

def debug=(value)
  @debug = value
end