quandl_client 2.5.0 → 2.5.1

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: 90fc4b658334f8b64a152c8856d1d5746d2f30d6
4
- data.tar.gz: dfd804e1df9105ef39ab391f5af287dd2b96bf9c
3
+ metadata.gz: 3018260bc400c7f59310d511e13cb51bfbffe97c
4
+ data.tar.gz: 4ab1e74283f845bb3dee3521c18367afc4d9a8ad
5
5
  SHA512:
6
- metadata.gz: 5c03db4abbe8ba3b1b815be22c42f7dbdc435c770e69ad9a3adadb454b129b306a6bb35f456da4cd765c8fd480898d38237653f0ffb28d7dfe3c34d960e9cb50
7
- data.tar.gz: 93bc9a5a89cd0bdefecc6fc9a183ed89c59bf7e83879cf6d1471b8a8ca1c446b50a391f493e732e45ba4f9cc41fb7eadf167b957cea75a7e1503b3b477267c2b
6
+ metadata.gz: 0c1931a9c197ae51d561b1dea40675ba24cca2247262b1c157fcbc78956738d0fd8be26b3c9aee7dd9c8a7c7498336486853debe63e2f0f2a6882b22de6349a5
7
+ data.tar.gz: 86c0a7a0f16a237c7cd8d38a1b0ddbfefaaaa675516857740b245374790507392ff457583c57692bc8a946e6a3b307e22bad7eecc6e07452e817910356ff793d
data/UPGRADE.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 2.5.1
2
+
3
+ * QUGC-57 move data validation from Quandl::Format into Quandl::Client. Data validations only run on #valid?
4
+ * QUGC-53 numeric codes require the full code
5
+
6
+
1
7
  # 2.5.0
2
8
 
3
9
  * remove yajl
data/examples/create.rb CHANGED
@@ -15,4 +15,18 @@ include Quandl::Client
15
15
  Quandl::Client.use ENV['QUANDL_TEST_URL']
16
16
  Quandl::Client.token = ENV['QUANDL_TEST_TOKEN']
17
17
 
18
- binding.pry
18
+ # set some attributes
19
+ d = Dataset.new(
20
+ code: "MY_DATASET_#{Time.now.to_i.to_s(16)}",
21
+ name: "My dataset has a name.",
22
+ description: "This is the description.",
23
+ data: [[ 2014, 1, 2 ]]
24
+ )
25
+ # POST to server
26
+ d.save
27
+
28
+ if d.saved?
29
+ puts "View your new dataset at: #{d.full_url}"
30
+ else
31
+ puts "Something went wrong:\n#{d.human_status}\n#{d.human_error_messages}"
32
+ end
data/examples/find.rb ADDED
@@ -0,0 +1,18 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
+
3
+ # DEBUGGING
4
+ require 'pry'
5
+ require "quandl/fabricate"
6
+
7
+ # LOAD
8
+ require "quandl/client"
9
+ include Quandl::Client
10
+
11
+ # CONFIGURE
12
+ Quandl::Client.use ENV['QUANDL_URL']
13
+ Quandl::Client.token = ENV['QUANDL_TOKEN']
14
+
15
+ # FIND
16
+ d = Dataset.find('MCX.ALMG2014')
17
+
18
+ binding.pry
@@ -14,7 +14,7 @@ class Quandl::Client::Dataset < Quandl::Client::Base
14
14
  # enforce code formatting
15
15
  if value.is_a?(String)
16
16
  # ensure slashes are forward facing
17
- value = value.gsub("\\","/")
17
+ value = value.gsub("\\","/").gsub(".","/")
18
18
  # ensure uppercase
19
19
  value = value.upcase
20
20
  end
@@ -45,6 +45,10 @@ class Quandl::Client::Dataset < Quandl::Client::Base
45
45
  validates :code, presence: true, format: { with: Quandl::Pattern.code, message: "is invalid. Expected format: #{Quandl::Pattern.code.to_example}" }
46
46
  validates :display_url, allow_blank: true, url: true
47
47
  validate :data_columns_should_not_exceed_column_names!
48
+ validate :data_rows_should_have_equal_columns!
49
+ validate :data_row_count_should_match_column_count!
50
+ validate :ambiguous_code_requires_source_code!
51
+
48
52
 
49
53
  ##############
50
54
  # PROPERTIES #
@@ -121,6 +125,15 @@ class Quandl::Client::Dataset < Quandl::Client::Base
121
125
 
122
126
  protected
123
127
 
128
+ def ambiguous_code_requires_source_code!
129
+ if code.to_s.numeric? && source_code.blank?
130
+ message = %Q{Pure numerical codes like "#{code}" are not allowed unless you prefix them with a source code. Do this:\ncode: <your-username>/#{code}}
131
+ self.errors.add( :data, message )
132
+ return false
133
+ end
134
+ true
135
+ end
136
+
124
137
  def data_columns_should_not_exceed_column_names!
125
138
  if dataset_data.data? && column_names.present? && data.first.count != column_names.count
126
139
  self.errors.add( :data, "You may not change the number of columns in a dataset. This dataset has #{column_names.count} columns but you tried to send #{data.first.count} columns." )
@@ -129,6 +142,40 @@ class Quandl::Client::Dataset < Quandl::Client::Base
129
142
  true
130
143
  end
131
144
 
145
+ def data_rows_should_have_equal_columns!
146
+ # skip validation unless data is present
147
+ return true unless dataset_data.data?
148
+ # use first row as expected column count
149
+ column_count = data[0].count
150
+ # check each row
151
+ data.each_with_index do |row, index|
152
+ # the row is valid if it's count matches the first row's count
153
+ next if row.count == column_count
154
+ # the row is invalid if the count is mismatched
155
+ self.errors.add( :data, "Unexpected number of points in this row '#{row}'. Expected #{column_count} but found #{row.count} based on #{data[0]}" )
156
+ # return validation failure
157
+ return false
158
+ end
159
+ true
160
+ end
161
+
162
+ def data_row_count_should_match_column_count!
163
+ # skip validation unless data and column_names present
164
+ return true unless dataset_data.data? && column_names.present?
165
+ # count the number of expected columns
166
+ column_count = column_names.count
167
+ # check each row
168
+ data.each_with_index do |row, index|
169
+ # the row is valid if it's count matches the first row's count
170
+ next if row.count == column_count
171
+ # the row is invalid if the count is mismatched
172
+ self.errors.add( :data, "Unexpected number of points in this row '#{row}'. Expected #{column_names.count} but found #{row.count} based on #{column_names}" )
173
+ # return validation failure
174
+ return false
175
+ end
176
+ true
177
+ end
178
+
132
179
  def save_dataset_data
133
180
  return if (!saved? && id.blank?)
134
181
  return if !dataset_data.data?
@@ -1,6 +1,6 @@
1
1
  module Quandl
2
2
  module Client
3
- VERSION = '2.5.0'
3
+ VERSION = '2.5.1'
4
4
  API_VERSION = 'v2'
5
5
 
6
6
  class << self
@@ -3,6 +3,32 @@ require 'spec_helper'
3
3
 
4
4
  describe Dataset do
5
5
 
6
+ let(:dataset){ build(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
7
+ subject{ dataset }
8
+
9
+ context "given ambiguous code" do
10
+ before(:each){
11
+ dataset.source_code = nil
12
+ dataset.code = '12345'
13
+ dataset.valid?
14
+ }
15
+ its(:valid?){ should be_false }
16
+ its('errors.messages'){ should eq({ data: ["Pure numerical codes like \"12345\" are not allowed unless you prefix them with a source code. Do this:\ncode: <your-username>/12345"]}) }
17
+ end
18
+
19
+ context "mismatch row count" do
20
+ before(:each){ dataset.data = [[2012, 1,2],[2011, 1,2,3]] }
21
+ its(:valid?){ should be_false }
22
+ end
23
+
24
+ context "mismatch column_names count" do
25
+ before(:each){
26
+ dataset.column_names = ['Date','Value']
27
+ dataset.data = [[2012, 1,2],[2011, 1,2]]
28
+ }
29
+ its(:valid?){ should be_false }
30
+ end
31
+
6
32
  describe "#code" do
7
33
 
8
34
  before(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hilscher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-07 00:00:00.000000000 Z
11
+ date: 2014-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -196,6 +196,7 @@ files:
196
196
  - Rakefile
197
197
  - UPGRADE.md
198
198
  - examples/create.rb
199
+ - examples/find.rb
199
200
  - examples/login.rb
200
201
  - examples/search.rb
201
202
  - examples/trims.rb