class Quata::API

Provides access to all the Quandl API endpoints

Attributes

api_key[R]

Public Class Methods

new(api_key=nil, opts={}) click to toggle source

Initializes the API with an optional API Key, and cache settings.

# File lib/quata/api.rb, line 14
def initialize(api_key=nil, opts={})
  opts, api_key = api_key, nil if api_key.is_a?(Hash) && opts.empty?
  @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

Public Instance Methods

default_query() click to toggle source

Returns a hash that will be merged into all query strings before sending the request to Quandl. This method is used by API Cake.

# File lib/quata/api.rb, line 24
def default_query
  { api_key: api_key } 
end
get_csv(path, params={}) click to toggle source

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.

# File lib/quata/api.rb, line 31
def get_csv(path, params={})
  path = "#{path}.csv"
  payload = get! path, params

  if payload.response.code != '200'
    raise Quata::BadResponse, "#{payload.response.code} #{payload.response.msg}"
  end

  payload.response.body
end