Class: Trader::JsonApiConverter

Inherits:
SyncConverter show all
Defined in:
lib/trade-o-matic/converters/json_api_converter.rb

Instance Attribute Summary collapse

Attributes inherited from SyncConverter

#ttl

Attributes inherited from FixedConverter

#rate

Instance Method Summary collapse

Methods inherited from SyncConverter

#expired?, #rate

Methods inherited from FixedConverter

#apply, #current_rate

Methods inherited from Converter

#apply, #current_rate

Constructor Details

#initialize(_url, _path, _ttl = 30) ⇒ JsonApiConverter

Returns a new instance of JsonApiConverter.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/trade-o-matic/converters/json_api_converter.rb', line 8

def initialize(_url, _path, _ttl=30)
  @url = _url
  @path = _path

  super(_ttl) do
    json_string = RestClient.get _url
    json = JSON.parse json_string
    value = _path.inject(json) { |r, k| r[k] }
    Standard.amount value
  end
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/trade-o-matic/converters/json_api_converter.rb', line 6

def path
  @path
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/trade-o-matic/converters/json_api_converter.rb', line 6

def url
  @url
end