Class: OandaAPI::Configuration
- Inherits:
-
Object
- Object
- OandaAPI::Configuration
- Defined in:
- lib/oanda_api/configuration.rb
Overview
Configures client API settings.
Constant Summary collapse
- DATETIME_FORMAT =
:rfc3339- LABS_API_VERSION =
"labs/v1"- MAX_REQUESTS_PER_SECOND =
15- OPEN_TIMEOUT =
10- READ_TIMEOUT =
10- REST_API_VERSION =
"v1"- USE_COMPRESSION =
false- USE_REQUEST_THROTTLING =
false- CONNECTION_POOL_SIZE =
2
Instance Method Summary collapse
-
#connection_pool_size ⇒ Numeric
Maximum size of the persistent connection pool.
-
#connection_pool_size=(value) ⇒ Numeric
Define the maximum size of the persistent connection pool.
-
#datetime_format ⇒ Symbol
The format in which dates will be returned by the API (
:rfc3339or:unix). -
#datetime_format=(value) ⇒ void
See #datetime_format.
-
#headers ⇒ Hash
Headers that are set on every request as a result of configuration settings.
-
#labs_api_version ⇒ String
The Oanda Labs API version used by the client.
-
#labs_api_version=(value) ⇒ void
See #labs_api_version.
-
#max_requests_per_second ⇒ Numeric
The maximum number of requests per second allowed to be made through the API.
- #max_requests_per_second=(value) ⇒ void
-
#min_request_interval ⇒ Float
The minimum amount of time in seconds that must elapse between consecutive requests to the API.
-
#open_timeout ⇒ Numeric
The number of seconds the client waits for a new HTTP connection to be established before raising a timeout exception.
-
#open_timeout=(value) ⇒ void
See #open_timeout.
-
#read_timeout ⇒ Numeric
The number of seconds the client waits for a response from the API before raising a timeout exception.
-
#read_timeout=(value) ⇒ void
See #read_timeout.
-
#rest_api_version ⇒ String
The Oanda REST API version used by the client.
-
#rest_api_version=(value) ⇒ void
See #rest_api_version.
-
#use_compression ⇒ Boolean
(also: #use_compression?)
Specifies whether the API uses compressed responses.
-
#use_compression=(value) ⇒ void
See #use_compression.
-
#use_request_throttling ⇒ Boolean
(also: #use_request_throttling?)
Throttles the rate of requests made to the API.
- #use_request_throttling=(value) ⇒ void
Instance Method Details
#connection_pool_size ⇒ Numeric
Maximum size of the persistent connection pool.
18 19 20 |
# File 'lib/oanda_api/configuration.rb', line 18 def connection_pool_size @connection_pool_size ||= CONNECTION_POOL_SIZE end |
#connection_pool_size=(value) ⇒ Numeric
Define the maximum size of the persistent connection pool.
24 25 26 27 |
# File 'lib/oanda_api/configuration.rb', line 24 def connection_pool_size=(value) fail ArgumentError, "must be a number > 0" unless value.is_a?(Numeric) && value > 0 @connection_pool_size = value end |
#datetime_format ⇒ Symbol
The format in which dates will be returned by the API (:rfc3339 or :unix).
See the Oanda Development Guide for more details about DateTime formats.
32 33 34 |
# File 'lib/oanda_api/configuration.rb', line 32 def datetime_format @datetime_format ||= DATETIME_FORMAT end |
#datetime_format=(value) ⇒ void
This method returns an undefined value.
See #datetime_format.
39 40 41 42 |
# File 'lib/oanda_api/configuration.rb', line 39 def datetime_format=(value) fail ArgumentError, "Invalid datetime format" unless OandaAPI::DATETIME_FORMATS.include? value @datetime_format = value end |
#headers ⇒ Hash
168 169 170 171 172 173 |
# File 'lib/oanda_api/configuration.rb', line 168 def headers h = {} h["X-Accept-Datetime-Format"] = datetime_format.to_s.upcase h["Accept-Encoding"] = "deflate, gzip" if use_compression? h end |
#labs_api_version ⇒ String
The Oanda Labs API version used by the client.
46 47 48 |
# File 'lib/oanda_api/configuration.rb', line 46 def labs_api_version @labs_api_version ||= LABS_API_VERSION end |
#labs_api_version=(value) ⇒ void
This method returns an undefined value.
See #labs_api_version.
53 54 55 |
# File 'lib/oanda_api/configuration.rb', line 53 def labs_api_version=(value) @labs_api_version = value end |
#max_requests_per_second ⇒ Numeric
The maximum number of requests per second allowed to be made through the
API. Only enforced if #use_request_throttling? is true.
61 62 63 |
# File 'lib/oanda_api/configuration.rb', line 61 def max_requests_per_second @max_requests_per_second ||= MAX_REQUESTS_PER_SECOND end |
#max_requests_per_second=(value) ⇒ void
This method returns an undefined value.
68 69 70 71 72 |
# File 'lib/oanda_api/configuration.rb', line 68 def max_requests_per_second=(value) fail ArgumentError, "must be a number > 0" unless value.is_a?(Numeric) && value > 0 @min_request_interval = nil @max_requests_per_second = value end |
#min_request_interval ⇒ Float
The minimum amount of time in seconds that must elapse between consecutive requests to the API.
Determined by #max_requests_per_second. Only enforced if #use_request_throttling? is true.
77 78 79 |
# File 'lib/oanda_api/configuration.rb', line 77 def min_request_interval @min_request_interval ||= (1.0 / max_requests_per_second) end |
#open_timeout ⇒ Numeric
The number of seconds the client waits for a new HTTP connection to be established before raising a timeout exception.
84 85 86 |
# File 'lib/oanda_api/configuration.rb', line 84 def open_timeout @open_timeout ||= OPEN_TIMEOUT end |
#open_timeout=(value) ⇒ void
This method returns an undefined value.
See #open_timeout.
91 92 93 94 |
# File 'lib/oanda_api/configuration.rb', line 91 def open_timeout=(value) fail ArgumentError, "must be an integer or float" unless value && (value.is_a?(Integer) || value.is_a?(Float)) @open_timeout = value end |
#read_timeout ⇒ Numeric
The number of seconds the client waits for a response from the API before raising a timeout exception.
99 100 101 |
# File 'lib/oanda_api/configuration.rb', line 99 def read_timeout @read_timeout ||= READ_TIMEOUT end |
#read_timeout=(value) ⇒ void
This method returns an undefined value.
See #read_timeout.
106 107 108 109 |
# File 'lib/oanda_api/configuration.rb', line 106 def read_timeout=(value) fail ArgumentError, "must be an integer or float" unless value && (value.is_a?(Integer) || value.is_a?(Float)) @read_timeout = value end |
#rest_api_version ⇒ String
The Oanda REST API version used by the client.
113 114 115 |
# File 'lib/oanda_api/configuration.rb', line 113 def rest_api_version @rest_api_version ||= REST_API_VERSION end |
#rest_api_version=(value) ⇒ void
This method returns an undefined value.
See #rest_api_version.
120 121 122 |
# File 'lib/oanda_api/configuration.rb', line 120 def rest_api_version=(value) @rest_api_version = value end |
#use_compression ⇒ Boolean Also known as: use_compression?
Specifies whether the API uses compressed responses. See the Oanda Development Guide for more information about compression.
128 129 130 131 |
# File 'lib/oanda_api/configuration.rb', line 128 def use_compression @use_compression = USE_COMPRESSION if @use_compression.nil? @use_compression end |
#use_compression=(value) ⇒ void
This method returns an undefined value.
See #use_compression.
138 139 140 |
# File 'lib/oanda_api/configuration.rb', line 138 def use_compression=(value) @use_compression = !!value end |
#use_request_throttling ⇒ Boolean Also known as: use_request_throttling?
Throttles the rate of requests made to the API. See the Oanda Developers Guide for information about connection limits. If enabled, requests will not exceed #max_requests_per_second. If the rate of requests received by the client exceeds this limit, the client delays the rate-exceeding request for the minimum amount of time needed to satisfy the rate limit.
151 152 153 154 |
# File 'lib/oanda_api/configuration.rb', line 151 def use_request_throttling @use_request_throttling = USE_REQUEST_THROTTLING if @use_request_throttling.nil? @use_request_throttling end |
#use_request_throttling=(value) ⇒ void
This method returns an undefined value.
161 162 163 |
# File 'lib/oanda_api/configuration.rb', line 161 def use_request_throttling=(value) @use_request_throttling = !!value end |