quandl_client 0.1.14 → 0.1.15

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.
data/UPGRADE.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.15
2
+
3
+ * revise parse_json to respond with more informative error
4
+ * validation errors should return 422
5
+
1
6
  ## 0.1.14
2
7
 
3
8
  * add Dataset#locations spec to test that location data is returned in the same order as it is sent.
@@ -14,7 +14,7 @@ class ParseJSON < Faraday::Response::Middleware
14
14
  end
15
15
 
16
16
  def parse(body, env)
17
- json = parse_json(body)
17
+ json = parse_json(body, env)
18
18
  errors = json.delete(:errors) || {}
19
19
  metadata = json.delete(:metadata) || {}
20
20
  # collect some response data
@@ -32,19 +32,23 @@ class ParseJSON < Faraday::Response::Middleware
32
32
  object
33
33
  end
34
34
 
35
- def parse_json(body = nil)
35
+ def parse_json(body = nil, env)
36
36
  body ||= '{}'
37
- message = "Response from the API must behave like a Hash or an Array (last JSON response was #{body.inspect})"
38
-
39
37
  json = begin
40
38
  Yajl.load(body, :symbolize_keys => true)
41
39
  rescue Yajl::ParseError
42
- { id: 1, errors: { parse_error: message } }
43
-
44
- # raise Her::Errors::ParseError, message
40
+ nil
41
+ end
42
+ # invalid json body?
43
+ if json.blank?
44
+ # fallback to error message
45
+ json = {
46
+ id: 1,
47
+ errors: {
48
+ parse_error: "Quandl::Client::ParseJSON error. status: #{env[:status]}, body: #{body.inspect}"
49
+ }
50
+ }
45
51
  end
46
- # raise Her::Errors::ParseError, message unless json.is_a?(Hash) or json.is_a?(Array)
47
-
48
52
  json
49
53
  end
50
54
 
@@ -1,6 +1,6 @@
1
1
  module Quandl
2
2
  module Client
3
- VERSION = '0.1.14'
3
+ VERSION = '0.1.15'
4
4
  API_VERSION = 'v1'
5
5
 
6
6
  class << self
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+
6
+ subject{
7
+ build(:dataset, source_code: create(:source).code )
8
+ }
9
+
10
+ describe "#availability_delay" do
11
+ context "given valid input" do
12
+ it "saves the delay" do
13
+ delay = '02:00:10'
14
+ subject.availability_delay = delay
15
+ subject.save
16
+ Dataset.find(subject.id).availability_delay.should eq delay
17
+ end
18
+
19
+ end
20
+ end
21
+
22
+ describe "#locations" do
23
+ context "with navigation" do
24
+ it "should return the data in the right order" do
25
+ locations = [
26
+ {
27
+ category: 'js_http',
28
+ url: "http://test-#{(Time.now.to_f * 1000).to_i}.com/data",
29
+ navigation: [
30
+ {:id => 'id303', :type => 'link'},
31
+ {:name => 'selectionname', :type => 'text', :value => 'cd' },
32
+ {:name => 'auswaehlen', :type => 'button'},
33
+ {:id => "id#cd", :type => 'link'},
34
+ {:name => 'werteabruf', :type => 'button'}
35
+ ]
36
+ }
37
+ ]
38
+ subject.locations = locations
39
+ subject.save
40
+ dataset = Dataset.find(subject.id)
41
+ dataset.locations[0][:category].should eq locations[0][:category]
42
+ dataset.locations[0][:url].should eq locations[0][:url]
43
+ dataset.locations[0][:navigation].should eq locations[0][:navigation]
44
+ end
45
+ end
46
+ context "datasets sharing location" do
47
+
48
+ let(:location){ [{ category: "http", url: "http://www.bankofcanada.ca/rates/price-indexes/cpi/"}] }
49
+ let(:dataset1){ create(:dataset, source_code: create(:source).code, locations: location ) }
50
+ let(:dataset2){ create(:dataset, source_code: create(:source).code, locations: location ) }
51
+
52
+ it "should share the location" do
53
+ Dataset.find(dataset1.id).locations.should eq Dataset.find(dataset2.id).locations
54
+ end
55
+
56
+ it "should update the dataset" do
57
+ d = Dataset.find(dataset1.id)
58
+ d.data = [[ Date.today, 42, 68 ]]
59
+ d.save
60
+ d.status.should eq 200
61
+ end
62
+
63
+ end
64
+ end
65
+
66
+ end
@@ -37,11 +37,12 @@ describe Dataset do
37
37
  context "when updated" do
38
38
 
39
39
  let(:source){ create(:source) }
40
- let(:dataset){ create(:dataset, source_code: source.code, data: Quandl::Data::Random.table(rows: 20, columns: 2).to_csv ) }
41
-
42
- it "should change data" do
40
+ let(:dataset){ create(:dataset, source_code: source.code, data: Quandl::Data::Random.table(rows: 20, columns: 2, nils: false).to_csv ) }
41
+ subject{ Dataset.find(dataset.id) }
42
+
43
+
44
+ it "should update data" do
43
45
  # update the dataset
44
- subject = Dataset.find(dataset.id)
45
46
  new_row = [ subject.data_table[0][0], 1.0, 2.0]
46
47
  subject.data = [ new_row ]
47
48
  subject.save
@@ -49,13 +50,33 @@ describe Dataset do
49
50
  Dataset.find(dataset.id).data_table.sort_descending[0].should eq new_row
50
51
  end
51
52
 
52
- it "should change column_spec" do
53
- subject = Dataset.find(dataset.id)
53
+ it "should update column_spec" do
54
54
  subject.column_spec = "[0,[\"Date \\n\",{}],[\"Column 1 \",{}],[\"New Column Name \",{}]]"
55
55
  subject.save
56
56
  Dataset.find(dataset.id).column_spec.should eq subject.column_spec
57
57
  end
58
58
 
59
+ context "with new rows" do
60
+
61
+ it "should include new row" do
62
+ new_data = 10.times.collect{|i| [Date.parse(subject.to_date) + i + 1, rand(12), rand(12) ] }
63
+ new_data = Quandl::Data::Table.new(new_data).sort_descending
64
+ subject.data = new_data
65
+ subject.save
66
+ updated_dataset = Dataset.find(subject.id)
67
+ updated_dataset.data_table.to_date[0].should eq new_data.to_date[0]
68
+ end
69
+
70
+ it "should include old rows" do
71
+ new_data = 10.times.collect{|i| [Date.parse(subject.to_date) + i + 2, rand(12), rand(12) ] }
72
+ new_data = Quandl::Data::Table.new(new_data).sort_descending
73
+ subject.data = new_data
74
+ subject.save
75
+ updated_dataset = Dataset.find(subject.id)
76
+ updated_dataset.data_table.count.should eq 30
77
+ end
78
+ end
79
+
59
80
  end
60
81
 
61
82
  end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+
6
+ let(:source){ create(:source) }
7
+ subject{ build(:dataset, source_code: source.code, data: Quandl::Data::Random.table(rows: 20, columns: 2) ) }
8
+
9
+ describe "#from_date" do
10
+ context "before_save" do
11
+ it "should be nil" do
12
+ subject.from_date.should be_nil
13
+ end
14
+ end
15
+ context "after_save" do
16
+ before(:each){ subject.save }
17
+ it "should equal the last date" do
18
+ subject.from_date.should eq subject.data_table.to_date[-1][0].to_s
19
+ end
20
+ end
21
+ end
22
+
23
+ describe "#to_date" do
24
+ context "before_save" do
25
+ it "should be nil" do
26
+ subject.to_date.should be_nil
27
+ end
28
+ end
29
+ context "after_save" do
30
+ before(:each){ subject.save }
31
+ it "should equal the first date" do
32
+ subject.to_date.should eq subject.data_table.to_date[0][0].to_s
33
+ end
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+
6
+ describe "#code" do
7
+
8
+ before(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
9
+
10
+ let(:source){ create(:source) }
11
+ let(:dataset){ create(:dataset, source_code: source.code ) }
12
+ let(:invalid_dataset){ create(:dataset, source_code: source.code, code: dataset.code ) }
13
+ subject{ invalid_dataset }
14
+
15
+ it "should create the dataset" do
16
+ dataset.status.should eq 201
17
+ end
18
+
19
+ its(:saved?){ should be_false }
20
+ its(:status){ should eq 422 }
21
+
22
+ end
23
+
24
+
25
+ end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,7 @@ require "quandl/client"
11
11
 
12
12
  include Quandl::Client
13
13
  Quandl::Client.use 'http://localhost:3000/api/'
14
+ # Quandl::Client.use 'http://staging.quandl.com/api/'
14
15
  Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN']
15
16
 
16
17
  RSpec.configure do |config|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-14 00:00:00.000000000 Z
12
+ date: 2013-09-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -252,10 +252,12 @@ files:
252
252
  - quandl_client.gemspec
253
253
  - spec/factories/dataset.rb
254
254
  - spec/factories/source.rb
255
- - spec/quandl/client/models/dataset/location_spec.rb
256
- - spec/quandl/client/models/dataset/persistence_spec.rb
257
- - spec/quandl/client/models/dataset/search_spec.rb
258
- - spec/quandl/client/models/source_spec.rb
255
+ - spec/quandl/client/dataset/location_spec.rb
256
+ - spec/quandl/client/dataset/persistence_spec.rb
257
+ - spec/quandl/client/dataset/search_spec.rb
258
+ - spec/quandl/client/dataset/trim_spec.rb
259
+ - spec/quandl/client/dataset/validation_spec.rb
260
+ - spec/quandl/client/source_spec.rb
259
261
  - spec/spec_helper.rb
260
262
  homepage: http://blake.hilscher.ca/
261
263
  licenses:
@@ -285,8 +287,10 @@ summary: Client rest orm.
285
287
  test_files:
286
288
  - spec/factories/dataset.rb
287
289
  - spec/factories/source.rb
288
- - spec/quandl/client/models/dataset/location_spec.rb
289
- - spec/quandl/client/models/dataset/persistence_spec.rb
290
- - spec/quandl/client/models/dataset/search_spec.rb
291
- - spec/quandl/client/models/source_spec.rb
290
+ - spec/quandl/client/dataset/location_spec.rb
291
+ - spec/quandl/client/dataset/persistence_spec.rb
292
+ - spec/quandl/client/dataset/search_spec.rb
293
+ - spec/quandl/client/dataset/trim_spec.rb
294
+ - spec/quandl/client/dataset/validation_spec.rb
295
+ - spec/quandl/client/source_spec.rb
292
296
  - spec/spec_helper.rb
@@ -1,46 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Dataset do
5
-
6
- subject{
7
- build(:dataset, source_code: create(:source).code )
8
- }
9
-
10
- describe "#availability_delay" do
11
- context "given valid input" do
12
- it "saves the delay" do
13
- delay = '02:00:10'
14
- subject.availability_delay = delay
15
- subject.save
16
- Dataset.find(subject.id).availability_delay.should eq delay
17
- end
18
-
19
- end
20
- end
21
-
22
- describe "#locations" do
23
- it "should save and return the location data" do
24
- locations = [
25
- {
26
- category: 'js_http',
27
- url: "http://test-#{(Time.now.to_f * 1000).to_i}.com/data",
28
- navigation: [
29
- {:id => 'id303', :type => 'link'},
30
- {:name => 'selectionname', :type => 'text', :value => 'cd' },
31
- {:name => 'auswaehlen', :type => 'button'},
32
- {:id => "id#cd", :type => 'link'},
33
- {:name => 'werteabruf', :type => 'button'}
34
- ]
35
- }
36
- ]
37
- subject.locations = locations
38
- subject.save
39
- dataset = Dataset.find(subject.id)
40
- dataset.locations[0][:category].should eq locations[0][:category]
41
- dataset.locations[0][:url].should eq locations[0][:url]
42
- dataset.locations[0][:navigation].should eq locations[0][:navigation]
43
- end
44
- end
45
-
46
- end