class OandaAPI::Client::TokenClient

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 {developer.oanda.com/rest-live/authentication/ obtaining a personal access token from Oanda}.

@example Example usage

client = OandaAPI::Client::TokenClient.new :practice, ENV.fetch("OANDA_PRACTICE_TOKEN")

# Get information for an account.
# See http://developer.oanda.com/rest-live/accounts/
account = client.accounts.get.first   # => OandaAPI::Resource::Account

# Get a list of open positions.
# See http://developer.oanda.com/rest-live/positions/
positions = client.account(account.id)
                  .positions.get      # => OandaAPI::ResourceCollection

@!attribute [r] auth_token

@return [String] Oanda personal access token.

@!attribute [rw] domain

@return [Symbol] identifies the Oanda subdomain (`:practice` or `:live`)
  accessed by the client.

@!attribute [rw] default_params

@return [Hash] parameters that are included with every API
  request as either query or url_form encoded parameters.

@!attribute [rw] headers

@return [Hash] parameters that are included with every API request
  as HTTP headers.

Attributes

auth_token[R]
default_params[RW]
domain[RW]
headers[RW]

Public Class Methods

new(domain, auth_token, options={}) click to toggle source

@param [Symbol] domain see {#domain} @param [String] auth_token see {#auth_token}

Calls superclass method OandaAPI::Client::new
# File lib/oanda_api/client/token_client.rb, line 45
def initialize(domain, auth_token, options={})
  super options
  @auth_token = auth_token
  @default_params = {}
  self.domain = domain
  @headers = auth
end

Public Instance Methods

auth() click to toggle source

Parameters used for authentication. @return [Hash]

# File lib/oanda_api/client/token_client.rb, line 55
def auth
  { "Authorization" => "Bearer #{auth_token}" }
end
domain=(value) click to toggle source

@private Sets the domain the client can access. (Testing convenience only). @return [void]

# File lib/oanda_api/client/token_client.rb, line 62
def domain=(value)
  fail ArgumentError, "Invalid domain" unless OandaAPI::DOMAINS.include? value
  @domain = value
end