Class: EOD::API
- Inherits:
-
APICake::Base
- Object
- APICake::Base
- EOD::API
- Defined in:
- lib/eod/api.rb
Overview
Provides access to all the EOD API endpoints with dynamic methods anc caching.
Instance Attribute Summary collapse
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
Instance Method Summary collapse
- #default_query ⇒ Object
- #get_csv(*args) ⇒ Object
-
#initialize(api_token, use_cache: true, cache_dir: nil, cache_life: nil) ⇒ API
constructor
A new instance of API.
Constructor Details
#initialize(api_token, use_cache: true, cache_dir: nil, cache_life: nil) ⇒ API
Returns a new instance of API.
11 12 13 14 15 16 |
# File 'lib/eod/api.rb', line 11 def initialize(api_token, use_cache: true, cache_dir: nil, cache_life: nil) @api_token = api_token cache.disable unless use_cache cache.dir = cache_dir if cache_dir cache.life = cache_life if cache_life end |
Instance Attribute Details
#api_token ⇒ Object (readonly)
Returns the value of attribute api_token.
9 10 11 |
# File 'lib/eod/api.rb', line 9 def api_token @api_token end |
Instance Method Details
#default_query ⇒ Object
18 19 20 |
# File 'lib/eod/api.rb', line 18 def default_query { api_token: api_token, fmt: :json } end |
#get_csv(*args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/eod/api.rb', line 22 def get_csv(*args) payload = get!(*args) if payload.response.code != '200' raise BadResponse, "#{payload.response.code} #{payload.response.msg}" end data = payload.parsed_response data = csv_node data if data.is_a? Hash header = data.first.keys CSV.generate do |csv| csv << header data.each { |row| csv << row.values } end end |