quandl 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a80d550c3a42a20073ce20ec17b9565e3dacd26
4
- data.tar.gz: 1377601b7d60dfc17faa807d25add882bc4418e0
3
+ metadata.gz: 8bcec9178eedea09db0f199d66775c08a466e626
4
+ data.tar.gz: 1f83ce52389cdcf290b7227d683e47ea1a5bbfae
5
5
  SHA512:
6
- metadata.gz: 481d5c5b7a5089c23a9abba7c52ffcc48aa626f70f7c221f16ea1e552a367c4bf1fa5e48aea2cc1bf93eeefd1bc961f5ee8a9d1d32321c6a7cd3a6053ae32810
7
- data.tar.gz: d2f63dcf21bfc4be9bf169ea161f32ce32ac30f1cb0c8ad6aeb01ac942ea10bf743f5054cbc0dbbf9fbed390de419bdbba7ad9e02ff695981549515bd8788c5c
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 bulk download of all datasets data of a database:
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 datasets data of a database:
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.
@@ -53,4 +53,7 @@ module Quandl
53
53
 
54
54
  class ForbiddenError < QuandlError
55
55
  end
56
+
57
+ class InvalidDataError < QuandlError
58
+ end
56
59
  end
@@ -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(:download_type, :path_only)
11
+ options.assert_valid_keys(:params)
12
12
 
13
- url = self.class.default_path + '/data'
14
- url = Quandl::ApiConfig.api_base + '/' + url unless options[:path_only]
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
- url = bulk_download_url({ path_only: true }.merge(options))
30
- download_url = Quandl::Connection.request(:get, url) do |response, _request, _result, &_block|
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
- file_or_folder_path = Pathname.new(file_or_folder_path.to_s).join(File.basename(uri.path))
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
 
@@ -1,3 +1,3 @@
1
1
  module Quandl
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
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.1
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-05 00:00:00.000000000 Z
12
+ date: 2015-08-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport