Class: OandaAPI::Client::TokenClient
- Inherits:
-
Object
- Object
- OandaAPI::Client::TokenClient
- Includes:
- OandaAPI::Client
- Defined in:
- lib/oanda_api/client/token_client.rb
Overview
Makes requests to the API. Instances access Oanda's practice or live environments. Most API methods require an account API token to perform requests in the associated environment. See the Oanda Development Guide for information about obtaining a personal access token from Oanda.
Constant Summary
Constants included from OandaAPI::Client
Instance Attribute Summary collapse
-
#auth_token ⇒ String
readonly
Oanda personal access token.
-
#default_params ⇒ Hash
Parameters that are included with every API request as either query or url_form encoded parameters.
-
#domain ⇒ Symbol
Identifies the Oanda subdomain (
:practice
or:live
) accessed by the client. -
#headers ⇒ Hash
Parameters that are included with every API request as HTTP headers.
Instance Method Summary collapse
-
#auth ⇒ Hash
Parameters used for authentication.
-
#initialize(domain, auth_token, options = {}) ⇒ TokenClient
constructor
A new instance of TokenClient.
Methods included from OandaAPI::Client
#api_uri, #execute_request, last_request_at, last_request_at=, last_throttled_at, #load_persistent_connection_adapter, map_method_to_http_verb, #proc, throttle_request_rate
Constructor Details
#initialize(domain, auth_token, options = {}) ⇒ TokenClient
Returns a new instance of TokenClient.
45 46 47 48 49 50 51 |
# File 'lib/oanda_api/client/token_client.rb', line 45 def initialize(domain, auth_token, ={}) super @auth_token = auth_token @default_params = {} self.domain = domain @headers = auth end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class OandaAPI::Client
Instance Attribute Details
#auth_token ⇒ String (readonly)
Returns Oanda personal access token.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/oanda_api/client/token_client.rb', line 37 class TokenClient include Client attr_reader :auth_token attr_accessor :domain, :default_params, :headers # @param [Symbol] domain see {#domain} # @param [String] auth_token see {#auth_token} def initialize(domain, auth_token, ={}) super @auth_token = auth_token @default_params = {} self.domain = domain @headers = auth end # Parameters used for authentication. # @return [Hash] def auth { "Authorization" => "Bearer #{auth_token}" } end # @private # Sets the domain the client can access. (Testing convenience only). # @return [void] def domain=(value) fail ArgumentError, "Invalid domain" unless OandaAPI::DOMAINS.include? value @domain = value end end |
#default_params ⇒ Hash
Returns parameters that are included with every API request as either query or url_form encoded parameters.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/oanda_api/client/token_client.rb', line 37 class TokenClient include Client attr_reader :auth_token attr_accessor :domain, :default_params, :headers # @param [Symbol] domain see {#domain} # @param [String] auth_token see {#auth_token} def initialize(domain, auth_token, ={}) super @auth_token = auth_token @default_params = {} self.domain = domain @headers = auth end # Parameters used for authentication. # @return [Hash] def auth { "Authorization" => "Bearer #{auth_token}" } end # @private # Sets the domain the client can access. (Testing convenience only). # @return [void] def domain=(value) fail ArgumentError, "Invalid domain" unless OandaAPI::DOMAINS.include? value @domain = value end end |
#domain ⇒ Symbol
Returns identifies the Oanda subdomain (:practice
or :live
)
accessed by the client.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/oanda_api/client/token_client.rb', line 37 class TokenClient include Client attr_reader :auth_token attr_accessor :domain, :default_params, :headers # @param [Symbol] domain see {#domain} # @param [String] auth_token see {#auth_token} def initialize(domain, auth_token, ={}) super @auth_token = auth_token @default_params = {} self.domain = domain @headers = auth end # Parameters used for authentication. # @return [Hash] def auth { "Authorization" => "Bearer #{auth_token}" } end # @private # Sets the domain the client can access. (Testing convenience only). # @return [void] def domain=(value) fail ArgumentError, "Invalid domain" unless OandaAPI::DOMAINS.include? value @domain = value end end |
#headers ⇒ Hash
Returns parameters that are included with every API request as HTTP headers.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/oanda_api/client/token_client.rb', line 37 class TokenClient include Client attr_reader :auth_token attr_accessor :domain, :default_params, :headers # @param [Symbol] domain see {#domain} # @param [String] auth_token see {#auth_token} def initialize(domain, auth_token, ={}) super @auth_token = auth_token @default_params = {} self.domain = domain @headers = auth end # Parameters used for authentication. # @return [Hash] def auth { "Authorization" => "Bearer #{auth_token}" } end # @private # Sets the domain the client can access. (Testing convenience only). # @return [void] def domain=(value) fail ArgumentError, "Invalid domain" unless OandaAPI::DOMAINS.include? value @domain = value end end |
Instance Method Details
#auth ⇒ Hash
Parameters used for authentication.
55 56 57 |
# File 'lib/oanda_api/client/token_client.rb', line 55 def auth { "Authorization" => "Bearer #{auth_token}" } end |