quandl 1.0.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3a80d550c3a42a20073ce20ec17b9565e3dacd26
4
- data.tar.gz: 1377601b7d60dfc17faa807d25add882bc4418e0
2
+ SHA256:
3
+ metadata.gz: 8481bd2e2b3c7f1cf717957487dd202dd480499ca654a158b3f2c05d6d79a849
4
+ data.tar.gz: dae3cfe235ca3195fd537bca6a1ac9a4a74f91d8f8110e85cd9a04f145a3d7fe
5
5
  SHA512:
6
- metadata.gz: 481d5c5b7a5089c23a9abba7c52ffcc48aa626f70f7c221f16ea1e552a367c4bf1fa5e48aea2cc1bf93eeefd1bc961f5ee8a9d1d32321c6a7cd3a6053ae32810
7
- data.tar.gz: d2f63dcf21bfc4be9bf169ea161f32ce32ac30f1cb0c8ad6aeb01ac942ea10bf743f5054cbc0dbbf9fbed390de419bdbba7ad9e02ff695981549515bd8788c5c
6
+ metadata.gz: 16e109f9880cabb3fd880e4a5dc1b68c9bb7bd179137b67de8812cf6ded8c1a73dc89b4e262c877840d6ce43b89802f8ed31a680fc1287a33f423cd7d6d32acd
7
+ data.tar.gz: 7b67c735c72a6170a0aa00c328cd21af6743c8ce1f40f4dc072b71a7fc256fbf842099d5f18b8b4b01e9198d37446c2442bc920fde931a32c2da75146908c627
data/README.md CHANGED
@@ -2,13 +2,6 @@
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
- ## Deprecation of old package
6
-
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
10
-
11
-
12
5
  ## Installation
13
6
 
14
7
  ```ruby
@@ -32,7 +25,7 @@ Quandl::ApiConfig.api_version = '2015-04-09'
32
25
 
33
26
  ### Dataset
34
27
 
35
- Retrieving dataset data can be done in a similar way to Databases. For example to retrieve a dataset use its full code:
28
+ Retrieving dataset data can be done in a similar way to Databases. For example to retrieve a dataset use its full code:
36
29
 
37
30
  ```ruby
38
31
  require 'quandl'
@@ -60,7 +53,7 @@ Quandl::Dataset.get('WIKI/AAPL').data
60
53
  => ... data ...
61
54
  ```
62
55
 
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:
56
+ 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:
64
57
 
65
58
  ```ruby
66
59
  Quandl::Dataset.get('WIKI/AAPL').data.first.date
@@ -84,9 +77,9 @@ Quandl::Database.all
84
77
  => ... results ...
85
78
  ```
86
79
 
87
- ### Database Bulk Download
80
+ ### Download Entire Database (Bulk Download)
88
81
 
89
- To get the url for bulk download of all datasets data of a database:
82
+ To get the url for downloading all dataset data of a database:
90
83
 
91
84
  ```ruby
92
85
  require 'quandl'
@@ -95,19 +88,21 @@ Quandl::Database.get('ZEA').bulk_download_url
95
88
  => "https://www.quandl.com/api/v3/databases/ZEA/data?api_key=tEsTkEy123456789"
96
89
  ```
97
90
 
98
- To bulk download all datasets data of a database:
91
+ To bulk download all dataset data of a database:
99
92
 
100
93
  ```ruby
101
94
  Quandl::ApiConfig.api_key = 'tEsTkEy123456789'
102
95
  Quandl::Database.get('ZEA').bulk_download_to_file('/path/to/destination/file_or_folder')
103
96
  ```
104
97
 
98
+ 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).
99
+
105
100
  For bulk download of premium databases, please ensure that a valid `api_key` is set, as authentication is required.
106
101
 
107
- For both `bulk_download_url` and `bulk_download_to_file`, an optional `download_type` parameter can be passed in:
102
+ For both `bulk_download_url` and `bulk_download_to_file`, an optional `download_type` query parameter can be passed in:
108
103
 
109
104
  ```ruby
110
- Quandl::Database.get('ZEA').bulk_download_to_file('.', download_type: 'partial')
105
+ Quandl::Database.get('ZEA').bulk_download_to_file('.', params: {download_type: 'partial'})
111
106
  ```
112
107
 
113
108
  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.
@@ -125,7 +120,7 @@ database.data_fields
125
120
  => ["id", "name", "database_code", "description", "datasets_count", "downloads", "premium", "image"]
126
121
  ```
127
122
 
128
- You can then uses these methods in your code. Additionally you can access the data by using the hash equalivalent lookup.
123
+ You can then uses these methods in your code. Additionally you can access the data by using the hash equivalent lookup.
129
124
 
130
125
  ```ruby
131
126
  database = Quandl::Database.get('WIKI')
@@ -187,10 +182,6 @@ databases = Quandl::Database.all.to_csv
187
182
  => "Id,Name,Database Code,Description,Datasets Count,Downloads,Premium,Image,Bundle Ids,Plan ...
188
183
  ```
189
184
 
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
-
194
185
  ## Additional Links
195
186
 
196
187
  * [Quandl](https://www.quandl.com)
@@ -200,4 +191,3 @@ For any questions, comments or inquires about this package please open a ticket
200
191
  ## License
201
192
 
202
193
  [MIT License](http://opensource.org/licenses/MIT)
203
-
@@ -1,32 +1,47 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Quandl
2
4
  class ApiConfig
3
5
  API_KEY_THREAD_KEY = 'quandl_api_key'
4
6
  API_BASE_THREAD_KEY = 'quandl_api_base'
5
7
  API_VERSION_THREAD_KEY = 'quandl_api_version_key'
6
8
 
9
+ @api_key = nil
10
+ @api_base = nil
11
+ @api_version = nil
12
+
7
13
  class << self
8
14
  def api_key=(api_key)
15
+ @api_key ||= api_key
9
16
  Thread.current[API_KEY_THREAD_KEY] = api_key
10
17
  end
11
18
 
12
19
  def api_key
13
- Thread.current[API_KEY_THREAD_KEY]
20
+ Thread.current[API_KEY_THREAD_KEY] || @api_key
14
21
  end
15
22
 
16
23
  def api_base=(api_base)
24
+ @api_base ||= api_base
17
25
  Thread.current[API_BASE_THREAD_KEY] = api_base
18
26
  end
19
27
 
20
28
  def api_base
21
- Thread.current[API_BASE_THREAD_KEY] || 'https://www.quandl.com/api/v3'
29
+ Thread.current[API_BASE_THREAD_KEY] || @api_base || 'https://www.quandl.com/api/v3'
22
30
  end
23
31
 
24
32
  def api_version=(api_version)
33
+ @api_version ||= api_version
25
34
  Thread.current[API_VERSION_THREAD_KEY] = api_version
26
35
  end
27
36
 
28
37
  def api_version
29
- Thread.current[API_VERSION_THREAD_KEY]
38
+ Thread.current[API_VERSION_THREAD_KEY] || @api_version
39
+ end
40
+
41
+ def reset
42
+ @api_key = nil
43
+ @api_base = nil
44
+ @api_version = nil
30
45
  end
31
46
  end
32
47
  end
@@ -46,29 +46,29 @@ module Quandl
46
46
 
47
47
  case code_letter
48
48
  when 'L'
49
- fail LimitExceededError.new(message, resp.code, resp.body, error_body,
50
- resp.headers, code)
51
- when 'M'
52
- fail InternalServerError.new(message, resp.code, resp.body, error_body,
49
+ raise LimitExceededError.new(message, resp.code, resp.body, error_body,
53
50
  resp.headers, code)
51
+ when 'M'
52
+ raise InternalServerError.new(message, resp.code, resp.body, error_body,
53
+ resp.headers, code)
54
54
  when 'A'
55
- fail AuthenticationError.new(message, resp.code, resp.body, error_body,
56
- resp.headers, code)
55
+ raise AuthenticationError.new(message, resp.code, resp.body, error_body,
56
+ resp.headers, code)
57
57
  when 'P'
58
- fail ForbiddenError.new(message, resp.code, resp.body, error_body,
59
- resp.headers, code)
58
+ raise ForbiddenError.new(message, resp.code, resp.body, error_body,
59
+ resp.headers, code)
60
60
  when 'S'
61
- fail InvalidRequestError.new(message, resp.code, resp.body, error_body,
62
- resp.headers, code)
61
+ raise InvalidRequestError.new(message, resp.code, resp.body, error_body,
62
+ resp.headers, code)
63
63
  when 'C'
64
- fail NotFoundError.new(message, resp.code, resp.body, error_body,
65
- resp.headers, code)
64
+ raise NotFoundError.new(message, resp.code, resp.body, error_body,
65
+ resp.headers, code)
66
66
  when 'X'
67
- fail ServiceUnavailableError.new(message, resp.code, resp.body,
68
- error_body, resp.headers, code)
67
+ raise ServiceUnavailableError.new(message, resp.code, resp.body,
68
+ error_body, resp.headers, code)
69
69
  else
70
- fail QuandlError.new(message, resp.code, resp.body, error_body,
71
- resp.headers, code)
70
+ raise QuandlError.new(message, resp.code, resp.body, error_body,
71
+ resp.headers, code)
72
72
  end
73
73
  end
74
74
  end
@@ -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
@@ -25,6 +25,7 @@ module Quandl
25
25
  def method_missing(method_name, *args, &block)
26
26
  return @raw_data[method_name.to_s] if @raw_data.key?(method_name.to_s)
27
27
  return @raw_data.method(method_name.to_s).call(*args, &block) if @raw_data.respond_to?(method_name.to_s)
28
+
28
29
  super
29
30
  end
30
31
  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'].empty? &&
7
+ data['dataset_data']['column_names'].length != data['dataset_data']['data'].first.length
8
+ raise 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)
@@ -26,6 +31,7 @@ module Quandl
26
31
 
27
32
  def method_missing(method_name, *args, &block)
28
33
  return @meta[method_name.to_s] if @meta.key?(method_name.to_s)
34
+
29
35
  super
30
36
  end
31
37
  end
@@ -8,31 +8,37 @@ 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
- fail(QuandlError, 'You must specific a file handle or folder to write to.') if file_or_folder_path.blank?
32
+ raise(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
34
- Quandl::Connection.handle_api_error(response) if response
35
- fail(QuandlError, 'Unexpected result when fetching bulk download URI.')
40
+ Quandl::Connection.handle_api_error(response) if response&.body
41
+ raise(QuandlError, 'Unexpected result when fetching bulk download URI.')
36
42
  end
37
43
  end
38
44
  uri = URI.parse(download_url)
@@ -40,7 +46,7 @@ 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
+ file_or_folder_path = Pathname.new(file_or_folder_path.to_s).join(File.basename(uri.path)) if File.directory?(file_or_folder_path)
44
50
  file = File.open(file_or_folder_path, 'wb')
45
51
  end
46
52
 
@@ -3,11 +3,11 @@ module Quandl
3
3
  include Quandl::Operations::Get
4
4
  include Quandl::Operations::List
5
5
 
6
- # rubocop:disable Style/AccessorMethodName
6
+ # rubocop:disable Naming/AccessorMethodName
7
7
  def self.get_path
8
8
  default_path + '/metadata'
9
9
  end
10
- # rubocop:enable Style/AccessorMethodName
10
+ # rubocop:enable Naming/AccessorMethodName
11
11
 
12
12
  def database
13
13
  Quandl::Database.get(database_code)
@@ -10,7 +10,8 @@ module Quandl
10
10
  end
11
11
 
12
12
  def more_results?
13
- fail(QuandlError, "#{@klass} does not support pagination yet") if !@meta.key?('total_pages') && !@meta.key?('current_page')
13
+ raise(QuandlError, "#{@klass} does not support pagination yet") if !@meta.key?('total_pages') && !@meta.key?('current_page')
14
+
14
15
  @meta['total_pages'] > @meta['current_page']
15
16
  end
16
17
 
@@ -19,7 +20,7 @@ module Quandl
19
20
  end
20
21
 
21
22
  def to_csv
22
- fail(QuandlError, 'No values to export') if @values.empty?
23
+ raise(QuandlError, 'No values to export') if @values.empty?
23
24
 
24
25
  CSV.generate do |csv|
25
26
  csv << @values.first.column_names
@@ -39,6 +40,7 @@ module Quandl
39
40
  return @meta[method_name.to_s] if @meta.key?(method_name.to_s)
40
41
  return @meta[*args] if method_name.to_s == '[]' && @meta.key?(args[0].to_s)
41
42
  return @values.method(method_name).call(*args, &block) if @values.respond_to?(method_name)
43
+
42
44
  super
43
45
  end
44
46
  end
@@ -10,11 +10,11 @@ module Quandl
10
10
  new(response_data[lookup_key.singularize])
11
11
  end
12
12
 
13
- # rubocop:disable Style/AccessorMethodName
13
+ # rubocop:disable Naming/AccessorMethodName
14
14
  def get_path
15
15
  default_path
16
16
  end
17
- # rubocop:enable Style/AccessorMethodName
17
+ # rubocop:enable Naming/AccessorMethodName
18
18
  end
19
19
  end
20
20
  end
@@ -1,11 +1,12 @@
1
1
  module Quandl
2
2
  class Util
3
3
  def self.methodize(string)
4
- string.gsub(/\./, '').parameterize.gsub(/\-/, '_')
4
+ string.delete('.').parameterize.tr('-', '_')
5
5
  end
6
6
 
7
7
  def self.convert_to_dates(hash)
8
8
  return hash unless hash.is_a?(Hash)
9
+
9
10
  hash.update(hash) do |_k, v|
10
11
  if v.is_a?(String) && v =~ /^\d{4}-\d{2}-\d{2}$/ # Date
11
12
  Date.parse(v)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Quandl
2
- VERSION = '1.0.1'
4
+ VERSION = '1.1.1'
3
5
  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.1.1
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: 2020-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -17,70 +17,56 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 4.2.3
20
+ version: 5.2.4.3
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 4.2.3
28
- - !ruby/object:Gem::Dependency
29
- name: rest-client
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: 1.8.0
35
- type: :runtime
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: 1.8.0
27
+ version: 5.2.4.3
42
28
  - !ruby/object:Gem::Dependency
43
29
  name: json
44
30
  requirement: !ruby/object:Gem::Requirement
45
31
  requirements:
46
32
  - - "~>"
47
33
  - !ruby/object:Gem::Version
48
- version: 1.8.3
34
+ version: 2.3.0
49
35
  type: :runtime
50
36
  prerelease: false
51
37
  version_requirements: !ruby/object:Gem::Requirement
52
38
  requirements:
53
39
  - - "~>"
54
40
  - !ruby/object:Gem::Version
55
- version: 1.8.3
41
+ version: 2.3.0
56
42
  - !ruby/object:Gem::Dependency
57
- name: bundler
43
+ name: rest-client
58
44
  requirement: !ruby/object:Gem::Requirement
59
45
  requirements:
60
46
  - - "~>"
61
47
  - !ruby/object:Gem::Version
62
- version: '1.10'
63
- type: :development
48
+ version: 2.0.2
49
+ type: :runtime
64
50
  prerelease: false
65
51
  version_requirements: !ruby/object:Gem::Requirement
66
52
  requirements:
67
53
  - - "~>"
68
54
  - !ruby/object:Gem::Version
69
- version: '1.10'
55
+ version: 2.0.2
70
56
  - !ruby/object:Gem::Dependency
71
- name: rake
57
+ name: factory_girl
72
58
  requirement: !ruby/object:Gem::Requirement
73
59
  requirements:
74
60
  - - "~>"
75
61
  - !ruby/object:Gem::Version
76
- version: '10.0'
62
+ version: 4.5.0
77
63
  type: :development
78
64
  prerelease: false
79
65
  version_requirements: !ruby/object:Gem::Requirement
80
66
  requirements:
81
67
  - - "~>"
82
68
  - !ruby/object:Gem::Version
83
- version: '10.0'
69
+ version: 4.5.0
84
70
  - !ruby/object:Gem::Dependency
85
71
  name: rspec
86
72
  requirement: !ruby/object:Gem::Requirement
@@ -96,61 +82,33 @@ dependencies:
96
82
  - !ruby/object:Gem::Version
97
83
  version: '0'
98
84
  - !ruby/object:Gem::Dependency
99
- name: pry-byebug
85
+ name: rubocop
100
86
  requirement: !ruby/object:Gem::Requirement
101
87
  requirements:
102
- - - "~>"
88
+ - - ">="
103
89
  - !ruby/object:Gem::Version
104
- version: 3.1.0
90
+ version: '0'
105
91
  type: :development
106
92
  prerelease: false
107
93
  version_requirements: !ruby/object:Gem::Requirement
108
94
  requirements:
109
- - - "~>"
95
+ - - ">="
110
96
  - !ruby/object:Gem::Version
111
- version: 3.1.0
97
+ version: '0'
112
98
  - !ruby/object:Gem::Dependency
113
99
  name: webmock
114
100
  requirement: !ruby/object:Gem::Requirement
115
101
  requirements:
116
102
  - - "~>"
117
103
  - !ruby/object:Gem::Version
118
- version: 1.21.0
104
+ version: 3.0.1
119
105
  type: :development
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
108
  requirements:
123
109
  - - "~>"
124
110
  - !ruby/object:Gem::Version
125
- version: 1.21.0
126
- - !ruby/object:Gem::Dependency
127
- name: factory_girl
128
- requirement: !ruby/object:Gem::Requirement
129
- requirements:
130
- - - "~>"
131
- - !ruby/object:Gem::Version
132
- version: 4.5.0
133
- type: :development
134
- prerelease: false
135
- version_requirements: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - "~>"
138
- - !ruby/object:Gem::Version
139
- version: 4.5.0
140
- - !ruby/object:Gem::Dependency
141
- name: rubocopter
142
- requirement: !ruby/object:Gem::Requirement
143
- requirements:
144
- - - ">="
145
- - !ruby/object:Gem::Version
146
- version: '0'
147
- type: :development
148
- prerelease: false
149
- version_requirements: !ruby/object:Gem::Requirement
150
- requirements:
151
- - - ">="
152
- - !ruby/object:Gem::Version
153
- version: '0'
111
+ version: 3.0.1
154
112
  description: A ruby implementation of the quandl client to be used as an ORM for quandl's
155
113
  restful APIs.
156
114
  email:
@@ -193,10 +151,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
151
  - !ruby/object:Gem::Version
194
152
  version: '0'
195
153
  requirements: []
196
- rubyforge_project:
197
- rubygems_version: 2.4.5
154
+ rubygems_version: 3.0.6
198
155
  signing_key:
199
156
  specification_version: 4
200
157
  summary: An ORM interface into the quandl api.
201
158
  test_files: []
202
- has_rdoc: