quandl 0.4.4 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +5 -13
  2. data/README.md +133 -318
  3. data/lib/quandl.rb +27 -0
  4. data/lib/quandl/api_config.rb +33 -0
  5. data/lib/quandl/connection.rb +75 -0
  6. data/lib/quandl/errors/quandl_error.rb +56 -0
  7. data/lib/quandl/model/base.rb +31 -0
  8. data/lib/quandl/model/data.rb +32 -0
  9. data/lib/quandl/model/database.rb +62 -0
  10. data/lib/quandl/model/dataset.rb +24 -0
  11. data/lib/quandl/model/list.rb +45 -0
  12. data/lib/quandl/operations/base.rb +17 -0
  13. data/lib/quandl/operations/get.rb +21 -0
  14. data/lib/quandl/operations/list.rb +23 -0
  15. data/lib/quandl/util.rb +35 -0
  16. data/lib/quandl/version.rb +3 -0
  17. metadata +78 -319
  18. data/.gitignore +0 -16
  19. data/.travis.yml +0 -20
  20. data/Gemfile +0 -14
  21. data/Guardfile +0 -8
  22. data/LICENSE +0 -7
  23. data/Rakefile +0 -27
  24. data/UPGRADE.md +0 -262
  25. data/VERSION +0 -1
  26. data/bin/quandl +0 -25
  27. data/config/locales/en.yml +0 -26
  28. data/dist/resources/pkg/Distribution.erb +0 -15
  29. data/dist/resources/pkg/PackageInfo.erb +0 -6
  30. data/dist/resources/pkg/postinstall.erb +0 -47
  31. data/dist/resources/pkg/quandl +0 -25
  32. data/dist/resources/ruby/PackageInfo +0 -3
  33. data/dist/resources/windows/quandl +0 -25
  34. data/lib/commander/command/quandl_ext.rb +0 -21
  35. data/lib/quandl/command.rb +0 -47
  36. data/lib/quandl/command/client.rb +0 -0
  37. data/lib/quandl/command/client_ext.rb +0 -1
  38. data/lib/quandl/command/client_ext/user.rb +0 -11
  39. data/lib/quandl/command/compatibility_check.rb +0 -11
  40. data/lib/quandl/command/config.rb +0 -92
  41. data/lib/quandl/command/presenter.rb +0 -75
  42. data/lib/quandl/command/presenter/helper.rb +0 -19
  43. data/lib/quandl/command/presenter/record.rb +0 -113
  44. data/lib/quandl/command/presenters/dataset_presenter.rb +0 -19
  45. data/lib/quandl/command/presenters/error_presenter.rb +0 -31
  46. data/lib/quandl/command/presenters/nil_class_presenter.rb +0 -10
  47. data/lib/quandl/command/presenters/scraper_presenter.rb +0 -25
  48. data/lib/quandl/command/presenters/superset_presenter.rb +0 -10
  49. data/lib/quandl/command/task.rb +0 -44
  50. data/lib/quandl/command/task/callbacks.rb +0 -28
  51. data/lib/quandl/command/task/clientable.rb +0 -51
  52. data/lib/quandl/command/task/commandable.rb +0 -103
  53. data/lib/quandl/command/task/configurable.rb +0 -80
  54. data/lib/quandl/command/task/dependable.rb +0 -71
  55. data/lib/quandl/command/task/inputable.rb +0 -37
  56. data/lib/quandl/command/task/logging.rb +0 -83
  57. data/lib/quandl/command/task/presentation.rb +0 -36
  58. data/lib/quandl/command/task/reportable.rb +0 -35
  59. data/lib/quandl/command/task/threading.rb +0 -123
  60. data/lib/quandl/command/task/translations.rb +0 -37
  61. data/lib/quandl/command/task/updatable.rb +0 -80
  62. data/lib/quandl/command/task/validations.rb +0 -25
  63. data/lib/quandl/command/tasks.rb +0 -24
  64. data/lib/quandl/command/tasks/delete.rb +0 -34
  65. data/lib/quandl/command/tasks/download.rb +0 -44
  66. data/lib/quandl/command/tasks/info.rb +0 -48
  67. data/lib/quandl/command/tasks/list.rb +0 -31
  68. data/lib/quandl/command/tasks/login.rb +0 -47
  69. data/lib/quandl/command/tasks/replace.rb +0 -58
  70. data/lib/quandl/command/tasks/schedule.rb +0 -211
  71. data/lib/quandl/command/tasks/search.rb +0 -39
  72. data/lib/quandl/command/tasks/superset.rb +0 -66
  73. data/lib/quandl/command/tasks/uninstall.rb +0 -17
  74. data/lib/quandl/command/tasks/update.rb +0 -249
  75. data/lib/quandl/command/tasks/upload.rb +0 -60
  76. data/lib/quandl/command/version.rb +0 -5
  77. data/lib/quandl/lang.rb +0 -45
  78. data/lib/quandl/utility.rb +0 -2
  79. data/lib/quandl/utility/config.rb +0 -43
  80. data/lib/quandl/utility/ruby_version.rb +0 -143
  81. data/quandl.gemspec +0 -43
  82. data/scripts/compile_ruby_pkg.sh +0 -34
  83. data/scripts/install.sh +0 -51
  84. data/scripts/win/quandl_toolbelt.iss +0 -89
  85. data/spec/config/output.rb +0 -21
  86. data/spec/config/quandl.rb +0 -67
  87. data/spec/factories/dataset.rb +0 -10
  88. data/spec/factories/source.rb +0 -10
  89. data/spec/fixtures/scraper-test-file.rb +0 -6
  90. data/spec/lib/quandl/command/delete_spec.rb +0 -45
  91. data/spec/lib/quandl/command/download_spec.rb +0 -49
  92. data/spec/lib/quandl/command/replace_spec.rb +0 -22
  93. data/spec/lib/quandl/command/schedule_spec.rb +0 -45
  94. data/spec/lib/quandl/command/superset_spec.rb +0 -28
  95. data/spec/lib/quandl/command/upload_spec.rb +0 -86
  96. data/spec/lib/quandl/command_spec.rb +0 -38
  97. data/spec/spec_helper.rb +0 -43
  98. data/tasks/toolbelt.rake +0 -138
  99. data/tasks/toolbelt.rb +0 -116
  100. data/tasks/toolbelt/build.rb +0 -2
  101. data/tasks/toolbelt/build/darwin.rb +0 -118
  102. data/tasks/toolbelt/build/ruby.rb +0 -105
  103. data/tasks/toolbelt/build/tarball.rb +0 -79
  104. data/tasks/toolbelt/build/windows.rb +0 -25
  105. data/tasks/toolbelt/push.rb +0 -18
  106. data/tasks/toolbelt/storage.rb +0 -28
  107. data/tasks/toolbelt/tar.rb +0 -21
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MTFmZmJmOTc5NmYwNGZhOGUzMWNhOWQxMzllODE5YWE0NjQ0ZjEwZA==
5
- data.tar.gz: !binary |-
6
- NzI1ZmYyMzlhOTc5NTNmMmJhNGI2MmZmY2U2N2RhNjkwZTg0YjUxYw==
2
+ SHA1:
3
+ metadata.gz: 87e7132b067d332656110bfa7074e2bcaff73679
4
+ data.tar.gz: 18467ef6fffdef18bdcb9c959d98151cee64be87
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZWU2MTU1YTcwMTk2ZmZiYTRhZTlkZTMwOWUzZTRhNjQ5ODk4OTNjMDEyYjZl
10
- MGI5NWVmNWRkOTBmMWUxNmJjYzAzNGE0YjE3Yjk2Zjk2NWZiNmYwYjA1NGJi
11
- NTIwY2JiN2NkZDlhN2Y0YjIyMTI4MDYyNjljOWE0N2FmYzkyNDg=
12
- data.tar.gz: !binary |-
13
- MzZlZTkzNTAzZjEyZDQ5ZTIyOTE2ODU3ZmZlNDAzZDQ1ODU3YTYxZDIyYjRi
14
- YTgzODc2MTgxZjliZWFjN2UxMTAyN2VlY2VlYzlhNjg3OWZiZjMxMDc4NzE2
15
- ZDllYzYwYTNkMjNmNWFjZjBjNjU5NWI1ZjRjZjc4YmQ5NTA2Zjg=
6
+ metadata.gz: cfbb28a5c8ad560bcafffe8d1ab0182bea85af5899a65372eb515f85bf9164443d697a9025b7fe18955d96ee9ca18579039f824554abc42c2f0a67701c3a7e6d
7
+ data.tar.gz: c08e8547dba57bad78708ef595dd4f8c5af33d06edf0c813e234ba402892818204624f7bdf98680a02ae28c09388fb7afea529f1a16fe1b06ad4240c931cf894
data/README.md CHANGED
@@ -1,369 +1,184 @@
1
- [![Code Climate](https://codeclimate.com/github/quandl/quandl_command.png)](https://codeclimate.com/github/quandl/quandl_command)
1
+ # Quandl Ruby Client
2
2
 
3
- # Quandl Toolbelt
3
+ *Copyright Quandl 2015*
4
4
 
5
- ** The Quandl Toolbelt is currently in ALPHA TESTING. You are nevertheless welcome to try it. **
5
+ The official gem for all your data needs! The Quandl client can be used to interact with the latest version of the [Quandl restful API](https://www.quandl.com/tools/api). Currently V3.
6
6
 
7
- The Quandl toolbelt enables you to create and maintain time series data on Quandl.com. The Quandl toolbelt is extremly simple to understand and use. (We use it to maintain the 8 million datasets currently on the site.)
7
+ Note that v1 and v2 of the REST API are deprecated and we will be moving over all functionality to V3. During this transitionary period you can continue to use the old client here: https://rubygems.org/gems/quandl_client
8
8
 
9
- ## Installation
10
-
11
- ### Mac
12
-
13
- **[quandl-toolbelt.pkg](http://s3.amazonaws.com/quandl-command/quandl-toolbelt.pkg)**
14
-
15
-
16
- ### Windows
17
-
18
- **[Quandl Setup.exe]( http://s3.amazonaws.com/quandl-command/Quandl+Setup.exe)**
19
9
 
20
-
21
- ### Gemfile
22
-
23
- In your Gemfile, add:
10
+ ## Installation
24
11
 
25
12
  ```ruby
26
- gem "quandl"
13
+ gem 'quandl'
27
14
  ```
28
15
 
16
+ ## Configuration
29
17
 
18
+ | Option | Explanation | Example |
19
+ |---|---|---|
20
+ | api_key | Your access key | `tEsTkEy123456789` | Used to identify who you are and provide more access. |
21
+ | api_version | The version you wish to access the api with | 2015-04-09 | Can be used to test your code against the latest version without committing to it. |
30
22
 
23
+ ```ruby
24
+ require 'quandl'
25
+ Quandl::ApiConfig.api_key = 'tEsTkEy123456789'
26
+ Quandl::ApiConfig.api_version = '2015-04-09'
27
+ ```
31
28
 
32
- ## Login
33
-
34
- Once the toolbelt is installed, the next step is to login to Quandl:
35
-
36
- $ quandl login
37
- Obtain your token from the API tab on this page: http://www.quandl.com/users/info
38
- Token: ***************
39
- You have successfully authenticated!
40
- username: tammer1
41
- email: tammer@quandl.com
42
-
43
- If you have a Quandl password, you can also use `quandl login --method password`. (You might not have a Quandl password if you log in using Github, Google, Linkedin or Twitter)
44
-
45
-
46
-
47
-
48
- ## Create a Dataset
49
-
50
- Create [data.csv](https://raw2.github.com/quandl/toolbelt_help/master/data.csv) that looks something like this:
51
-
52
- code: AAA
53
- name: My first dataset
54
- description: It only has two rows.
55
- -----
56
- 1999-12-31, 1.23
57
- 2000-01-01, 4.56
58
-
59
- Now send it to Quandl:
60
-
61
- $ quandl upload data.csv
62
-
63
- <!-- You just created a dataset on Quandl.com: [www.quandl.com/<your username>/AAA](#) -->
64
-
65
- You just created a dataset on Quandl.com: `www.quandl.com/<your-username>/AAA`
66
-
67
-
68
-
69
-
70
- ## Update a Dataset
71
-
72
- The new dataset will now exist on Quandl forever. You can send new data and/or update metadata whenever you want. For example, create [data_update.csv](https://raw2.github.com/quandl/toolbelt_help/master/data_udpate.csv):
73
-
74
- code: AAA
75
- description: I am updating this description.
76
- --
77
- 2000-01-02, 99.9
78
-
79
- Now send to Quandl:
80
-
81
- $ quandl upload data_update.csv
82
-
83
- Notice that the dataset now has three rows and a new description:
84
- <!-- [www.quandl.com/<your user name>/AAA](#) -->
85
- `www.quandl.com/<your-username>/AAA`
86
-
87
- <!--
88
- ## An Alternate Update Method
89
- You might also want to edit it more at [www.quandl.com/edit/<your user name>/FOO](#)
90
- -->
91
-
92
-
93
-
94
-
95
- ## Delete a Dataset
96
-
97
- You can delete the dataset:
98
-
99
- $ quandl delete AAA
100
- source_code … created_at: '2014-01-21T15:53:22Z'
101
- Are you sure? (y/n)
102
- y
103
- OK 1241ms AAA
104
-
105
-
106
-
107
-
108
- ## Scrapers and Other Data Producing Programs
109
-
110
- As long as your program outputs Quandl flavored CSV as above, it is ready for use with the Quandl toolbelt. Consider this scraper, written in both Ruby ([scraper1.rb](https://raw2.github.com/quandl/toolbelt_help/master/scraper1.rb)) and Python ([scraper1.py](https://raw2.github.com/quandl/toolbelt_help/master/scraper1.py)):
111
-
112
- # This is script that pulls the history of Facebook (FB) stock price from Google.
113
- # It then prints the data to the screen in CSV format.
114
- # It prepends the CSV with Quandl metadata (code, name, description)
115
- #
116
-
117
-
118
-
119
- If I were to run this script on Jan 31, 2014 I would get this:
120
-
121
- $ ruby scraper.rb
122
- code: FB
123
- name: Facebook Stock Price
124
- ----
125
- Date,Open,High,Low,Close,Volume
126
- 30-Jan-14,62.12,62.50,60.46,61.08,150438699
127
- 29-Jan-14,54.61,54.95,53.19,53.53,98089932
128
- ...
129
-
130
- I can turn the output of this script into a Quandl dataset like this:
131
-
132
- $ ruby scraper.rb | quandl upload
133
-
134
- or
135
-
136
- $ python scraper.py | quandl upload
137
-
138
- If you download the script and run the above command, you would see the result here:
139
- <!-- [www.quandl.com/YOU/FB](#) -->
140
- `www.quandl.com/<your-username>/FB`
141
-
142
- You can pipe the script to `quandl upload` each day to keep the dataset up to date on Quandl.com. Everytime you send data to an existing dataset the new data is merged with what is already there. (Hence the Quandl toolbelt is ideal for daily data harvesting or loading entire datasets or some combination of the two.)
143
-
144
- <!--
145
- Now I send my script to Quandl for regular execution:
146
-
147
- $ quandl schedule scraper.rb daily 17:30
148
-
149
- The scraper will be run daily at 17:30 (in your time zone). Every day when it runs, if the script's output is not valid OR the script reports something to STDERR, then you receive an alert email.
150
-
151
- You now have a dataset on Quandl that refreshes daily!
152
- -->
153
-
154
-
155
-
156
-
157
- ## Scheduling Your Scripts
158
-
159
- This feature is not ready for use yet. When it is ready you will be able to send any script to Quandl. Quandl will then run the script on a schedule and send the output to `quandl upload` for you. You can (optionally) receive emails when the script succeeds or fails.
160
-
161
-
162
-
163
-
164
- ## Many Datasets via One Input Stream
165
-
166
- You can send multiple datasets with a single call to `quandl upload`. [Scraper2.rb](https://raw2.github.com/quandl/toolbelt_help/master/scraper2.rb) ([Scraper2.py](https://raw2.github.com/quandl/toolbelt_help/master/scraper2.py)) produces the most recent closing data for two stocks:
167
-
168
- code: AAPL
169
- --
170
- 2000-01-15,88.32,...
171
-
172
- code: MSFT
173
- --
174
- 2000-01-15,44.20,...
175
-
176
- Then
177
-
178
- $ python scraper.py | quandl upload
179
-
180
- Creates or updates both `quandl.com/<your-username>/AAPL` and `quandl.com/<your-username>/MSFT`
181
-
182
- You can send an infinite number of datasets via one call to `quandl upload`.
183
-
184
-
185
-
186
-
187
- ## Quandl Flavored CSV
188
-
189
- Quandl "flavored" CSV is just just plain vanilla CSV prepended with metadata in [YAML](http://en.wikipedia.org/wiki/YAML) format. Metadata is seperated from data by a single line containing one or more dashes "-".
190
-
191
-
192
- ### Quick Reference
193
-
194
- Here is the entire specification by example for quick reference:
195
-
196
- # This is a comment. Also note blank lines are allowed; they are simply ignored
197
-
198
- code: A01 # only (uppercase) letters, numbers and "_" can be used
199
-
200
- name: My Dataset
201
-
202
- description: "This data is my dataset. Note the use of quotes so
203
- that I can use two lines and also use the reserved character ':'"
204
-
205
- reference_url: www.wsj.com/somewhere # any valid url
206
-
207
- frequency: daily # frequency is inferred if you omit this field
208
-
209
- private: true # true => only you can see the dataset on Quandl
210
-
211
- ----
212
-
213
- Date,Price,Volume # if omitted on new dataset, default headings are created
214
- 2012-01-01,32.23 # the csv data. date can be almost any format you want
215
-
216
-
217
- ### Metadata Specifications
218
-
219
- |Field|Description|Required?|
220
- |-----|------------|--------|
221
- |code|a unique id for the dataset; uppercase letters, numbers and "_" are the only characters allowed.|Required|
222
- |name|a name for the dataset|Strongly Recomended|
223
- |description|a description for the dataset|Recomended|
224
- |reference_url|An external URL where the data can be validated. Most datasets on Quandl cite an external source to maximize credability|Optional|
225
- |frequency|daily, weekly, monthly,quarterly or annual|optional; inferred if omitted|
226
- |private|true or false; default is false|private data is visible to only you|
227
-
228
-
229
-
230
-
231
- ## Example Scrapers
232
-
233
- ### Shibor
234
-
235
- [www.shibor.org](http://www.shibor.org) publishes Shibor rates which Quandl republishes at [www.quandl.com/TAMMER1/SHIBOR](http://www.quandl.com/TAMMER1/SHIBOR)
236
-
237
- This dataset is maintained via [this ruby script](https://github.com/tammer/scrapers/blob/master/shibor.rb) that fetches the 10 most recent days of data from Shibor.org.
238
-
239
- You can run the script to print 10 days of Shibor rates to the screen:
240
-
241
- curl "https://raw.github.com/tammer/scrapers/master/shibor.rb" | ruby
242
-
243
- To maintain this dataset on Quandl, we simply run the following on a daily basis:
244
-
245
- curl "https://raw.github.com/tammer/scrapers/master/shibor.rb" | ruby | quandl upload
246
-
247
- Each day 10 rows are sent to Quandl. Usually 9 of those rows are redundant, but that is harmless since we replace existing data with exactly the same data. Notice how old data is not affected by the updates.
248
-
249
- The backfill for this dataset was manually downloaded and converted into a simple CSV file which we then pushed to the site:
250
-
251
- quandl upload shibor_backfill.csv
252
-
253
-
254
- ### Hsieh Trend Following Factors
255
-
256
- Professor David Hsieh maintains hedge fund trend following risk factors at [faculty.fuqua.duke.edu/~dah7/HFRFData.htm](https://faculty.fuqua.duke.edu/~dah7/HFRFData.htm). They are available on Quandl at [quandl.com/TAMMER1/TFRF](http://www.quandl.com/TAMMER1/TFRF).
257
-
258
- The data is maintained by running [hsieh.rb](https://github.com/tammer/scrapers/blob/master/hsieh.rb) every day. To see the output of the script:
259
-
260
- curl "https://raw.github.com/tammer/scrapers/master/hsieh.rb" | ruby
261
-
262
- To keep the data up to date, we scheduled a daily run of:
263
-
264
- curl "https://raw.github.com/tammer/scrapers/master/hsieh.rb" | ruby | quandl upload
265
-
266
-
267
- ### Copyright Data
268
-
269
- Some data publishers provide data on the condition that you not republish it. When scraping such sites, be sure to set the private flag to be true so that only you can see the data, at which point you should be in compliance, since you are simply storing a single copy on a private cloud based repository; (no different from storing a copy on Google Docs or Dropbox).
270
-
271
- For example, if you happen to need the MSCI Far East Index on Quandl, you can scrape it with a program like [this](https://github.com/tammer/scrapers/blob/master/msci.rb). You then pipe to Quandl as usual, ensuring the private flag is true:
272
-
273
- curl "https://raw.github.com/tammer/scrapers/master/msci.rb" | ruby | quandl upload
274
-
275
- Now you have the data you need on Quandl while remaining compliant with MSCI's terms of use.
276
-
277
-
278
- ### Additional Examples
279
-
280
- |Dataset|Scraper|
281
- |-------|----|
282
- | [Litecoin vs USD](http://quandl.com/TAMMER1/LTCUSD)| [litecoin.rb](https://github.com/tammer/scrapers/blob/master/litecoin.rb)|
283
-
284
-
285
-
286
-
287
- ## Full Reference
288
-
289
- Other features of the Toolbelt including `quandl download`, `quandl info`, `quandl list` and other minor features are documented in the [Quandl Toolbelt Reference](#) page.
290
-
29
+ ## Retrieving Data
291
30
 
31
+ ### Database
292
32
 
33
+ To retrieve a database simply use its code with the get parameter:
293
34
 
294
- ## FAQ
35
+ ```ruby
36
+ require 'quandl'
37
+ Quandl::Database.get('WIKI')
38
+ => ... wiki database ...
39
+ ```
295
40
 
296
- ### How can I use ":" in the name or description field?
41
+ You can also retrieve a list of databases by using:
297
42
 
298
- You should put the text in double quotes:
43
+ ```ruby
44
+ require 'quandl'
45
+ Quandl::Database.all
46
+ => ... results ...
47
+ ```
299
48
 
300
- code: FOO
301
- name: My Dataset
302
- description: "I love colons : : :"
49
+ You can also search for specific databases by passing a query parameter such as:
303
50
 
304
- From Ruby:
51
+ ```ruby
52
+ require 'quandl'
53
+ Quandl::Database.all(params: { query: 'oil' })
54
+ => ... oil results ...
55
+ ```
305
56
 
306
- puts "description: \"I love colons : : :\" "
57
+ ### Dataset
307
58
 
308
- or
59
+ Retrieving dataset data can be done in a similar way to Databases. For example to retrieve a dataset use its full code:
309
60
 
310
- puts ' description: "I love colons : : :" '
61
+ ```ruby
62
+ require 'quandl'
63
+ Quandl::Dataset.get('WIKI/AAPL')
64
+ => ... dataset ...
65
+ ```
311
66
 
312
- From Python:
67
+ You can also retrieve the dataset through the database by using the helper method.
313
68
 
314
- print "description: \"I love colons : : :\""
315
69
 
70
+ ```ruby
71
+ require 'quandl'
72
+ Quandl::Database.get('WIKI').datasets
73
+ => ... datasets results ...
74
+ ```
316
75
 
317
- ### Are the Datasets Publicly Accessible?
76
+ or to search for datasets with `AAPL` in them use:
318
77
 
319
- You decide. By default it is public. use:
78
+ ```ruby
79
+ require 'quandl'
80
+ Quandl::Database.get('WIKI').datasets(params: { query: 'apple' })
81
+ => ... datasets results for apple ...
82
+ ```
320
83
 
321
- private: true
84
+ ### Data
322
85
 
323
- To make the dataset visible only to you.
86
+ Dataset data can be queried through a dataset. For example:
324
87
 
88
+ ```ruby
89
+ require 'quandl'
90
+ Quandl::Dataset.get('WIKI/AAPL').data
91
+ => ... data ...
92
+ ```
325
93
 
326
- ### Can you handle high frequency (intra-day) data?
94
+ you can access the data much like you would other lists. In addition all the data column fields are mapped to their column_names for convenience:
327
95
 
328
- No.
96
+ ```ruby
97
+ require 'quandl'
98
+ Quandl::Dataset.get('WIKI/AAPL').data.first.date
99
+ => ... date ...
100
+ ```
329
101
 
102
+ ## Working with results
330
103
 
331
- ### How do I including Blank or Nils
104
+ ### Instance
332
105
 
333
- This is how you include nil datums:
106
+ All data once retrieved is abstracted into custom classes. You can get a list of the fields in each class by using the `data_fields` method.
334
107
 
335
- Code: NIL
336
- Name: Example Data with Missing Points
337
- Description: This dataset is for example only.
338
- --
339
- Date, High, Low, Mid
340
- 2005, 1, 2, 3
341
- 2004, 5, nil, 4
342
- 2003, ,,9
343
- 2002, 1, 2, N.a.
108
+ ```ruby
109
+ require 'quandl'
110
+ database = Quandl::Database.get('WIKI')
111
+ database.data_fields
112
+ => ["id", "name", "database_code", "description", "datasets_count", "downloads", "premium", "image"]
113
+ ```
344
114
 
345
- This dataset can be seen on Quandl right [here](http://www.quandl.com/TAMMER1/NIL)
115
+ You can then uses these methods in your code. Additionally you can access the data by using the hash equalivalent lookup.
346
116
 
117
+ ```ruby
118
+ require 'quandl'
119
+ database = Quandl::Database.get('WIKI')
120
+ database.database_code
121
+ => 'WIKI'
122
+ database['database_code']
123
+ => 'WIKI'
124
+ ```
347
125
 
348
- ### Your SHIBOR script seems to download the past 10 days' worth of data...
126
+ In some cases name of the fields returned by the API may not be compatible with the ruby language syntax. These will be converted into compatible field names.
349
127
 
350
- ...Assuming that happens daily, then you'll have overlapping data (e.g., the most recent day's data is new, but the prior nine days worth of data should be in the database already). How does Quandl deal with that? What if the underlying data changes - will Quandl update the previous nine days of data? Will it record what the data used to be based on the 'original' dataset?
128
+ ```ruby
129
+ require 'quandl'
130
+ data = Quandl::Dataset.get('WIKI/AAPL').data(params: { limit: 1 }).first
131
+ data.column_names
132
+ => ["Date", "Open", "High", "Low", "Close", "Volume", "Ex-Dividend", "Split Ratio", "Adj. Open", "Adj. High", "Adj. Low", "Adj. Close", "Adj. Volume"]
133
+ data.data_fields
134
+ => ["date", "open", "high", "low", "close", "volume", "ex_dividend", "split_ratio", "adj_open", "adj_high", "adj_low", "adj_close", "adj_volume"]
135
+ ```
351
136
 
352
- Answer: If you upload data for dates where data already exists, the new data over-writes the old data. Thus if you send redundant data, it is harmless. Shibor.rb is written this way for two reason: 1) helpful in case the publisher changes something a few days later. 2) helpful if we miss run for a couple of days for some reason.
137
+ ### List
353
138
 
139
+ Most list queries will return a paginated list of results. You can check whether the resulting list has more data by using the `more_results?` method. Depending on its results you can pass additional params to filter the data:
354
140
 
355
- ### A given municipal bond doesn't trade every day...
141
+ ```ruby
142
+ require 'quandl'
143
+ databases = Quandl::Database.all
144
+ => ... results ...
145
+ databases.more_results?
146
+ => true
147
+ Quandl::Database.all(params: { page: 2 })
148
+ => ... more results ...
149
+ ```
356
150
 
357
- So, if I set up a separate 'id' for each bond, then each day there will be some bonds that get pricing updates and others that don't. Are there any issues with this, or can Quandl handle this kind of 'sparse' data?
151
+ Lists also function as arrays and can be iterated through. Note however that using these features will only work on the current page of data you have locally. You will need to continue to fetch results and iterate again to loop through the full result set.
358
152
 
359
- Answer: Sparse data is not a problem.
153
+ ```ruby
154
+ require 'quandl'
155
+ databases = Quandl::Database.all.each { |d| puts d.database_code }
156
+ => ... print database codes ...
157
+ databases.more_results?
158
+ => true
159
+ Quandl::Database.all(params: { page: 2 }).each { |d| puts d.database_code }
160
+ => ... print more database codes ...
161
+ ```
360
162
 
163
+ Lists also return metadata associated with the request. This can include things like the current page, total results, etc. Each of these fields can be accessed through a hash or convenience method.
361
164
 
362
- ### Why can't I find my dataset using search on Quandl.
165
+ ```ruby
166
+ require 'quandl'
167
+ Quandl::Database.all.current_page
168
+ => 1
169
+ Quandl::Database.all['current_page']
170
+ => 1
171
+ ```
363
172
 
364
- If it is private, it will not appear in search ever. If it is public, it can take up to 1 hour before our index is updated with your new dataset.
173
+ As a convenience method lists can also return their data in CSV form. To do this simply issue the .to_csv method on a list:
365
174
 
175
+ ```ruby
176
+ require 'quandl'
177
+ databases = Quandl::Database.all.to_csv
178
+ => "Id,Name,Database Code,Description,Datasets Count,Downloads,Premium,Image,Bundle Ids,Plan ...
179
+ ```
366
180
 
367
- ### My Question is not answered!
181
+ ## Additional Links
368
182
 
369
- You best <a href='mailto:connect@quandl.com'>email</a> me then. Put "Toolbelt" in the subject and you go right to the top of my inbox.
183
+ * [Quandl](https://www.quandl.com)
184
+ * [Quandl Tools](https://www.quandl.com/tools/api)