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- 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.
-
#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.
17 18 19 |
# File 'lib/oanda_api/configuration.rb', line 17 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.
23 24 25 26 |
# File 'lib/oanda_api/configuration.rb', line 23 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.
31 32 33 |
# File 'lib/oanda_api/configuration.rb', line 31 def datetime_format @datetime_format ||= DATETIME_FORMAT end |
#datetime_format=(value) ⇒ void
This method returns an undefined value.
See #datetime_format.
38 39 40 41 |
# File 'lib/oanda_api/configuration.rb', line 38 def datetime_format=(value) fail ArgumentError, "Invalid datetime format" unless OandaAPI::DATETIME_FORMATS.include? value @datetime_format = value end |
#headers ⇒ Hash
Returns headers that are set on every request as a result of configuration settings.
154 155 156 157 158 159 |
# File 'lib/oanda_api/configuration.rb', line 154 def headers h = {} h["X-Accept-Datetime-Format"] = datetime_format.to_s.upcase h["Accept-Encoding"] = "deflate, gzip" if use_compression? h 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.
47 48 49 |
# File 'lib/oanda_api/configuration.rb', line 47 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.
54 55 56 57 58 |
# File 'lib/oanda_api/configuration.rb', line 54 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.
63 64 65 |
# File 'lib/oanda_api/configuration.rb', line 63 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.
70 71 72 |
# File 'lib/oanda_api/configuration.rb', line 70 def open_timeout @open_timeout ||= OPEN_TIMEOUT end |
#open_timeout=(value) ⇒ void
This method returns an undefined value.
See #open_timeout.
77 78 79 80 |
# File 'lib/oanda_api/configuration.rb', line 77 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.
85 86 87 |
# File 'lib/oanda_api/configuration.rb', line 85 def read_timeout @read_timeout ||= READ_TIMEOUT end |
#read_timeout=(value) ⇒ void
This method returns an undefined value.
See #read_timeout.
92 93 94 95 |
# File 'lib/oanda_api/configuration.rb', line 92 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.
99 100 101 |
# File 'lib/oanda_api/configuration.rb', line 99 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.
106 107 108 |
# File 'lib/oanda_api/configuration.rb', line 106 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.
114 115 116 117 |
# File 'lib/oanda_api/configuration.rb', line 114 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.
124 125 126 |
# File 'lib/oanda_api/configuration.rb', line 124 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.
137 138 139 140 |
# File 'lib/oanda_api/configuration.rb', line 137 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.
147 148 149 |
# File 'lib/oanda_api/configuration.rb', line 147 def use_request_throttling=(value) @use_request_throttling = !!value end |