Class: EbayTrader::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ebay_trader/configuration.rb

Constant Summary collapse

URI_PRODUCTION =

URL for eBay’s Trading API Production environment.

'https://api.ebay.com/ws/api.dll'
URI_SANDBOX =

URL for eBay’s Trading API Sandbox environment.

'https://api.sandbox.ebay.com/ws/api.dll'
DEFAULT_AUTH_TOKEN_KEY =
'__DEFAULT__'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ebay_trader/configuration.rb', line 80

def initialize
  self.environment = :sandbox
  @dev_id = nil
  @environment = :sandbox

  @dev_id  = nil
  @app_id  = nil
  @cert_id = nil

  @ebay_site_id = 0
  @ebay_api_version = 935   # 2015-Jul-24
  @http_timeout = 30        # seconds

  @price_type = :big_decimal

  @username_auth_tokens = {}

  @ssl_verify = true
end

Instance Attribute Details

#app_idString

Returns Application keys App ID.

Returns:

  • (String)

    Application keys App ID.



22
23
24
# File 'lib/ebay_trader/configuration.rb', line 22

def app_id
  @app_id
end

#cert_idString

Returns Application keys Certificate ID.

Returns:

  • (String)

    Application keys Certificate ID.



25
26
27
# File 'lib/ebay_trader/configuration.rb', line 25

def cert_id
  @cert_id
end

#counter_callbackProc (readonly)

Returns an optional Proc or Lambda to record application level API request call volume.

Returns:

  • (Proc)

    an optional Proc or Lambda to record application level API request call volume.



60
61
62
# File 'lib/ebay_trader/configuration.rb', line 60

def counter_callback
  @counter_callback
end

#dev_idString

The Dev ID application key.

Returns:

  • (String)

    Application keys Developer ID.



19
20
21
# File 'lib/ebay_trader/configuration.rb', line 19

def dev_id
  @dev_id
end

#ebay_api_versionFixnum

Returns the eBay Trading API version.

Returns:

  • (Fixnum)

    the eBay Trading API version.

See Also:



39
40
41
# File 'lib/ebay_trader/configuration.rb', line 39

def ebay_api_version
  @ebay_api_version
end

#ebay_site_idFixnum

This can be overridden by including an ebay_site_id value in the list of arguments to Request#initialize.

Returns:

  • (Fixnum)

    The default eBay site ID to use in API requests, default is 0.

See Also:



35
36
37
# File 'lib/ebay_trader/configuration.rb', line 35

def ebay_site_id
  @ebay_site_id
end

#http_timeoutFixnum (readonly)

Returns the number of seconds before the HTTP session times out.

Returns:

  • (Fixnum)

    the number of seconds before the HTTP session times out.



46
47
48
# File 'lib/ebay_trader/configuration.rb', line 46

def http_timeout
  @http_timeout
end

#price_typeSymbol

Set the type of object to be used to represent price values, with the default being :big_decimal.

  • :big_decimal expose price values as BigDecimal

  • :money expose price values as Money objects, but only if the Money gem is available to your app.

  • :fixnum expose price values as Fixnum

  • :integer expose price values as Fixnum

  • :float expose price values as Float - not recommended!

Returns:

  • (Symbol)

    :big_decimal, :money, :fixnum or :float



57
58
59
# File 'lib/ebay_trader/configuration.rb', line 57

def price_type
  @price_type
end

#ru_nameString

Returns the eBay RuName for the application.

Returns:

  • (String)

    the eBay RuName for the application.

See Also:



43
44
45
# File 'lib/ebay_trader/configuration.rb', line 43

def ru_name
  @ru_name
end

#ssl_verifyBoolean|String

Specify if the SSL certificate should be verified, true by default. It is recommended that all SSL certificates are verified to prevent man-in-the-middle type attacks.

One potential reason for temporarily deactivating verification is when certificates expire, which they periodically do, and you need to take emergency steps to keep your service running. In such cases you may see the following error message:

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed


78
79
80
# File 'lib/ebay_trader/configuration.rb', line 78

def ssl_verify
  @ssl_verify
end

#uriURI

sandbox and production environments.

Returns:

  • (URI)

    Get the URI for eBay API requests, which will be different for



29
30
31
# File 'lib/ebay_trader/configuration.rb', line 29

def uri
  @uri
end

Instance Method Details

#auth_tokenString

Get the default authentication token, or nil if not set.

Returns:

  • (String)

    the default auth token.



144
145
146
# File 'lib/ebay_trader/configuration.rb', line 144

def auth_token
  auth_token_for(DEFAULT_AUTH_TOKEN_KEY)
end

#auth_token=(auth_token) ⇒ Object

Optionally set a default authentication token to be used in API requests.

Parameters:

  • auth_token (String)

    the eBay auth token for the user making requests.



137
138
139
# File 'lib/ebay_trader/configuration.rb', line 137

def auth_token=(auth_token)
  map_auth_token(DEFAULT_AUTH_TOKEN_KEY, auth_token)
end

#auth_token_for(key) ⇒ String

Get the eBay API auth token matching the given key, or nil if not found.

Returns:

  • (String)

    the corresponding auth token, or nil.



164
165
166
# File 'lib/ebay_trader/configuration.rb', line 164

def auth_token_for(key)
  @username_auth_tokens[secure_auth_token_key(key)]
end

#counter=(callback) ⇒ Proc

Provide a callback to track the number of eBay API calls made.

As eBay rations the number of API calls you can make in a single day, typically to 5_000, it is advisable to record the volume of calls submitted. Here you can provide an application level callback that will be called during each API Request.

Parameters:

  • callback (Proc|lambda)

    to be called during each eBay API request call.

Returns:

  • (Proc)


178
179
180
# File 'lib/ebay_trader/configuration.rb', line 178

def counter=(callback)
  @counter_callback = callback if callback && callback.is_a?(Proc)
end

#environment=(env) ⇒ Symbol

Set the eBay environment to either :sandbox or :production. If the value of env is not recognized :sandbox will be assumed.

Parameters:

  • env (Symbol)

    :sandbox or :production

Returns:

  • (Symbol)

    :sandbox or :production



106
107
108
109
110
# File 'lib/ebay_trader/configuration.rb', line 106

def environment=(env)
  @environment = (env.to_s.downcase.strip == 'production') ? :production : :sandbox
  @uri = URI.parse(production? ? URI_PRODUCTION : URI_SANDBOX)
  @environment
end

#has_counter?Boolean

Determine if a #counter_callback has been set for this application.

Returns:

  • (Boolean)

    true if a counter proc or lambda has been provided.



186
187
188
# File 'lib/ebay_trader/configuration.rb', line 186

def has_counter?
  @counter_callback != nil
end

#has_keys_set?Boolean

Determine if all #dev_id, #app_id and #cert_id have all been set.

Returns:

  • (Boolean)

    true if dev_id, app_id and cert_id have been defined.



129
130
131
# File 'lib/ebay_trader/configuration.rb', line 129

def has_keys_set?
  !(dev_id.nil? || app_id.nil? || cert_id.nil?)
end

#map_auth_token(key, auth_token) ⇒ Object

Map an eBay API auth token to an easy to remember String key. This could be the corresponding eBay username thus making it easier to select the user auth token from a UI list or command line argument.

Parameters:

  • key (String)

    auth_token identifier, typically an eBay username.

  • auth_token (String)

    an eBay API authentication token.



155
156
157
# File 'lib/ebay_trader/configuration.rb', line 155

def map_auth_token(key, auth_token)
  @username_auth_tokens[secure_auth_token_key(key)] = auth_token
end

#production?Boolean

Determine if this app is targeting eBay’s production environment.

Returns:

  • (Boolean)

    true if production mode, otherwise false.



115
116
117
# File 'lib/ebay_trader/configuration.rb', line 115

def production?
  @environment == :production
end

#sandbox?Boolean

Determine if this app is targeting eBay’s sandbox environment.

Returns:

  • (Boolean)

    true if sandbox mode, otherwise false.



122
123
124
# File 'lib/ebay_trader/configuration.rb', line 122

def sandbox?
  !production?
end