Class: OandaApiV20::Client
- Inherits:
-
Object
- Object
- OandaApiV20::Client
- Includes:
- HTTParty
- Defined in:
- lib/oanda_api_v20/client.rb
Constant Summary collapse
- BASE_URI =
{ live: 'https://api-fxtrade.oanda.com/v3', practice: 'https://api-fxpractice.oanda.com/v3' }
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #method_missing(name, *args, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/oanda_api_v20/client.rb', line 13 def initialize( = {}) .each do |key, value| self.send("#{key}=", value) if self.respond_to?("#{key}=") end @base_uri = [:practice] == true ? BASE_URI[:practice] : BASE_URI[:live] @headers = {} @headers['Authorization'] = "Bearer #{access_token}" @headers['X-Accept-Datetime-Format'] = 'RFC3339' @headers['Content-Type'] = 'application/json' end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/oanda_api_v20/client.rb', line 26 def method_missing(name, *args, &block) case name when :show, :create, :update, :cancel, :close set_http_verb(name, last_action) api = Api.new(api_attributes) if api.respond_to?(last_action) response = last_arguments.nil? || last_arguments.empty? ? api.send(last_action, &block) : api.send(last_action, *last_arguments, &block) api_result = JSON.parse(response.body) set_last_transaction_id(api_result) end api_result when *api_methods set_last_action_and_arguments(name, args) set_account_id(args.first) if name == :account self end end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
10 11 12 |
# File 'lib/oanda_api_v20/client.rb', line 10 def access_token @access_token end |
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
11 12 13 |
# File 'lib/oanda_api_v20/client.rb', line 11 def base_uri @base_uri end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
11 12 13 |
# File 'lib/oanda_api_v20/client.rb', line 11 def headers @headers end |