quandl 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -5
- data/lib/quandl/errors/quandl_error.rb +3 -0
- data/lib/quandl/model/data.rb +5 -0
- data/lib/quandl/model/database.rb +16 -8
- data/lib/quandl/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bcec9178eedea09db0f199d66775c08a466e626
|
4
|
+
data.tar.gz: 1f83ce52389cdcf290b7227d683e47ea1a5bbfae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba3f3b3dc36b8c5608a7d5f274b3b571224966748076b0a3ec8a40937ee7e1bb4387143dc25ecad070ad96669f8d925c5c97c28e03380ba0374078da13a6208e
|
7
|
+
data.tar.gz: 9b8e317737e4b51d3547a9cc6fdc636f7dc207fa6c6c873742b5ce28720af8c65d0f194662d794b81dee75c33f8349b84ea1a4ab70069def46e430c09b2f7dca
|
data/README.md
CHANGED
@@ -84,9 +84,9 @@ Quandl::Database.all
|
|
84
84
|
=> ... results ...
|
85
85
|
```
|
86
86
|
|
87
|
-
### Database Bulk Download
|
87
|
+
### Download Entire Database (Bulk Download)
|
88
88
|
|
89
|
-
To get the url for
|
89
|
+
To get the url for downloading all dataset data of a database:
|
90
90
|
|
91
91
|
```ruby
|
92
92
|
require 'quandl'
|
@@ -95,19 +95,21 @@ Quandl::Database.get('ZEA').bulk_download_url
|
|
95
95
|
=> "https://www.quandl.com/api/v3/databases/ZEA/data?api_key=tEsTkEy123456789"
|
96
96
|
```
|
97
97
|
|
98
|
-
To bulk download all
|
98
|
+
To bulk download all dataset data of a database:
|
99
99
|
|
100
100
|
```ruby
|
101
101
|
Quandl::ApiConfig.api_key = 'tEsTkEy123456789'
|
102
102
|
Quandl::Database.get('ZEA').bulk_download_to_file('/path/to/destination/file_or_folder')
|
103
103
|
```
|
104
104
|
|
105
|
+
The file or folder path can either be specified as a string or as a [File](http://ruby-doc.org/core-2.2.0/File.html).
|
106
|
+
|
105
107
|
For bulk download of premium databases, please ensure that a valid `api_key` is set, as authentication is required.
|
106
108
|
|
107
|
-
For both `bulk_download_url` and `bulk_download_to_file`, an optional `download_type` parameter can be passed in:
|
109
|
+
For both `bulk_download_url` and `bulk_download_to_file`, an optional `download_type` query parameter can be passed in:
|
108
110
|
|
109
111
|
```ruby
|
110
|
-
Quandl::Database.get('ZEA').bulk_download_to_file('.', download_type: 'partial')
|
112
|
+
Quandl::Database.get('ZEA').bulk_download_to_file('.', params: {download_type: 'partial'})
|
111
113
|
```
|
112
114
|
|
113
115
|
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.
|
data/lib/quandl/model/data.rb
CHANGED
@@ -3,6 +3,11 @@ module Quandl
|
|
3
3
|
include Quandl::Operations::List
|
4
4
|
|
5
5
|
def self.create_list_from_response(_response, data)
|
6
|
+
if data['dataset_data']['data'].length > 0 &&
|
7
|
+
data['dataset_data']['column_names'].length != data['dataset_data']['data'].first.length
|
8
|
+
fail InvalidDataError.new('number of column names does not match number of data points in a row!',
|
9
|
+
nil, nil, data)
|
10
|
+
end
|
6
11
|
values = data['dataset_data'].delete('data')
|
7
12
|
metadata = data['dataset_data']
|
8
13
|
Quandl::List.new(self, values, metadata)
|
@@ -8,26 +8,32 @@ module Quandl
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def bulk_download_url(options = {})
|
11
|
-
options.assert_valid_keys(:
|
11
|
+
options.assert_valid_keys(:params)
|
12
12
|
|
13
|
-
url =
|
14
|
-
url = Quandl::ApiConfig.api_base + '/' + url
|
13
|
+
url = bulk_download_path
|
14
|
+
url = Quandl::ApiConfig.api_base + '/' + url
|
15
15
|
url = Quandl::Util.constructed_path(url, id: database_code)
|
16
16
|
|
17
|
-
params = {}
|
18
|
-
params['download_type'] = options[:download_type] if options[:download_type]
|
17
|
+
params = options[:params] || {}
|
19
18
|
params['api_key'] = Quandl::ApiConfig.api_key if Quandl::ApiConfig.api_key
|
19
|
+
params['api_version'] = Quandl::ApiConfig.api_version if Quandl::ApiConfig.api_version
|
20
20
|
|
21
21
|
url += '?' + params.to_query if params.any?
|
22
22
|
url
|
23
23
|
end
|
24
24
|
|
25
|
+
def bulk_download_path
|
26
|
+
path = self.class.default_path + '/data'
|
27
|
+
path = Quandl::Util.constructed_path(path, id: database_code)
|
28
|
+
path
|
29
|
+
end
|
30
|
+
|
25
31
|
def bulk_download_to_file(file_or_folder_path, options = {})
|
26
32
|
fail(QuandlError, 'You must specific a file handle or folder to write to.') if file_or_folder_path.blank?
|
27
33
|
|
28
34
|
# Retrieve the location of the bulk download url
|
29
|
-
|
30
|
-
download_url = Quandl::Connection.request(:get,
|
35
|
+
path = bulk_download_path
|
36
|
+
download_url = Quandl::Connection.request(:get, path, options) do |response, _request, _result, &_block|
|
31
37
|
if response.code == 302
|
32
38
|
response.headers[:location]
|
33
39
|
else
|
@@ -40,7 +46,9 @@ module Quandl
|
|
40
46
|
# Check that we can write to the directory
|
41
47
|
file = file_or_folder_path
|
42
48
|
unless file_or_folder_path.is_a?(File)
|
43
|
-
|
49
|
+
if File.directory?(file_or_folder_path)
|
50
|
+
file_or_folder_path = Pathname.new(file_or_folder_path.to_s).join(File.basename(uri.path))
|
51
|
+
end
|
44
52
|
file = File.open(file_or_folder_path, 'wb')
|
45
53
|
end
|
46
54
|
|
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.
|
4
|
+
version: 1.0.2
|
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-08-
|
12
|
+
date: 2015-08-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|