Class: Nasdaq::API
- Inherits:
-
APICake::Base
- Object
- APICake::Base
- Nasdaq::API
- Defined in:
- lib/nasdaq/api.rb
Overview
Provides access to all the API endpoints
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
-
#default_query ⇒ Object
Returns a hash that will be merged into all query strings before sending the request.
-
#get_csv(path, params = {}) ⇒ Object
Forwards all arguments to #get! and converts the JSON response to CSV If the response contains one or more arrays, the first array will be the CSV output.
-
#initialize(api_key = nil, opts = {}) ⇒ API
constructor
Initializes the API with an optional API Key, and cache settings.
Constructor Details
#initialize(api_key = nil, opts = {}) ⇒ API
Initializes the API with an optional API Key, and cache settings.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/nasdaq/api.rb', line 13 def initialize(api_key = nil, opts = {}) if api_key.is_a?(Hash) && opts.empty? opts = api_key api_key = nil end @api_key = api_key cache.disable unless opts[:use_cache] cache.dir = opts[:cache_dir] if opts[:cache_dir] cache.life = opts[:cache_life] if opts[:cache_life] end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/nasdaq/api.rb', line 8 def api_key @api_key end |
Instance Method Details
#default_query ⇒ Object
Returns a hash that will be merged into all query strings before sending the request. This method is used by API Cake.
26 27 28 |
# File 'lib/nasdaq/api.rb', line 26 def default_query { api_key: api_key } end |
#get_csv(path, params = {}) ⇒ Object
Forwards all arguments to #get! and converts the JSON response to CSV If the response contains one or more arrays, the first array will be the CSV output. Otherwise, the response itself will be used.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/nasdaq/api.rb', line 33 def get_csv(path, params = {}) path = "#{path}.csv" payload = get! path, params if payload.response.code != '200' raise Nasdaq::BadResponse, "#{payload.response.code} #{payload.response.msg}" end payload.response.body end |