quandl_client 0.1.16 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -95,7 +95,7 @@ d = Dataset.create( attributes )
95
95
 
96
96
  d = Dataset.find( d.full_code )
97
97
  d.name = 'New Name'
98
- d.data = Quandl::Data::Random.table.to_csv
98
+ d.data = Quandl::Fabricate::Data::Table.rand.to_csv
99
99
  d.save
100
100
 
101
101
  d = Dataset.collapse(:weekly).find( d.full_code )
data/UPGRADE.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.17
2
+
3
+ * Dataset#source_code is optional
4
+
5
+
1
6
  ## 0.1.16
2
7
 
3
8
  * add sheet description
@@ -35,8 +35,7 @@ class Dataset
35
35
  ###############
36
36
  # VALIDATIONS #
37
37
  ###############
38
-
39
- validates :source_code, presence: true
38
+
40
39
  validates :code, presence: true, format: { with: /[A-Z0-9_]+/ }
41
40
  validates :name, presence: true, :length => { :maximum => 1000 }
42
41
 
@@ -49,7 +48,7 @@ class Dataset
49
48
  :description, :updated_at, :frequency,
50
49
  :from_date, :to_date, :column_names, :private, :type,
51
50
  :display_url, :column_spec, :import_spec, :import_url,
52
- :locations_attributes, :data, :availability_delay
51
+ :locations_attributes, :data, :availability_delay, :refreshed_at
53
52
 
54
53
  before_save :enforce_required_formats
55
54
 
@@ -1,6 +1,6 @@
1
1
  module Quandl
2
2
  module Client
3
- VERSION = '0.1.16'
3
+ VERSION = '0.1.17'
4
4
  API_VERSION = 'v1'
5
5
 
6
6
  class << self
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+
6
+ let(:source){
7
+ s = Source.find("QUANDL_CLIENT_TEST_SOURCE")
8
+ s = create(:source, code: "QUANDL_CLIENT_TEST_SOURCE") unless s.exists?
9
+ s
10
+ }
11
+ subject{ create(:dataset, source_code: source.code, private: true ) }
12
+
13
+ describe "#private" do
14
+
15
+ it "should update to false" do
16
+ subject.private = false
17
+ subject.save
18
+ Dataset.find(subject.id).private.should be_false
19
+ end
20
+
21
+ it "should update to true" do
22
+ subject.private = false
23
+ subject.save
24
+ subject.private = true
25
+ subject.save
26
+ Dataset.find(subject.id).private.should be_true
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dataset do
5
+
6
+ let(:dataset){
7
+ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data::Table.rand( rows: 10, columns: 4 ) )
8
+ }
9
+
10
+ describe "#data" do
11
+ subject{ Dataset.find( dataset.id ).data }
12
+ its(:count){ should eq 10 }
13
+ end
14
+
15
+ context "updated" do
16
+
17
+ subject{
18
+ sleep(0.75)
19
+ Dataset.find( dataset.id )
20
+ }
21
+
22
+ describe "#data" do
23
+ before(:each){ subject.data = Quandl::Fabricate::Data::Table.rand( rows: 12, columns: 4 ); subject.save }
24
+ its(:updated_at){ should_not eq dataset.updated_at }
25
+ its(:data){ should_not eq dataset.data }
26
+ its(:refreshed_at){ should_not eq dataset.refreshed_at }
27
+ end
28
+
29
+ context "#column_spec" do
30
+ before(:each){ subject.column_spec = "[0,[\"Date \\n\",{}],[\"Column 1 \",{}],[\"New Column Name \",{}]]"; subject.save }
31
+ its(:updated_at){ should_not eq dataset.updated_at }
32
+ its(:column_spec){ should_not eq dataset.column_spec }
33
+ end
34
+
35
+ end
36
+
37
+
38
+ end
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
  describe Dataset do
5
5
 
6
6
  subject{
7
- build(:dataset, source_code: create(:source).code )
7
+ build(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" )
8
8
  }
9
9
 
10
10
  describe "#availability_delay" do
@@ -46,8 +46,8 @@ describe Dataset do
46
46
  context "datasets sharing location" do
47
47
 
48
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 ) }
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
51
 
52
52
  it "should share the location" do
53
53
  Dataset.find(dataset1.id).locations.should eq Dataset.find(dataset2.id).locations
@@ -0,0 +1,93 @@
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
+ context "when created" do
12
+ context "without token" do
13
+ before(:all){ Quandl::Client.token = '' }
14
+
15
+ let(:dataset){ create(:dataset) }
16
+ subject{ dataset }
17
+
18
+ its(:saved?){ should be_false }
19
+ its(:status){ should eq 401 }
20
+
21
+ after(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
22
+ end
23
+ context "with token" do
24
+
25
+ let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
26
+ subject{ dataset }
27
+
28
+ its(:saved?){ should be_true }
29
+ its(:status){ should eq 201 }
30
+
31
+ end
32
+ context "with data" do
33
+
34
+ let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data::Table.rand(rows: 20, columns: 2, nils: false) ) }
35
+ subject{ dataset }
36
+
37
+ its(:saved?){ should be_true }
38
+ its(:status){ should eq 201 }
39
+
40
+ end
41
+ end
42
+
43
+ context "when updated" do
44
+
45
+ let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data::Table.rand(rows: 20, columns: 2, nils: false).to_csv ) }
46
+ subject{ Dataset.find(dataset.id) }
47
+
48
+ it "should include new row" do
49
+ new_data = 10.times.collect{|i| [Date.parse(subject.to_date) + i + 1, rand(12), rand(12) ] }
50
+ new_data = Quandl::Data::Table.new(new_data).sort_descending
51
+ subject.data = new_data
52
+ subject.save
53
+ updated_dataset = Dataset.find(subject.id)
54
+ updated_dataset.data_table.to_date[0].should eq new_data.to_date[0]
55
+ end
56
+
57
+ it "should include old rows" do
58
+ new_data = 10.times.collect{|i| [Date.parse(subject.to_date) + i + 2, rand(12), rand(12) ] }
59
+ new_data = Quandl::Data::Table.new(new_data).sort_descending
60
+ subject.data = new_data
61
+ subject.save
62
+ updated_dataset = Dataset.find(subject.id)
63
+ updated_dataset.data_table.count.should eq 30
64
+ end
65
+
66
+ end
67
+
68
+ context "when deleted" do
69
+
70
+ let(:dataset){ create(:dataset, private: false ) }
71
+
72
+ it "should delete the dataset" do
73
+ dataset.destroy
74
+ dataset.status.should eq 200
75
+ end
76
+
77
+ context "as a user" do
78
+
79
+ it "should not delete the dataset with a user token" do
80
+ id = dataset.id
81
+ # behave as a user
82
+ Quandl::Client.token = ENV['QUANDL_USER_TOKEN']
83
+ user_dataset = Dataset.find(id)
84
+ user_dataset.destroy
85
+ user_dataset.status.should eq 403
86
+ end
87
+
88
+ after(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
89
+
90
+ end
91
+ end
92
+
93
+ end
@@ -2,9 +2,8 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Dataset do
5
-
6
- let(:source){ create(:source) }
7
- let(:dataset){ create(:dataset, source_code: source.code ) }
5
+
6
+ let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
8
7
 
9
8
  it "should find the dataset by id" do
10
9
  Dataset.find(dataset.id).id.should eq dataset.id
@@ -0,0 +1,46 @@
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
+ its(:saved?){ should be_true }
11
+ its(:source_code){ should be_present }
12
+
13
+ describe "#source_code=" do
14
+ before(:each){
15
+ subject.source_code = 'WHO'
16
+ subject.save
17
+ }
18
+ its(:status){ should be 200 }
19
+ its(:source_code){ should eq 'WHO' }
20
+ end
21
+
22
+ end
23
+
24
+ context "normal user" do
25
+ # behave as a user
26
+ before(:all){ Quandl::Client.token = ENV['QUANDL_USER_TOKEN'] }
27
+
28
+ its(:saved?){ should be_true }
29
+ its(:source_code){ should be_present }
30
+
31
+ it "should find the source" do
32
+ Source.find(dataset.source_code).exists?.should be_true
33
+ end
34
+
35
+ describe "#source_code=" do
36
+ before(:each){
37
+ subject.source_code = 'WHO'
38
+ subject.save
39
+ }
40
+ its(:status){ should be 422 }
41
+ end
42
+
43
+ after(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
44
+ end
45
+
46
+ end
@@ -3,8 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  describe Dataset do
5
5
 
6
- let(:source){ create(:source) }
7
- subject{ build(:dataset, source_code: source.code, data: Quandl::Data::Random.table(rows: 20, columns: 2) ) }
6
+ subject{ build(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", data: Quandl::Fabricate::Data::Table.rand(rows: 20, columns: 2) ) }
8
7
 
9
8
  describe "#from_date" do
10
9
  context "before_save" do
@@ -7,9 +7,8 @@ describe Dataset do
7
7
 
8
8
  before(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
9
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 ) }
10
+ let(:dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE" ) }
11
+ let(:invalid_dataset){ create(:dataset, source_code: "QUANDL_CLIENT_TEST_SOURCE", code: dataset.code ) }
13
12
  subject{ invalid_dataset }
14
13
 
15
14
  it "should create the dataset" do
@@ -14,6 +14,7 @@ describe Sheet do
14
14
  context "when saved" do
15
15
 
16
16
  before(:each){ subject.save }
17
+
17
18
  its(:saved?){ should be_true }
18
19
 
19
20
  describe "#description" do
@@ -44,7 +44,6 @@ describe Source do
44
44
 
45
45
  end
46
46
 
47
-
48
47
  end
49
48
 
50
49
 
data/spec/spec_helper.rb CHANGED
@@ -8,10 +8,12 @@ factory_dir = File.join( File.dirname(__FILE__), 'factories/**/*.rb' )
8
8
  Dir.glob( factory_dir ).each{|f| require(f); puts f }
9
9
 
10
10
  require "quandl/client"
11
+ require "quandl/fabricate"
11
12
 
12
13
  include Quandl::Client
13
14
  Quandl::Client.use 'http://localhost:3000/api/'
14
15
  # Quandl::Client.use 'http://staging.quandl.com/api/'
16
+ # Quandl::Client.use 'http://quandl.com/api/'
15
17
  Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN']
16
18
 
17
19
  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.16
4
+ version: 0.1.17
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-09-09 00:00:00.000000000 Z
12
+ date: 2013-09-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -253,13 +253,16 @@ files:
253
253
  - spec/factories/dataset.rb
254
254
  - spec/factories/sheet.rb
255
255
  - spec/factories/source.rb
256
- - spec/quandl/client/dataset/location_spec.rb
257
- - spec/quandl/client/dataset/persistence_spec.rb
258
- - spec/quandl/client/dataset/search_spec.rb
259
- - spec/quandl/client/dataset/trim_spec.rb
260
- - spec/quandl/client/dataset/validation_spec.rb
261
- - spec/quandl/client/sheet_spec.rb
262
- - spec/quandl/client/source_spec.rb
256
+ - spec/lib/quandl/client/dataset/attributes_spec.rb
257
+ - spec/lib/quandl/client/dataset/data_spec.rb
258
+ - spec/lib/quandl/client/dataset/location_spec.rb
259
+ - spec/lib/quandl/client/dataset/persistence_spec.rb
260
+ - spec/lib/quandl/client/dataset/search_spec.rb
261
+ - spec/lib/quandl/client/dataset/source_spec.rb
262
+ - spec/lib/quandl/client/dataset/trim_spec.rb
263
+ - spec/lib/quandl/client/dataset/validation_spec.rb
264
+ - spec/lib/quandl/client/sheet_spec.rb
265
+ - spec/lib/quandl/client/source_spec.rb
263
266
  - spec/spec_helper.rb
264
267
  homepage: http://blake.hilscher.ca/
265
268
  licenses:
@@ -290,11 +293,14 @@ test_files:
290
293
  - spec/factories/dataset.rb
291
294
  - spec/factories/sheet.rb
292
295
  - spec/factories/source.rb
293
- - spec/quandl/client/dataset/location_spec.rb
294
- - spec/quandl/client/dataset/persistence_spec.rb
295
- - spec/quandl/client/dataset/search_spec.rb
296
- - spec/quandl/client/dataset/trim_spec.rb
297
- - spec/quandl/client/dataset/validation_spec.rb
298
- - spec/quandl/client/sheet_spec.rb
299
- - spec/quandl/client/source_spec.rb
296
+ - spec/lib/quandl/client/dataset/attributes_spec.rb
297
+ - spec/lib/quandl/client/dataset/data_spec.rb
298
+ - spec/lib/quandl/client/dataset/location_spec.rb
299
+ - spec/lib/quandl/client/dataset/persistence_spec.rb
300
+ - spec/lib/quandl/client/dataset/search_spec.rb
301
+ - spec/lib/quandl/client/dataset/source_spec.rb
302
+ - spec/lib/quandl/client/dataset/trim_spec.rb
303
+ - spec/lib/quandl/client/dataset/validation_spec.rb
304
+ - spec/lib/quandl/client/sheet_spec.rb
305
+ - spec/lib/quandl/client/source_spec.rb
300
306
  - spec/spec_helper.rb
@@ -1,94 +0,0 @@
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
- context "when created" do
12
- context "without token" do
13
-
14
- before(:all){ Quandl::Client.token = '' }
15
-
16
- let(:dataset){ create(:dataset) }
17
- subject{ dataset }
18
-
19
- its(:saved?){ should be_false }
20
- its(:status){ should eq 401 }
21
-
22
- end
23
- context "with token" do
24
-
25
- before(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
26
-
27
- let(:source){ create(:source) }
28
- let(:dataset){ create(:dataset, source_code: source.code ) }
29
- subject{ dataset }
30
-
31
- its(:saved?){ should be_true }
32
- its(:status){ should eq 201 }
33
-
34
- end
35
- context "with data" do
36
-
37
- before(:all){ Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN'] }
38
-
39
- let(:source){ create(:source) }
40
- let(:dataset){ create(:dataset, source_code: source.code, data: Quandl::Data::Random.table(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(:source){ create(:source) }
52
- let(:dataset){ create(:dataset, source_code: source.code, data: Quandl::Data::Random.table(rows: 20, columns: 2, nils: false).to_csv ) }
53
- subject{ Dataset.find(dataset.id) }
54
-
55
-
56
- it "should update data" do
57
- # update the dataset
58
- new_row = [ subject.data_table[0][0], 1.0, 2.0]
59
- subject.data = [ new_row ]
60
- subject.save
61
- # check the data
62
- Dataset.find(dataset.id).data_table.sort_descending[0].should eq new_row
63
- end
64
-
65
- it "should update column_spec" do
66
- subject.column_spec = "[0,[\"Date \\n\",{}],[\"Column 1 \",{}],[\"New Column Name \",{}]]"
67
- subject.save
68
- Dataset.find(dataset.id).column_spec.should eq subject.column_spec
69
- end
70
-
71
- context "with new rows" do
72
-
73
- it "should include new row" do
74
- new_data = 10.times.collect{|i| [Date.parse(subject.to_date) + i + 1, rand(12), rand(12) ] }
75
- new_data = Quandl::Data::Table.new(new_data).sort_descending
76
- subject.data = new_data
77
- subject.save
78
- updated_dataset = Dataset.find(subject.id)
79
- updated_dataset.data_table.to_date[0].should eq new_data.to_date[0]
80
- end
81
-
82
- it "should include old rows" do
83
- new_data = 10.times.collect{|i| [Date.parse(subject.to_date) + i + 2, rand(12), rand(12) ] }
84
- new_data = Quandl::Data::Table.new(new_data).sort_descending
85
- subject.data = new_data
86
- subject.save
87
- updated_dataset = Dataset.find(subject.id)
88
- updated_dataset.data_table.count.should eq 30
89
- end
90
- end
91
-
92
- end
93
-
94
- end