Class: OandaAPI::ResourceBase

Inherits:
Object
  • Object
show all
Defined in:
lib/oanda_api/resource_base.rb

Overview

Base class for all Resources.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ ResourceBase

Returns a new instance of ResourceBase.

Parameters:

  • attributes (Hash) (defaults to: {})

    collection of resource attributes. See the Oanda Developer Guide for documentation about resource attributes.



17
18
19
20
# File 'lib/oanda_api/resource_base.rb', line 17

def initialize(attributes = {})
  initialize_attributes Utils.rubyize_keys(attributes.dup)
  @location = attributes.location if attributes.respond_to? :location
end

Instance Attribute Details

#locationString

Returns the +location+ header if one is returned in an API response.

Examples:

Using the +location+ attribute

client = OandaAPI::Client::TokenClient.new :practice, token
all_transactions = client.(123).alltransactions.get
all_transactions.location # => https://fxtrade.oanda.com/transactionhistory/d3aed6823c.json.zip

Returns:

  • (String)

    the +location+ header if one is returned in an API response.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/oanda_api/resource_base.rb', line 11

class ResourceBase
  attr_accessor :location

  # @param [Hash] attributes collection of resource attributes. See the
  #   {http://developer.oanda.com/rest-live/development-guide/ Oanda Developer Guide}
  #   for documentation about resource attributes.
  def initialize(attributes = {})
    initialize_attributes Utils.rubyize_keys(attributes.dup)
    @location = attributes.location if attributes.respond_to? :location
  end

  private

  # @private
  # Initializes attributes.
  #
  # @param [Hash] attributes collection of resource attributes.
  # @return [void]
  def initialize_attributes(attributes)
    attributes.each do |key, value|
      send("#{key}=", value) if respond_to? key
    end
  end
end