Class: EbayTrader::Configuration
- Inherits:
-
Object
- Object
- EbayTrader::Configuration
- 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
-
#app_id ⇒ String
Application keys App ID.
-
#cert_id ⇒ String
Application keys Certificate ID.
-
#counter_callback ⇒ Proc
readonly
An optional Proc or Lambda to record application level API request call volume.
-
#dev_id ⇒ String
The Dev ID application key.
-
#ebay_api_version ⇒ Fixnum
The eBay Trading API version.
-
#ebay_site_id ⇒ Fixnum
This can be overridden by including an ebay_site_id value in the list of arguments to Request#initialize.
-
#http_timeout ⇒ Fixnum
readonly
The number of seconds before the HTTP session times out.
-
#price_type ⇒ Symbol
Set the type of object to be used to represent price values, with the default being
:big_decimal
. -
#ru_name ⇒ String
The eBay RuName for the application.
-
#ssl_verify ⇒ Boolean|String
Specify if the SSL certificate should be verified,
true
by default. -
#uri ⇒ URI
sandbox and production environments.
Instance Method Summary collapse
-
#auth_token ⇒ String
Get the default authentication token, or
nil
if not set. -
#auth_token=(auth_token) ⇒ Object
Optionally set a default authentication token to be used in API requests.
-
#auth_token_for(key) ⇒ String
Get the eBay API auth token matching the given
key
, ornil
if not found. -
#counter=(callback) ⇒ Proc
Provide a callback to track the number of eBay API calls made.
-
#environment=(env) ⇒ Symbol
Set the eBay environment to either :sandbox or :production.
-
#has_counter? ⇒ Boolean
Determine if a #counter_callback has been set for this application.
- #has_keys_set? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#map_auth_token(key, auth_token) ⇒ Object
Map an eBay API auth token to an easy to remember
String
key. -
#production? ⇒ Boolean
Determine if this app is targeting eBay’s production environment.
-
#sandbox? ⇒ Boolean
Determine if this app is targeting eBay’s sandbox environment.
Constructor Details
#initialize ⇒ Configuration
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_id ⇒ String
Returns Application keys App ID.
22 23 24 |
# File 'lib/ebay_trader/configuration.rb', line 22 def app_id @app_id end |
#cert_id ⇒ String
Returns Application keys Certificate ID.
25 26 27 |
# File 'lib/ebay_trader/configuration.rb', line 25 def cert_id @cert_id end |
#counter_callback ⇒ Proc (readonly)
Returns 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_id ⇒ String
The Dev ID application key.
19 20 21 |
# File 'lib/ebay_trader/configuration.rb', line 19 def dev_id @dev_id end |
#ebay_api_version ⇒ Fixnum
Returns the eBay Trading API version.
39 40 41 |
# File 'lib/ebay_trader/configuration.rb', line 39 def ebay_api_version @ebay_api_version end |
#ebay_site_id ⇒ Fixnum
This can be overridden by including an ebay_site_id value in the list of arguments to Request#initialize.
35 36 37 |
# File 'lib/ebay_trader/configuration.rb', line 35 def ebay_site_id @ebay_site_id end |
#http_timeout ⇒ Fixnum (readonly)
Returns 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_type ⇒ Symbol
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!
57 58 59 |
# File 'lib/ebay_trader/configuration.rb', line 57 def price_type @price_type end |
#ru_name ⇒ String
Returns the eBay RuName for the application.
43 44 45 |
# File 'lib/ebay_trader/configuration.rb', line 43 def ru_name @ru_name end |
#ssl_verify ⇒ Boolean|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 |
#uri ⇒ URI
sandbox and production environments.
29 30 31 |
# File 'lib/ebay_trader/configuration.rb', line 29 def uri @uri end |
Instance Method Details
#auth_token ⇒ String
Get the default authentication token, or nil
if not set.
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.
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.
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.
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.
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.
186 187 188 |
# File 'lib/ebay_trader/configuration.rb', line 186 def has_counter? @counter_callback != nil end |
#has_keys_set? ⇒ Boolean
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.
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.
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.
122 123 124 |
# File 'lib/ebay_trader/configuration.rb', line 122 def sandbox? !production? end |