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
Instance Method Summary collapse
-
#datetime_format ⇒ Symbol
The format in which dates will be returned by the API (+:rfc3339+ or +: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
#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.
17 18 19 |
# File 'lib/oanda_api/configuration.rb', line 17 def datetime_format @datetime_format ||= DATETIME_FORMAT end |
#datetime_format=(value) ⇒ void
This method returns an undefined value.
See #datetime_format.
24 25 26 27 |
# File 'lib/oanda_api/configuration.rb', line 24 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.
140 141 142 143 144 145 |
# File 'lib/oanda_api/configuration.rb', line 140 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+.
33 34 35 |
# File 'lib/oanda_api/configuration.rb', line 33 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.
40 41 42 43 44 |
# File 'lib/oanda_api/configuration.rb', line 40 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+.
49 50 51 |
# File 'lib/oanda_api/configuration.rb', line 49 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.
56 57 58 |
# File 'lib/oanda_api/configuration.rb', line 56 def open_timeout @open_timeout ||= OPEN_TIMEOUT end |
#open_timeout=(value) ⇒ void
This method returns an undefined value.
See #open_timeout.
63 64 65 66 |
# File 'lib/oanda_api/configuration.rb', line 63 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.
71 72 73 |
# File 'lib/oanda_api/configuration.rb', line 71 def read_timeout @read_timeout ||= READ_TIMEOUT end |
#read_timeout=(value) ⇒ void
This method returns an undefined value.
See #read_timeout.
78 79 80 81 |
# File 'lib/oanda_api/configuration.rb', line 78 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.
85 86 87 |
# File 'lib/oanda_api/configuration.rb', line 85 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.
92 93 94 |
# File 'lib/oanda_api/configuration.rb', line 92 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.
100 101 102 103 |
# File 'lib/oanda_api/configuration.rb', line 100 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.
110 111 112 |
# File 'lib/oanda_api/configuration.rb', line 110 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.
123 124 125 126 |
# File 'lib/oanda_api/configuration.rb', line 123 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.
133 134 135 |
# File 'lib/oanda_api/configuration.rb', line 133 def use_request_throttling=(value) @use_request_throttling = !!value end |