quandl_client 2.7.5 → 2.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.gitignore +7 -7
  2. data/.rspec +1 -1
  3. data/.travis.yml +20 -20
  4. data/.yardopts +2 -2
  5. data/Gemfile +12 -12
  6. data/Guardfile +8 -8
  7. data/LICENSE +7 -7
  8. data/README.md +303 -303
  9. data/Rakefile +31 -35
  10. data/UPGRADE.md +190 -213
  11. data/VERSION +1 -1
  12. data/examples/create.rb +32 -32
  13. data/examples/find.rb +17 -17
  14. data/examples/login.rb +12 -12
  15. data/examples/search.rb +12 -12
  16. data/examples/trims.rb +15 -15
  17. data/lib/quandl/client.rb +49 -49
  18. data/lib/quandl/client/base.rb +91 -91
  19. data/lib/quandl/client/base/attributes.rb +15 -15
  20. data/lib/quandl/client/base/model.rb +40 -40
  21. data/lib/quandl/client/base/search.rb +74 -74
  22. data/lib/quandl/client/base/validation.rb +101 -101
  23. data/lib/quandl/client/middleware.rb +9 -9
  24. data/lib/quandl/client/middleware/parse_json.rb +85 -85
  25. data/lib/quandl/client/models/dataset.rb +261 -245
  26. data/lib/quandl/client/models/dataset/data.rb +57 -57
  27. data/lib/quandl/client/models/location.rb +10 -10
  28. data/lib/quandl/client/models/report.rb +14 -14
  29. data/lib/quandl/client/models/scraper.rb +16 -16
  30. data/lib/quandl/client/models/sheet.rb +50 -50
  31. data/lib/quandl/client/models/source.rb +48 -40
  32. data/lib/quandl/client/models/superset.rb +59 -59
  33. data/lib/quandl/client/models/user.rb +7 -7
  34. data/lib/quandl/client/version.rb +14 -14
  35. data/lib/quandl/her/remove_method_data.rb +8 -8
  36. data/lib/quandl/pattern.rb +37 -37
  37. data/lib/quandl/pattern/client.rb +8 -8
  38. data/quandl_client.gemspec +33 -33
  39. data/spec/factories/dataset.rb +10 -10
  40. data/spec/factories/sheet.rb +7 -7
  41. data/spec/factories/source.rb +9 -9
  42. data/spec/fixtures/scraper.rb +5 -5
  43. data/spec/lib/quandl/client/dataset/attributes_spec.rb +63 -63
  44. data/spec/lib/quandl/client/dataset/data_spec.rb +92 -92
  45. data/spec/lib/quandl/client/dataset/location_spec.rb +65 -65
  46. data/spec/lib/quandl/client/dataset/persistence_spec.rb +104 -104
  47. data/spec/lib/quandl/client/dataset/search_spec.rb +19 -19
  48. data/spec/lib/quandl/client/dataset/source_spec.rb +47 -47
  49. data/spec/lib/quandl/client/dataset/trim_spec.rb +35 -35
  50. data/spec/lib/quandl/client/dataset/validation_spec.rb +68 -68
  51. data/spec/lib/quandl/client/dataset_spec.rb +57 -57
  52. data/spec/lib/quandl/client/scraper_spec.rb +71 -71
  53. data/spec/lib/quandl/client/sheet_spec.rb +37 -37
  54. data/spec/lib/quandl/client/source_spec.rb +51 -51
  55. data/spec/spec_helper.rb +30 -30
  56. metadata +27 -5
@@ -1,66 +1,66 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Dataset do
5
-
6
- subject{
7
- build(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" )
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: "QUANDL_CLIENT_TEST_SOURCE", locations: location ) }
50
- let(:dataset2){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", 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
-
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+
6
+ subject{
7
+ build(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" )
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: "QUANDL_CLIENT_TEST_SOURCE", locations: location ) }
50
+ let(:dataset2){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", 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
66
  end
@@ -1,105 +1,105 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Dataset do
5
- context "when built" do
6
- subject{ build(:dataset) }
7
- its(:saved?){ should be_false }
8
- its(:valid?){ should be_true }
9
- end
10
-
11
- its(:request_started_at){ should be_nil }
12
- its(:request_finished_at){ should be_nil }
13
- its(:elapsed_request_time){ should be_nil }
14
-
15
- context "when created" do
16
- context "without token" do
17
- before(:all){ Quandl::Client.token = '' }
18
-
19
- let(:dataset){ create(:dataset) }
20
- subject{ dataset }
21
-
22
- its(:saved?){ should be_false }
23
- its(:status){ should eq 401 }
24
-
25
- its(:request_started_at){ should be_a Time }
26
-
27
- after(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
28
- end
29
- context "with token" do
30
-
31
- let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
32
- subject{ dataset }
33
-
34
- its(:saved?){ should be_true }
35
- its(:status){ should eq 201 }
36
-
37
- end
38
- context "with data" do
39
-
40
- let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand(rows: 20, columns: 2, nils: false) ) }
41
- subject{ dataset }
42
-
43
- its(:saved?){ should be_true }
44
- its(:status){ should eq 201 }
45
-
46
- end
47
- end
48
-
49
- context "when updated" do
50
-
51
- let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand(rows: 20, columns: 2, nils: false).to_csv ) }
52
- subject{ Dataset.find(dataset.id) }
53
-
54
- it "should include new row" do
55
- new_data = 10.times.collect{|i| [Date.parse(subject.to_date) + i + 1, rand(12), rand(12) ] }
56
- new_data = Quandl::Data.new(new_data).sort_descending
57
- subject.data = new_data
58
- subject.save
59
- updated_dataset = Dataset.find(subject.id)
60
- updated_dataset.data.to_date[0].should eq new_data.to_date[0]
61
- end
62
-
63
- it "should include old rows" do
64
- new_data = 10.times.collect{|i| [Date.parse(subject.to_date) + i + 2, rand(12), rand(12) ] }
65
- new_data = Quandl::Data.new(new_data).sort_descending
66
- subject.data = new_data
67
- subject.save
68
- updated_dataset = Dataset.find(subject.id)
69
- updated_dataset.data.count.should eq 30
70
- end
71
-
72
- end
73
-
74
- context "#destroy" do
75
-
76
- let(:dataset){ create(:dataset, private: false ) }
77
- before(:each){ dataset.destroy }
78
- subject{ dataset }
79
-
80
- its(:status){ should eq 200 }
81
-
82
- its(:request_started_at){ should be_a Time }
83
- its(:request_finished_at){ should be_a Time }
84
- its(:elapsed_request_time){ should be > 0 }
85
-
86
- end
87
-
88
- context "#destroy when user" do
89
-
90
- let(:dataset){ create(:dataset, private: false ) }
91
-
92
- it "should not delete the dataset with a user token" do
93
- id = dataset.id
94
- # behave as a user
95
- Quandl::Client.token = ENV['QUANDL_TEST_TOKEN']
96
- user_dataset = Dataset.find(id)
97
- user_dataset.destroy
98
- user_dataset.status.should eq 403
99
- end
100
-
101
- after(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
102
-
103
- end
104
-
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+ context "when built" do
6
+ subject{ build(:dataset) }
7
+ its(:saved?){ should be_false }
8
+ its(:valid?){ should be_true }
9
+ end
10
+
11
+ its(:request_started_at){ should be_nil }
12
+ its(:request_finished_at){ should be_nil }
13
+ its(:elapsed_request_time){ should be_nil }
14
+
15
+ context "when created" do
16
+ context "without token" do
17
+ before(:all){ Quandl::Client.token = '' }
18
+
19
+ let(:dataset){ create(:dataset) }
20
+ subject{ dataset }
21
+
22
+ its(:saved?){ should be_false }
23
+ its(:status){ should eq 401 }
24
+
25
+ its(:request_started_at){ should be_a Time }
26
+
27
+ after(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
28
+ end
29
+ context "with token" do
30
+
31
+ let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
32
+ subject{ dataset }
33
+
34
+ its(:saved?){ should be_true }
35
+ its(:status){ should eq 201 }
36
+
37
+ end
38
+ context "with data" do
39
+
40
+ let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand(rows: 20, columns: 2, nils: false) ) }
41
+ subject{ dataset }
42
+
43
+ its(:saved?){ should be_true }
44
+ its(:status){ should eq 201 }
45
+
46
+ end
47
+ end
48
+
49
+ context "when updated" do
50
+
51
+ let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand(rows: 20, columns: 2, nils: false).to_csv ) }
52
+ subject{ Dataset.find(dataset.id) }
53
+
54
+ it "should include new row" do
55
+ new_data = 10.times.collect{|i| [Date.parse(subject.to_date) + i + 1, rand(12), rand(12) ] }
56
+ new_data = Quandl::Data.new(new_data).sort_descending
57
+ subject.data = new_data
58
+ subject.save
59
+ updated_dataset = Dataset.find(subject.id)
60
+ updated_dataset.data.to_date[0].should eq new_data.to_date[0]
61
+ end
62
+
63
+ it "should include old rows" do
64
+ new_data = 10.times.collect{|i| [Date.parse(subject.to_date) + i + 2, rand(12), rand(12) ] }
65
+ new_data = Quandl::Data.new(new_data).sort_descending
66
+ subject.data = new_data
67
+ subject.save
68
+ updated_dataset = Dataset.find(subject.id)
69
+ updated_dataset.data.count.should eq 30
70
+ end
71
+
72
+ end
73
+
74
+ context "#destroy" do
75
+
76
+ let(:dataset){ create(:dataset, private: false ) }
77
+ before(:each){ dataset.destroy }
78
+ subject{ dataset }
79
+
80
+ its(:status){ should eq 200 }
81
+
82
+ its(:request_started_at){ should be_a Time }
83
+ its(:request_finished_at){ should be_a Time }
84
+ its(:elapsed_request_time){ should be > 0 }
85
+
86
+ end
87
+
88
+ context "#destroy when user" do
89
+
90
+ let(:dataset){ create(:dataset, private: false ) }
91
+
92
+ it "should not delete the dataset with a user token" do
93
+ id = dataset.id
94
+ # behave as a user
95
+ Quandl::Client.token = ENV['QUANDL_TEST_TOKEN']
96
+ user_dataset = Dataset.find(id)
97
+ user_dataset.destroy
98
+ user_dataset.status.should eq 403
99
+ end
100
+
101
+ after(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
102
+
103
+ end
104
+
105
105
  end
@@ -1,20 +1,20 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Dataset do
5
-
6
- let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
7
-
8
- it "should find the dataset by id" do
9
- Dataset.find(dataset.id).id.should eq dataset.id
10
- end
11
-
12
- it "should find the dataset by full code" do
13
- Dataset.find(dataset.full_code).id.should eq dataset.id
14
- end
15
-
16
- it "should exclude_data" do
17
- Dataset.find(dataset.id).attributes[:data].should be_blank
18
- end
19
-
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+
6
+ let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
7
+
8
+ it "should find the dataset by id" do
9
+ Dataset.find(dataset.id).id.should eq dataset.id
10
+ end
11
+
12
+ it "should find the dataset by full code" do
13
+ Dataset.find(dataset.full_code).id.should eq dataset.id
14
+ end
15
+
16
+ it "should exclude_data" do
17
+ Dataset.find(dataset.id).attributes[:data].should be_blank
18
+ end
19
+
20
20
  end
@@ -1,47 +1,47 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Dataset do
5
-
6
- let(:dataset){ create(:dataset, source_code: nil ) }
7
- subject{ dataset }
8
-
9
- context "admin user" do
10
-
11
- its(:saved?){ should be_true }
12
- its(:source_code){ should be_present }
13
-
14
- describe "#source_code=" do
15
- before(:each){
16
- subject.source_code = 'WHO'
17
- subject.save
18
- }
19
- its(:status){ should be 200 }
20
- its(:source_code){ should eq 'WHO' }
21
- end
22
-
23
- end
24
-
25
- context "normal user" do
26
- # behave as a user
27
- before(:all){ Quandl::Client.token = ENV['QUANDL_TEST_TOKEN'] }
28
-
29
- its(:saved?){ should be_true }
30
- its(:source_code){ should be_present }
31
-
32
- it "should find the source" do
33
- Source.find(dataset.source_code).exists?.should be_true
34
- end
35
-
36
- describe "#source_code=" do
37
- before(:each){
38
- subject.source_code = 'WHO'
39
- subject.save
40
- }
41
- its(:status){ should be 422 }
42
- end
43
-
44
- after(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
45
- end
46
-
47
- end
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+
6
+ let(:dataset){ create(:dataset, source_code: nil ) }
7
+ subject{ dataset }
8
+
9
+ context "admin user" do
10
+
11
+ its(:saved?){ should be_true }
12
+ its(:source_code){ should be_present }
13
+
14
+ describe "#source_code=" do
15
+ before(:each){
16
+ subject.source_code = 'WHO'
17
+ subject.save
18
+ }
19
+ its(:status){ should be 200 }
20
+ its(:source_code){ should eq 'WHO' }
21
+ end
22
+
23
+ end
24
+
25
+ context "normal user" do
26
+ # behave as a user
27
+ before(:all){ Quandl::Client.token = ENV['QUANDL_TEST_TOKEN'] }
28
+
29
+ its(:saved?){ should be_true }
30
+ its(:source_code){ should be_present }
31
+
32
+ it "should find the source" do
33
+ Source.find(dataset.source_code).exists?.should be_true
34
+ end
35
+
36
+ describe "#source_code=" do
37
+ before(:each){
38
+ subject.source_code = 'WHO'
39
+ subject.save
40
+ }
41
+ its(:status){ should be 422 }
42
+ end
43
+
44
+ after(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
45
+ end
46
+
47
+ end