# Quandl::Client ## Purpose The purpose of this gem is to interact with the [quandl api](http://www.quandl.com/help/api) ## Installation ```ruby gem 'quandl_client' ``` ## Configuration ```ruby require 'quandl/client' Quandl::Client.use 'http://localhost:3000/api/' Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] ``` ## Usage ### Quandl::Client::Dataset #### Search scope :rows, :exclude_data, :exclude_headers, :trim_start, :trim_end, :transform, :collapse ```ruby datasets = Quandl::Client::Dataset.query('cobalt').source_code('ofdp').all => [#, ...] ``` #### Show attributes :data, :source_code, :code, :name, :urlize_name, :description, :updated_at, :frequency, :from_date, :to_date, :column_names, :private, :type ```ruby d = Quandl::Client::Dataset.find('OFDP/COBALT_51') d.full_code d.data d = Quandl::Client::Dataset.collapse('weekly').trim_start("2012-03-31").trim_end("2013-06-30").find('OFDP/COBALT_51') d.data d = Quandl::Client::Dataset.exclude_data('true').find('OFDP/COBALT_51') d.data ``` #### Create ```ruby attributes = { code: "TEST_#{Time.now.to_i}", source_code: 'OFDP', name: "Test Upload #{Time.now.to_i}", frequency: 'daily', locations: [ { type: 'http', url: 'http://test.com', post_data: '[magic]', cookie_url: 'http://cookies.com' } ] } d = Dataset.create( attributes ) ``` #### Update ```ruby d = Dataset.find( d.full_code ) d.name = 'New Name' d.data = Quandl::Fabricate::Data.rand.to_csv d.save d = Dataset.collapse(:weekly).find( d.full_code ) d.data => [[...],...] ``` #### Delete ```ruby Dataset.destroy_existing('SOME_SOURCE/SOME_CODE') Dataset.destroy_existing(52352) Dataset.find('SOME_SOURCE/SOME_CODE') => nil ``` #### Delete Data ```ruby d = Dataset.find('SOME_SOURCE/SOME_CODE') d.delete_data d.data => nil d.delete_rows( '1998-02-01','1998-03-03' ) d.data => # given rows are deleted ``` #### Error Handling ```ruby d = Dataset.create(code: 'TEST', source_code: 'OFDP', locations: [{ type: 'http', url: 'test.com' }] ) d.error_messages => {:name=>["can't be blank"]} d = Dataset.create(name: 'asdfs', code: 'TEST', source_code: 'OFDP', locations: [{ type: 'http', url: 'test.com' }] ) d.error_messages => {"code"=>["has already been taken"], "frequency"=>["is not included in the list"]} ``` ### Quandl::Client::Source #### Search ```ruby sources = Quandl::Client::Source.query('can').all => [#...] ``` #### Show ```ruby s = Quandl::Client::Source.find('STATSCAN5') ``` #### Create ```ruby s = Source.create( code: 'test' ) s.valid? s.error_messages => {:code=>["is invalid"], :host=>["can't be blank"], :name=>["can't be blank"]} s = Source.create(code: %Q{TEST_#{Time.now.to_i}}, name: 'asdf', host: "http://asdf#{Time.now}.com" ) s.saved? => true ``` #### Update ```ruby s = Source.find(s.code) s.name = "Updated Name #{Time.now.to_i}" s.code = "DATA_#{Time.now.to_i}" s.save ``` #### Delete ```ruby Source.destroy_existing('SOMESOURCE') Source.destroy_existing(52352) ``` ### Quandl::Client::Sheet #### Search ```ruby sheets = Quandl::Client::Sheet.query('canada').all => [[# true ```