quandl_client 2.7.3 → 2.7.4

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 -6
  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 +35 -35
  10. data/UPGRADE.md +210 -207
  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 +245 -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 +40 -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 +5 -27
@@ -1,36 +1,36 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Dataset do
5
-
6
- subject{ build(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand(rows: 20, columns: 2) ) }
7
-
8
- describe "#from_date" do
9
- context "before_save" do
10
- it "should be nil" do
11
- subject.from_date.should be_nil
12
- end
13
- end
14
- context "after_save" do
15
- before(:each){ subject.save }
16
- it "should equal the last date" do
17
- subject.from_date.should eq subject.data.to_date[-1][0].to_s
18
- end
19
- end
20
- end
21
-
22
- describe "#to_date" do
23
- context "before_save" do
24
- it "should be nil" do
25
- subject.to_date.should be_nil
26
- end
27
- end
28
- context "after_save" do
29
- before(:each){ subject.save }
30
- it "should equal the first date" do
31
- subject.to_date.should eq subject.data.to_date[0][0].to_s
32
- end
33
- end
34
- end
35
-
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+
6
+ subject{ build(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data.rand(rows: 20, columns: 2) ) }
7
+
8
+ describe "#from_date" do
9
+ context "before_save" do
10
+ it "should be nil" do
11
+ subject.from_date.should be_nil
12
+ end
13
+ end
14
+ context "after_save" do
15
+ before(:each){ subject.save }
16
+ it "should equal the last date" do
17
+ subject.from_date.should eq subject.data.to_date[-1][0].to_s
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "#to_date" do
23
+ context "before_save" do
24
+ it "should be nil" do
25
+ subject.to_date.should be_nil
26
+ end
27
+ end
28
+ context "after_save" do
29
+ before(:each){ subject.save }
30
+ it "should equal the first date" do
31
+ subject.to_date.should eq subject.data.to_date[0][0].to_s
32
+ end
33
+ end
34
+ end
35
+
36
36
  end
@@ -1,69 +1,69 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Dataset do
5
-
6
- let(:dataset){ build(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
7
- subject{ dataset }
8
-
9
- context "data='1980,10,20\nASDF,10,30'" do
10
- before(:each){
11
- dataset.data = '1980,10,20\nASDF,10,30'
12
- dataset.valid?
13
- }
14
- its(:valid?){ should be_false }
15
- its('errors.messages'){ should eq({ data: ["Invalid date 'ASDF'"] }) }
16
- end
17
-
18
- context "given ambiguous code" do
19
- before(:each){
20
- dataset.source_code = nil
21
- dataset.code = '12345'
22
- dataset.valid?
23
- }
24
- its(:valid?){ should be_false }
25
- its('errors.messages'){ should eq({ data: ["Pure numerical codes like \"12345\" are not allowed unless you include a source code. Do this:\nsource_code: <USERNAME>\ncode: 12345"]}) }
26
- end
27
-
28
- context "mismatch row count" do
29
- before(:each){
30
- dataset.data = [[2012, 1,2],[2011, 1,2,3]]
31
- dataset.valid?
32
- }
33
- its(:valid?){ should be_false }
34
- its('errors.messages'){ should eq({ data:
35
- ["Unexpected number of points in this row:\n2011-12-31,1.0,2.0,3.0\nFound 3 but expected 2 based on precedent from the first row (2012-12-31,1.0,2.0)"]
36
- })}
37
- end
38
-
39
- context "mismatch column_names count" do
40
- before(:each){
41
- dataset.column_names = ['Date','Value']
42
- dataset.data = [[2012, 18,21],[2011, 1,2]]
43
- dataset.valid?
44
- }
45
- its(:valid?){ should be_false }
46
- its('errors.messages'){ should eq({ data:
47
- ["Unexpected number of points in this row:\n2012-12-31,18.0,21.0\nFound 2 but expected 1 based on precedent from the header row (Date,Value)"]
48
- })}
49
- end
50
-
51
- describe "#code" do
52
-
53
- before(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
54
-
55
- let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
56
- let(:invalid_dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", code: dataset.code ) }
57
- subject{ invalid_dataset }
58
-
59
- it "should create the dataset" do
60
- dataset.status.should eq 201
61
- end
62
-
63
- its(:saved?){ should be_false }
64
- its(:status){ should eq 422 }
65
-
66
- end
67
-
68
-
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+
6
+ let(:dataset){ build(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
7
+ subject{ dataset }
8
+
9
+ context "data='1980,10,20\nASDF,10,30'" do
10
+ before(:each){
11
+ dataset.data = '1980,10,20\nASDF,10,30'
12
+ dataset.valid?
13
+ }
14
+ its(:valid?){ should be_false }
15
+ its('errors.messages'){ should eq({ data: ["Invalid date 'ASDF'"] }) }
16
+ end
17
+
18
+ context "given ambiguous code" do
19
+ before(:each){
20
+ dataset.source_code = nil
21
+ dataset.code = '12345'
22
+ dataset.valid?
23
+ }
24
+ its(:valid?){ should be_false }
25
+ its('errors.messages'){ should eq({ data: ["Pure numerical codes like \"12345\" are not allowed unless you include a source code. Do this:\nsource_code: <USERNAME>\ncode: 12345"]}) }
26
+ end
27
+
28
+ context "mismatch row count" do
29
+ before(:each){
30
+ dataset.data = [[2012, 1,2],[2011, 1,2,3]]
31
+ dataset.valid?
32
+ }
33
+ its(:valid?){ should be_false }
34
+ its('errors.messages'){ should eq({ data:
35
+ ["Unexpected number of points in this row:\n2011-12-31,1.0,2.0,3.0\nFound 3 but expected 2 based on precedent from the first row (2012-12-31,1.0,2.0)"]
36
+ })}
37
+ end
38
+
39
+ context "mismatch column_names count" do
40
+ before(:each){
41
+ dataset.column_names = ['Date','Value']
42
+ dataset.data = [[2012, 18,21],[2011, 1,2]]
43
+ dataset.valid?
44
+ }
45
+ its(:valid?){ should be_false }
46
+ its('errors.messages'){ should eq({ data:
47
+ ["Unexpected number of points in this row:\n2012-12-31,18.0,21.0\nFound 2 but expected 1 based on precedent from the header row (Date,Value)"]
48
+ })}
49
+ end
50
+
51
+ describe "#code" do
52
+
53
+ before(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
54
+
55
+ let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
56
+ let(:invalid_dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", code: dataset.code ) }
57
+ subject{ invalid_dataset }
58
+
59
+ it "should create the dataset" do
60
+ dataset.status.should eq 201
61
+ end
62
+
63
+ its(:saved?){ should be_false }
64
+ its(:status){ should eq 422 }
65
+
66
+ end
67
+
68
+
69
69
  end
@@ -1,58 +1,58 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Dataset do
5
- let(:dataset){ create(:dataset) }
6
- subject{ dataset }
7
-
8
- describe ".find" do
9
- subject{ Dataset.find(query) }
10
- context "given nil" do
11
- let(:query){ nil }
12
- it{ should be_nil }
13
- end
14
- context "given empty string" do
15
- let(:query){ '' }
16
- it{ should be_nil }
17
- end
18
- context "given non-code value" do
19
- let(:query){ '/' }
20
- it{ should be_nil }
21
- end
22
- end
23
-
24
- describe ".touch_existing(:id)" do
25
- it "should touch the dataset" do
26
- dataset.updated_at
27
- sleep(1)
28
- Dataset.touch_existing(subject.id).should eq true
29
- Dataset.find(subject.id).updated_at.should_not eq dataset.updated_at
30
- end
31
- end
32
-
33
- it "should change url" do
34
- original_url = Quandl::Client::Base.url
35
- Quandl::Client.use('http://url.com/')
36
- Quandl::Client::Dataset.url.should eq 'http://url.com/v2'
37
- Quandl::Client.use('http://url.com/2/')
38
- Quandl::Client::Dataset.url.should eq 'http://url.com/2/v2'
39
- Quandl::Client.use original_url
40
- end
41
-
42
- describe ".query" do
43
- let(:datasets){ Quandl::Client::Dataset.query('oil').all }
44
- subject{ datasets }
45
-
46
- its(:first){ should be_a Quandl::Client::Dataset }
47
-
48
- describe "#metadata" do
49
- subject{ OpenStruct.new(datasets.metadata) }
50
- its(:total_count){ should > 1 }
51
- its(:per_page){ should eq 20 }
52
- its(:sources){ should be_present }
53
- its(:status){ should eq 200 }
54
- its(:current_page){ should eq 1 }
55
- end
56
- end
57
-
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+ let(:dataset){ create(:dataset) }
6
+ subject{ dataset }
7
+
8
+ describe ".find" do
9
+ subject{ Dataset.find(query) }
10
+ context "given nil" do
11
+ let(:query){ nil }
12
+ it{ should be_nil }
13
+ end
14
+ context "given empty string" do
15
+ let(:query){ '' }
16
+ it{ should be_nil }
17
+ end
18
+ context "given non-code value" do
19
+ let(:query){ '/' }
20
+ it{ should be_nil }
21
+ end
22
+ end
23
+
24
+ describe ".touch_existing(:id)" do
25
+ it "should touch the dataset" do
26
+ dataset.updated_at
27
+ sleep(1)
28
+ Dataset.touch_existing(subject.id).should eq true
29
+ Dataset.find(subject.id).updated_at.should_not eq dataset.updated_at
30
+ end
31
+ end
32
+
33
+ it "should change url" do
34
+ original_url = Quandl::Client::Base.url
35
+ Quandl::Client.use('http://url.com/')
36
+ Quandl::Client::Dataset.url.should eq 'http://url.com/v2'
37
+ Quandl::Client.use('http://url.com/2/')
38
+ Quandl::Client::Dataset.url.should eq 'http://url.com/2/v2'
39
+ Quandl::Client.use original_url
40
+ end
41
+
42
+ describe ".query" do
43
+ let(:datasets){ Quandl::Client::Dataset.query('oil').all }
44
+ subject{ datasets }
45
+
46
+ its(:first){ should be_a Quandl::Client::Dataset }
47
+
48
+ describe "#metadata" do
49
+ subject{ OpenStruct.new(datasets.metadata) }
50
+ its(:total_count){ should > 1 }
51
+ its(:per_page){ should eq 20 }
52
+ its(:sources){ should be_present }
53
+ its(:status){ should eq 200 }
54
+ its(:current_page){ should eq 1 }
55
+ end
56
+ end
57
+
58
58
  end
@@ -1,72 +1,72 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Scraper do
5
-
6
- let(:scraper){ Scraper.new }
7
- subject{ scraper }
8
-
9
- its(:valid?){ should be_false }
10
-
11
- context "name='file'" do
12
- before(:each){ scraper.name = "file-#{uuid}.rb" }
13
-
14
- its(:save){ should be_false }
15
-
16
- context "save" do
17
- before(:each){ scraper.save }
18
- its("error_messages.to_s"){ should match "You must provide one of" }
19
- its("error_messages.to_s"){ should match "scraper_url, git_url" }
20
- end
21
-
22
- context "scraper= File" do
23
- before(:each){
24
- scraper.scraper = "spec/fixtures/scraper.rb"
25
- scraper.save
26
- }
27
- its(:valid?){ should be_true }
28
- its(:saved?){ should be_true }
29
- its(:id){ should be_present }
30
- its(:scraper_url){ should match /s3/}
31
- its(:git_url){ should be_blank }
32
- its(:type){ should eq 'Scraper::Script' }
33
- end
34
-
35
- context "scraper_url='https://github.com/tammer/scrapers/blob/master/shibor.rb'" do
36
- before(:each){
37
- scraper.scraper_url = "https://github.com/tammer/scrapers/blob/master/shibor.rb"
38
- scraper.save
39
- }
40
- its(:valid?){ should be_true }
41
- its(:saved?){ should be_true }
42
- its(:id){ should be_present }
43
- its(:scraper_url){ should match /s3/}
44
- its(:git_url){ should be_blank }
45
- its(:type){ should eq 'Scraper::Script' }
46
- end
47
-
48
- context "git_url='git@github.com:tammer/scrapers.git'" do
49
- before(:each){
50
- scraper.git_url = "git@github.com:tammer/scrapers.git"
51
- scraper.save
52
- }
53
- its("error_messages.to_s"){ should match %Q{can't be blank} }
54
- end
55
-
56
- context "git_url='git@github.com:tammer/scrapers.git' & git_reference='master'" do
57
- before(:each){
58
- subject.git_url = "git@github.com:tammer/scrapers-#{uuid}.git"
59
- subject.git_reference = "master"
60
- subject.save
61
- }
62
- its(:valid?){ should be_true }
63
- its(:saved?){ should be_true }
64
- its(:id){ should be_present }
65
- its(:scraper_url){ should be_blank }
66
- its(:git_url){ should match /git@github.com:tammer\/scrapers/ }
67
- its(:type){ should eq 'Scraper::Git' }
68
- end
69
-
70
- end
71
-
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Scraper do
5
+
6
+ let(:scraper){ Scraper.new }
7
+ subject{ scraper }
8
+
9
+ its(:valid?){ should be_false }
10
+
11
+ context "name='file'" do
12
+ before(:each){ scraper.name = "file-#{uuid}.rb" }
13
+
14
+ its(:save){ should be_false }
15
+
16
+ context "save" do
17
+ before(:each){ scraper.save }
18
+ its("error_messages.to_s"){ should match "You must provide one of" }
19
+ its("error_messages.to_s"){ should match "scraper_url, git_url" }
20
+ end
21
+
22
+ context "scraper= File" do
23
+ before(:each){
24
+ scraper.scraper = "spec/fixtures/scraper.rb"
25
+ scraper.save
26
+ }
27
+ its(:valid?){ should be_true }
28
+ its(:saved?){ should be_true }
29
+ its(:id){ should be_present }
30
+ its(:scraper_url){ should match /s3/}
31
+ its(:git_url){ should be_blank }
32
+ its(:type){ should eq 'Scraper::Script' }
33
+ end
34
+
35
+ context "scraper_url='https://github.com/tammer/scrapers/blob/master/shibor.rb'" do
36
+ before(:each){
37
+ scraper.scraper_url = "https://github.com/tammer/scrapers/blob/master/shibor.rb"
38
+ scraper.save
39
+ }
40
+ its(:valid?){ should be_true }
41
+ its(:saved?){ should be_true }
42
+ its(:id){ should be_present }
43
+ its(:scraper_url){ should match /s3/}
44
+ its(:git_url){ should be_blank }
45
+ its(:type){ should eq 'Scraper::Script' }
46
+ end
47
+
48
+ context "git_url='git@github.com:tammer/scrapers.git'" do
49
+ before(:each){
50
+ scraper.git_url = "git@github.com:tammer/scrapers.git"
51
+ scraper.save
52
+ }
53
+ its("error_messages.to_s"){ should match %Q{can't be blank} }
54
+ end
55
+
56
+ context "git_url='git@github.com:tammer/scrapers.git' & git_reference='master'" do
57
+ before(:each){
58
+ subject.git_url = "git@github.com:tammer/scrapers-#{uuid}.git"
59
+ subject.git_reference = "master"
60
+ subject.save
61
+ }
62
+ its(:valid?){ should be_true }
63
+ its(:saved?){ should be_true }
64
+ its(:id){ should be_present }
65
+ its(:scraper_url){ should be_blank }
66
+ its(:git_url){ should match /git@github.com:tammer\/scrapers/ }
67
+ its(:type){ should eq 'Scraper::Git' }
68
+ end
69
+
70
+ end
71
+
72
72
  end