Class: OandaAPI::Client::TokenClient

Inherits:
Object
  • Object
show all
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.

Examples:

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/
 = client.accounts.get.first   # => OandaAPI::Resource::Account

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

Constant Summary

Constants included from OandaAPI::Client

BASE_URI

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:



45
46
47
48
49
50
51
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OandaAPI::Client

Instance Attribute Details

#auth_tokenString (readonly)

Returns Oanda personal access token.

Returns:

  • (String)

    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, options={})
    super options
    @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_paramsHash

Returns parameters that are included with every API request as either query or url_form encoded parameters.

Returns:

  • (Hash)

    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, options={})
    super options
    @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

#domainSymbol

Returns identifies the Oanda subdomain (:practice or :live) accessed by the client.

Returns:

  • (Symbol)

    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, options={})
    super options
    @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

#headersHash

Returns parameters that are included with every API request as HTTP headers.

Returns:

  • (Hash)

    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, options={})
    super options
    @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

#authHash

Parameters used for authentication.

Returns:

  • (Hash)


55
56
57
# File 'lib/oanda_api/client/token_client.rb', line 55

def auth
  { "Authorization" => "Bearer #{auth_token}" }
end