Class: OandaAPI::Client::UsernameClient

Inherits:
Object
  • Object
show all
Includes:
OandaAPI::Client
Defined in:
lib/oanda_api/client/username_client.rb

Overview

Makes requests to the API. Instances access the Oanda sandbox environment. Most client requests require a valid Oanda sandbox account username. See the Oanda Development Guide for information about creating a test account.

Examples:

Example usage (creates a new test account).

client = OandaAPI::Client::UsernameClient.new "_"  # Note: A new test account can be created without having an
                                                   # existing account, which is why we create a client in this
                                                   # example with a bogus username ("_").
 = client..create                # => OandaAPI::Resource::Account
.username                               # => "<username>"

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_throttled_at, map_method_to_http_verb, #proc, throttle_request_rate

Constructor Details

#initialize(username) ⇒ UsernameClient

Returns a new instance of UsernameClient.

Parameters:

  • username (String)

    used for authentication.


38
39
40
41
42
43
44
# File 'lib/oanda_api/client/username_client.rb', line 38

def initialize(username)
  super()
  @domain = :sandbox
  @username = username
  @default_params = auth
  @headers = {}
end

Dynamic Method Handling

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

Instance Attribute Details

#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.


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/oanda_api/client/username_client.rb', line 31

class UsernameClient
  include Client

  attr_reader :domain, :username
  attr_accessor :default_params, :headers

  # @param [String] username used for authentication.
  def initialize(username)
    super()
    @domain = :sandbox
    @username = username
    @default_params = auth
    @headers = {}
  end

  # Parameters used for authentication.
  # @return [Hash]
  def auth
    { "username" => @username }
  end
end

#domainSymbol (readonly)

Returns identifies the Oanda subdomain (:sandbox) which the client accesses.

Returns:

  • (Symbol)

    identifies the Oanda subdomain (:sandbox) which the client accesses.


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/oanda_api/client/username_client.rb', line 31

class UsernameClient
  include Client

  attr_reader :domain, :username
  attr_accessor :default_params, :headers

  # @param [String] username used for authentication.
  def initialize(username)
    super()
    @domain = :sandbox
    @username = username
    @default_params = auth
    @headers = {}
  end

  # Parameters used for authentication.
  # @return [Hash]
  def auth
    { "username" => @username }
  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.


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/oanda_api/client/username_client.rb', line 31

class UsernameClient
  include Client

  attr_reader :domain, :username
  attr_accessor :default_params, :headers

  # @param [String] username used for authentication.
  def initialize(username)
    super()
    @domain = :sandbox
    @username = username
    @default_params = auth
    @headers = {}
  end

  # Parameters used for authentication.
  # @return [Hash]
  def auth
    { "username" => @username }
  end
end

#usernameString (readonly)

Returns the username used for authentication.

Returns:

  • (String)

    the username used for authentication.


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/oanda_api/client/username_client.rb', line 31

class UsernameClient
  include Client

  attr_reader :domain, :username
  attr_accessor :default_params, :headers

  # @param [String] username used for authentication.
  def initialize(username)
    super()
    @domain = :sandbox
    @username = username
    @default_params = auth
    @headers = {}
  end

  # Parameters used for authentication.
  # @return [Hash]
  def auth
    { "username" => @username }
  end
end

Instance Method Details

#authHash

Parameters used for authentication.

Returns:

  • (Hash)

48
49
50
# File 'lib/oanda_api/client/username_client.rb', line 48

def auth
  { "username" => @username }
end