quandl 1.0.0.rc1 → 1.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +62 -43
- data/lib/quandl/api_config.rb.orig +48 -0
- data/lib/quandl/model/database.rb +1 -1
- data/lib/quandl/model/list.rb.orig +48 -0
- data/lib/quandl/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5eb40c7bbb80beb7aaf78a9147cbcde56542a407
|
4
|
+
data.tar.gz: 1b6c5c98ca1ed08e27f26d4d21492156a64e069e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ab11ee0f247d5f6c342fa032520fdd627ed4df2eb394b03e417df483967a2c7fc80b36360ada3db7a2a3b31ab0cee2bdec174c387f240da597972ca9b10c928
|
7
|
+
data.tar.gz: 437897b2e8b18937d8930ac8468314c8f98d4e6d6edb8f95dabb933b86344fb7a4e50344a5d42a291e409571601220df2149d94ee6f26f23eaed231beabf2b65
|
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
# Quandl Ruby Client
|
1
|
+
# Quandl Ruby Client [![Build Status](https://travis-ci.org/quandl/quandl-ruby.svg?branch=master)](https://travis-ci.org/quandl/quandl-ruby)
|
2
2
|
|
3
|
-
|
3
|
+
The official ruby 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/docs/api).
|
4
4
|
|
5
|
-
|
5
|
+
## Deprecation of old package
|
6
6
|
|
7
|
-
|
7
|
+
With the release of our v3 API we are officially deprecating version 2 of the `quandl_client` ruby gem. We have re-written the package from the ground up and will be moving forward with a 1.x.x package with the name of `quandl` that will rely on version 3 of our restful api. During this transitional period you can continue to use the old package here:
|
8
|
+
|
9
|
+
https://rubygems.org/gems/quandl_client
|
8
10
|
|
9
11
|
|
10
12
|
## Installation
|
@@ -28,77 +30,88 @@ Quandl::ApiConfig.api_version = '2015-04-09'
|
|
28
30
|
|
29
31
|
## Retrieving Data
|
30
32
|
|
31
|
-
###
|
33
|
+
### Dataset
|
32
34
|
|
33
|
-
|
35
|
+
Retrieving dataset data can be done in a similar way to Databases. For example to retrieve a dataset use its full code:
|
34
36
|
|
35
37
|
```ruby
|
36
38
|
require 'quandl'
|
37
|
-
Quandl::
|
38
|
-
=> ...
|
39
|
+
Quandl::Dataset.get('WIKI/AAPL')
|
40
|
+
=> ... dataset ...
|
39
41
|
```
|
40
42
|
|
41
|
-
You can also retrieve a list of
|
43
|
+
You can also retrieve a list of datasets associated to a database by using the Database helper method:
|
44
|
+
|
42
45
|
|
43
46
|
```ruby
|
44
|
-
|
45
|
-
|
46
|
-
=> ... results ...
|
47
|
+
Quandl::Database.get('WIKI').datasets
|
48
|
+
=> ... datasets results ...
|
47
49
|
```
|
48
50
|
|
49
|
-
|
51
|
+
By default, each list query will return page 1 of the first 100 results (Please see the [API Documentation](https://www.quandl.com/docs/api) for more detail)
|
52
|
+
|
53
|
+
### Data
|
54
|
+
|
55
|
+
Dataset data can be queried through a dataset. For example:
|
50
56
|
|
51
57
|
```ruby
|
52
58
|
require 'quandl'
|
53
|
-
Quandl::
|
54
|
-
=> ...
|
59
|
+
Quandl::Dataset.get('WIKI/AAPL').data
|
60
|
+
=> ... data ...
|
55
61
|
```
|
56
62
|
|
57
|
-
|
58
|
-
|
59
|
-
Retrieving dataset data can be done in a similar way to Databases. For example to retrieve a dataset use its full code:
|
63
|
+
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:
|
60
64
|
|
61
65
|
```ruby
|
62
|
-
|
63
|
-
|
64
|
-
=> ... dataset ...
|
66
|
+
Quandl::Dataset.get('WIKI/AAPL').data.first.date
|
67
|
+
=> ... date ...
|
65
68
|
```
|
66
69
|
|
67
|
-
|
70
|
+
### Database
|
68
71
|
|
72
|
+
To retrieve a database simply use its code with the get parameter:
|
69
73
|
|
70
74
|
```ruby
|
71
75
|
require 'quandl'
|
72
|
-
Quandl::Database.get('WIKI')
|
73
|
-
=> ...
|
76
|
+
Quandl::Database.get('WIKI')
|
77
|
+
=> ... wiki database ...
|
74
78
|
```
|
75
79
|
|
76
|
-
|
80
|
+
You can also retrieve a list of databases by using:
|
77
81
|
|
78
82
|
```ruby
|
79
|
-
|
80
|
-
|
81
|
-
=> ... datasets results for apple ...
|
83
|
+
Quandl::Database.all
|
84
|
+
=> ... results ...
|
82
85
|
```
|
83
86
|
|
84
|
-
###
|
87
|
+
### Database Bulk Download
|
85
88
|
|
86
|
-
|
89
|
+
To get the url for bulk download of all datasets data of a database:
|
87
90
|
|
88
91
|
```ruby
|
89
92
|
require 'quandl'
|
90
|
-
Quandl::
|
91
|
-
|
93
|
+
Quandl::ApiConfig.api_key = 'tEsTkEy123456789'
|
94
|
+
Quandl::Database.get('ZEA').bulk_download_url
|
95
|
+
=> "https://www.quandl.com/api/v3/databases/ZEA/data?api_key=tEsTkEy123456789"
|
92
96
|
```
|
93
97
|
|
94
|
-
|
98
|
+
To bulk download all datasets data of a database:
|
95
99
|
|
96
100
|
```ruby
|
97
|
-
|
98
|
-
Quandl::
|
99
|
-
=> ... date ...
|
101
|
+
Quandl::ApiConfig.api_key = 'tEsTkEy123456789'
|
102
|
+
Quandl::Database.get('ZEA').bulk_download_to_file('/path/to/destination/file_or_folder')
|
100
103
|
```
|
101
104
|
|
105
|
+
For bulk download of premium databases, please ensure that a valid `api_key` is set, as authentication is required.
|
106
|
+
|
107
|
+
For both `bulk_download_url` and `bulk_download_to_file`, an optional `download_type` parameter can be passed in:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
Quandl::Database.get('ZEA').bulk_download_to_file('.', download_type: 'partial')
|
111
|
+
```
|
112
|
+
|
113
|
+
If `download_type` is not specified, a `complete` bulk download will be performed. Please see the [API Documentation](https://www.quandl.com/docs/api) for more detail.
|
114
|
+
|
102
115
|
## Working with results
|
103
116
|
|
104
117
|
### Instance
|
@@ -115,7 +128,6 @@ database.data_fields
|
|
115
128
|
You can then uses these methods in your code. Additionally you can access the data by using the hash equalivalent lookup.
|
116
129
|
|
117
130
|
```ruby
|
118
|
-
require 'quandl'
|
119
131
|
database = Quandl::Database.get('WIKI')
|
120
132
|
database.database_code
|
121
133
|
=> 'WIKI'
|
@@ -126,7 +138,6 @@ database['database_code']
|
|
126
138
|
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.
|
127
139
|
|
128
140
|
```ruby
|
129
|
-
require 'quandl'
|
130
141
|
data = Quandl::Dataset.get('WIKI/AAPL').data(params: { limit: 1 }).first
|
131
142
|
data.column_names
|
132
143
|
=> ["Date", "Open", "High", "Low", "Close", "Volume", "Ex-Dividend", "Split Ratio", "Adj. Open", "Adj. High", "Adj. Low", "Adj. Close", "Adj. Volume"]
|
@@ -136,7 +147,7 @@ data.data_fields
|
|
136
147
|
|
137
148
|
### List
|
138
149
|
|
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:
|
150
|
+
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. By default, each list query will return page 1 of the first 100 results (Please see the [API Documentation](https://www.quandl.com/docs/api) for more detail). Depending on its results you can pass additional params to filter the data:
|
140
151
|
|
141
152
|
```ruby
|
142
153
|
require 'quandl'
|
@@ -151,8 +162,8 @@ Quandl::Database.all(params: { page: 2 })
|
|
151
162
|
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.
|
152
163
|
|
153
164
|
```ruby
|
154
|
-
|
155
|
-
databases
|
165
|
+
databases = Quandl::Database.all
|
166
|
+
databases.each { |d| puts d.database_code }
|
156
167
|
=> ... print database codes ...
|
157
168
|
databases.more_results?
|
158
169
|
=> true
|
@@ -163,7 +174,6 @@ Quandl::Database.all(params: { page: 2 }).each { |d| puts d.database_code }
|
|
163
174
|
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.
|
164
175
|
|
165
176
|
```ruby
|
166
|
-
require 'quandl'
|
167
177
|
Quandl::Database.all.current_page
|
168
178
|
=> 1
|
169
179
|
Quandl::Database.all['current_page']
|
@@ -173,12 +183,21 @@ Quandl::Database.all['current_page']
|
|
173
183
|
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:
|
174
184
|
|
175
185
|
```ruby
|
176
|
-
require 'quandl'
|
177
186
|
databases = Quandl::Database.all.to_csv
|
178
187
|
=> "Id,Name,Database Code,Description,Datasets Count,Downloads,Premium,Image,Bundle Ids,Plan ...
|
179
188
|
```
|
180
189
|
|
190
|
+
## Questions/Comments
|
191
|
+
|
192
|
+
For any questions, comments or inquires about this package please open a ticket on the github repo or email the development team at <dev@quandl.com>. For any questions about data provided by the API please email connect@quandl.com
|
193
|
+
|
181
194
|
## Additional Links
|
182
195
|
|
183
196
|
* [Quandl](https://www.quandl.com)
|
184
197
|
* [Quandl Tools](https://www.quandl.com/tools/api)
|
198
|
+
* [API Docs](https://www.quandl.com/docs/api)
|
199
|
+
|
200
|
+
## License
|
201
|
+
|
202
|
+
[MIT License](http://opensource.org/licenses/MIT)
|
203
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Quandl
|
2
|
+
class ApiConfig
|
3
|
+
API_KEY_THREAD_KEY = 'quandl_api_key'
|
4
|
+
API_BASE_THREAD_KEY = 'quandl_api_base'
|
5
|
+
API_VERSION_THREAD_KEY = 'quandl_api_version_key'
|
6
|
+
<<<<<<< HEAD
|
7
|
+
=======
|
8
|
+
DEFAULT_PER_PAGE_THREAD_KEY = 'default_per_page'
|
9
|
+
>>>>>>> abd0bfd... Implement Database and Dataset get and list
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def api_key=(api_key)
|
13
|
+
Thread.current[API_KEY_THREAD_KEY] = api_key
|
14
|
+
end
|
15
|
+
|
16
|
+
def api_key
|
17
|
+
Thread.current[API_KEY_THREAD_KEY]
|
18
|
+
end
|
19
|
+
|
20
|
+
def api_base=(api_base)
|
21
|
+
Thread.current[API_BASE_THREAD_KEY] = api_base
|
22
|
+
end
|
23
|
+
|
24
|
+
def api_base
|
25
|
+
Thread.current[API_BASE_THREAD_KEY] || 'https://www.quandl.com/api/v3'
|
26
|
+
end
|
27
|
+
|
28
|
+
def api_version=(api_version)
|
29
|
+
Thread.current[API_VERSION_THREAD_KEY] = api_version
|
30
|
+
end
|
31
|
+
|
32
|
+
def api_version
|
33
|
+
Thread.current[API_VERSION_THREAD_KEY]
|
34
|
+
end
|
35
|
+
<<<<<<< HEAD
|
36
|
+
=======
|
37
|
+
|
38
|
+
def default_per_page=(per_page)
|
39
|
+
Thread.current[DEFAULT_PER_PAGE_THREAD_KEY] = per_page
|
40
|
+
end
|
41
|
+
|
42
|
+
def default_per_page
|
43
|
+
Thread.current[DEFAULT_PER_PAGE_THREAD_KEY] || 25
|
44
|
+
end
|
45
|
+
>>>>>>> abd0bfd... Implement Database and Dataset get and list
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -16,7 +16,7 @@ module Quandl
|
|
16
16
|
|
17
17
|
params = {}
|
18
18
|
params['download_type'] = options[:download_type] if options[:download_type]
|
19
|
-
params['
|
19
|
+
params['api_key'] = Quandl::ApiConfig.api_key if Quandl::ApiConfig.api_key
|
20
20
|
|
21
21
|
url += '?' + params.to_query if params.any?
|
22
22
|
url
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Quandl
|
2
|
+
class List
|
3
|
+
attr_reader :meta
|
4
|
+
attr_reader :values
|
5
|
+
|
6
|
+
def initialize(klass, values, meta)
|
7
|
+
@klass = klass
|
8
|
+
@values = values.map { |v| klass.new(v, meta: meta) }
|
9
|
+
@meta = meta
|
10
|
+
end
|
11
|
+
|
12
|
+
def more_results?
|
13
|
+
<<<<<<< HEAD
|
14
|
+
=======
|
15
|
+
fail(QuandlError, "#{@klass} does not support pagination yet") if !@meta.key?('total_pages') && !@meta.key?('current_page')
|
16
|
+
>>>>>>> b480b01... pre-release version of quandl gem
|
17
|
+
@meta['total_pages'] > @meta['current_page']
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_a
|
21
|
+
@values.map(&:to_a)
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_csv
|
25
|
+
fail(QuandlError, 'No values to export') if @values.empty?
|
26
|
+
|
27
|
+
CSV.generate do |csv|
|
28
|
+
csv << @values.first.column_names
|
29
|
+
@values.each do |row|
|
30
|
+
csv << row.to_a
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def inspect
|
36
|
+
{ meta: @meta, values: @values }.to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def method_missing(method_name, *args, &block)
|
42
|
+
return @meta[method_name.to_s] if @meta.key?(method_name.to_s)
|
43
|
+
return @meta[*args] if method_name.to_s == '[]' && @meta.key?(args[0].to_s)
|
44
|
+
return @values.method(method_name).call(*args, &block) if @values.respond_to?(method_name)
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/quandl/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clement Leung
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-07-
|
12
|
+
date: 2015-07-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -162,6 +162,7 @@ files:
|
|
162
162
|
- README.md
|
163
163
|
- lib/quandl.rb
|
164
164
|
- lib/quandl/api_config.rb
|
165
|
+
- lib/quandl/api_config.rb.orig
|
165
166
|
- lib/quandl/connection.rb
|
166
167
|
- lib/quandl/errors/quandl_error.rb
|
167
168
|
- lib/quandl/model/base.rb
|
@@ -169,6 +170,7 @@ files:
|
|
169
170
|
- lib/quandl/model/database.rb
|
170
171
|
- lib/quandl/model/dataset.rb
|
171
172
|
- lib/quandl/model/list.rb
|
173
|
+
- lib/quandl/model/list.rb.orig
|
172
174
|
- lib/quandl/operations/base.rb
|
173
175
|
- lib/quandl/operations/get.rb
|
174
176
|
- lib/quandl/operations/list.rb
|