datacatalog 0.4.13 → 0.4.14

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "datacatalog"
8
- gem.version = '0.4.13'
8
+ gem.version = '0.4.14'
9
9
  gem.rubyforge_project = "datacatalog"
10
10
  gem.summary = %Q{Client for the National Data Catalog API}
11
11
  gem.description = %Q{A Ruby client library for the National Data Catalog API}
data/datacatalog.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{datacatalog}
8
- s.version = "0.4.13"
8
+ s.version = "0.4.14"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Luigi Montanez", "David James"]
12
- s.date = %q{2010-04-13}
12
+ s.date = %q{2010-04-28}
13
13
  s.description = %q{A Ruby client library for the National Data Catalog API}
14
14
  s.email = %q{luigi@sunlightfoundation.com}
15
15
  s.extra_rdoc_files = [
@@ -33,6 +33,8 @@ Gem::Specification.new do |s|
33
33
  "lib/resources/document.rb",
34
34
  "lib/resources/download.rb",
35
35
  "lib/resources/favorite.rb",
36
+ "lib/resources/importers.rb",
37
+ "lib/resources/imports.rb",
36
38
  "lib/resources/note.rb",
37
39
  "lib/resources/organization.rb",
38
40
  "lib/resources/rating.rb",
@@ -48,6 +50,8 @@ Gem::Specification.new do |s|
48
50
  "spec/document_spec.rb",
49
51
  "spec/download_spec.rb",
50
52
  "spec/favorite_spec.rb",
53
+ "spec/import_spec.rb",
54
+ "spec/importer_spec.rb",
51
55
  "spec/note_spec.rb",
52
56
  "spec/organization_spec.rb",
53
57
  "spec/rating_spec.rb",
@@ -76,6 +80,8 @@ Gem::Specification.new do |s|
76
80
  "spec/document_spec.rb",
77
81
  "spec/download_spec.rb",
78
82
  "spec/favorite_spec.rb",
83
+ "spec/import_spec.rb",
84
+ "spec/importer_spec.rb",
79
85
  "spec/note_spec.rb",
80
86
  "spec/organization_spec.rb",
81
87
  "spec/rating_spec.rb",
@@ -0,0 +1,33 @@
1
+ module DataCatalog
2
+
3
+ class Importer < Base
4
+
5
+ def self.all(conditions={})
6
+ cursor(uri, query_hash(conditions))
7
+ end
8
+
9
+ def self.get(id)
10
+ one(http_get(uri(id)))
11
+ end
12
+
13
+ def self.create(params={})
14
+ one(http_post(uri, :body => params))
15
+ end
16
+
17
+ def self.update(id, params={})
18
+ one(http_put(uri(id), :body => params))
19
+ end
20
+
21
+ def self.destroy(id)
22
+ one(http_delete(uri(id)))
23
+ end
24
+
25
+ # == Helpers
26
+
27
+ def self.uri(id=nil)
28
+ "/importers/#{id}"
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,33 @@
1
+ module DataCatalog
2
+
3
+ class Import < Base
4
+
5
+ def self.all(conditions={})
6
+ cursor(uri, query_hash(conditions))
7
+ end
8
+
9
+ def self.get(id)
10
+ one(http_get(uri(id)))
11
+ end
12
+
13
+ def self.create(params={})
14
+ one(http_post(uri, :body => params))
15
+ end
16
+
17
+ def self.update(id, params={})
18
+ one(http_put(uri(id), :body => params))
19
+ end
20
+
21
+ def self.destroy(id)
22
+ one(http_delete(uri(id)))
23
+ end
24
+
25
+ # == Helpers
26
+
27
+ def self.uri(id=nil)
28
+ "/imports/#{id}"
29
+ end
30
+
31
+ end
32
+
33
+ end
data/spec/comment_spec.rb CHANGED
@@ -8,17 +8,14 @@ describe Comment do
8
8
  clean_slate
9
9
  @user = User.create(
10
10
  :name => "Ted Smith",
11
- :email => "ted@email.com"
12
- )
11
+ :email => "ted@email.com")
13
12
  @source = Source.create(
14
13
  :title => "Some FCC Data",
15
14
  :url => "http://fcc.gov/somedata.csv",
16
- :source_type => "dataset"
17
- )
15
+ :source_type => "dataset")
18
16
  end
19
17
 
20
18
  describe ".create" do
21
-
22
19
  it "should create a new comment when valid params are passed in" do
23
20
  DataCatalog.with_key(@user.primary_api_key) do
24
21
  @comment = Comment.create(:source_id => @source.id, :text => "The first comment.")
@@ -29,11 +26,9 @@ describe Comment do
29
26
  refreshed_source.comments.first.text.should == "The first comment."
30
27
  refreshed_source.comments.first.user.name.should == "Ted Smith"
31
28
  end
32
-
33
- end # describe ".create"
29
+ end
34
30
 
35
31
  describe ".get" do
36
-
37
32
  before do
38
33
  DataCatalog.with_key(@user.primary_api_key) do
39
34
  @comment = Comment.create(:source_id => @source.id, :text => "The first comment.")
@@ -51,18 +46,17 @@ describe Comment do
51
46
  Comment.get(mangle(@comment.id))
52
47
  end.should raise_error(NotFound)
53
48
  end
54
-
55
- end # describe ".get"
49
+ end
56
50
 
57
51
  describe ".all" do
58
-
59
52
  before do
60
- @john = User.create(:name => "John Smith",
61
- :email => "john@email.com")
62
- @data = Source.create(:title => "Some FEC Data",
63
- :url => "http://fec.gov/somedata.csv",
64
- :source_type => "dataset")
65
-
53
+ @john = User.create(
54
+ :name => "John Smith",
55
+ :email => "john@email.com")
56
+ @data = Source.create(
57
+ :title => "Some FEC Data",
58
+ :url => "http://fec.gov/somedata.csv",
59
+ :source_type => "dataset")
66
60
  DataCatalog.with_key(@john.primary_api_key) do
67
61
  Comment.create(:source_id => @data.id, :text => "The first comment.")
68
62
  Comment.create(:source_id => @data.id, :text => "The second comment.")
@@ -76,11 +70,9 @@ describe Comment do
76
70
  comments[i].text.should == "The #{nth} comment."
77
71
  end
78
72
  end
79
-
80
- end # describe ".all"
73
+ end
81
74
 
82
75
  describe ".update" do
83
-
84
76
  before do
85
77
  DataCatalog.with_key(@user.primary_api_key) do
86
78
  @comment = Comment.create(:source_id => @source.id, :text => "The first comment.")
@@ -96,11 +88,9 @@ describe Comment do
96
88
  refreshed_source.comments.first.text.should == "The first comment, updated."
97
89
  refreshed_source.comments.first.user.name.should == "Ted Smith"
98
90
  end
99
-
100
- end # describe ".update"
91
+ end
101
92
 
102
93
  describe ".destroy" do
103
-
104
94
  before do
105
95
  DataCatalog.with_key(@user.primary_api_key) do
106
96
  @comment = Comment.create(:source_id => @source.id, :text => "The first comment.")
@@ -122,7 +112,6 @@ describe Comment do
122
112
  Comment.destroy(mangle(@comment.id))
123
113
  end.should raise_error(NotFound)
124
114
  end
125
-
126
- end # describe ".destroy"
115
+ end
127
116
 
128
- end
117
+ end
@@ -24,16 +24,13 @@ describe Download do
24
24
  end
25
25
 
26
26
  describe ".create" do
27
-
28
27
  it "should create a download when valid params are passed in" do
29
28
  refreshed_source = Source.get(@source.id)
30
29
  refreshed_source.downloads.first.url.should == "http://somedata.gov/test.csv"
31
30
  end
32
-
33
- end # describe ".create"
31
+ end
34
32
 
35
33
  describe ".get" do
36
-
37
34
  it "should return a download" do
38
35
  download = Download.get(@download.id)
39
36
  download.should be_an_instance_of(Download)
@@ -45,32 +42,26 @@ describe Download do
45
42
  Download.get(mangle(@download.id))
46
43
  end.should raise_error(NotFound)
47
44
  end
48
-
49
- end # describe ".get"
45
+ end
50
46
 
51
47
  describe ".all" do
52
-
53
48
  it "should return an enumeration of downloads" do
54
49
  downloads = Download.all(:source_id => @source.id)
55
50
  downloads.each do |o|
56
51
  o.should be_an_instance_of(Download)
57
52
  end
58
53
  end
59
-
60
- end # describe ".all"
54
+ end
61
55
 
62
56
  describe ".update" do
63
-
64
57
  it "should update an existing download with valid params" do
65
58
  Download.update(@download.id, :preview => "10,11,12,13")
66
59
  refreshed_download = Download.get(@download.id)
67
60
  refreshed_download.preview.should == "10,11,12,13"
68
61
  end
69
-
70
- end # describe ".update"
62
+ end
71
63
 
72
64
  describe ".destroy" do
73
-
74
65
  it "should destroy an existing download as an admin" do
75
66
  Download.destroy(@download.id).should be_true
76
67
  end
@@ -80,7 +71,6 @@ describe Download do
80
71
  Download.destroy(mangle(@download.id))
81
72
  end.should raise_error(NotFound)
82
73
  end
83
-
84
- end # describe ".destroy"
74
+ end
85
75
 
86
- end
76
+ end
@@ -0,0 +1,119 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include DataCatalog
3
+
4
+ describe Import do
5
+
6
+ before do
7
+ setup_api
8
+ clean_slate
9
+ @user = User.create(
10
+ :name => "Ted Smith",
11
+ :email => "ted@email.com"
12
+ )
13
+ @importer = Importer.create(
14
+ :name => "National Data Registry of Bats")
15
+ timestamp = Time.now
16
+ @imports = [
17
+ Import.create({
18
+ :importer_id => @importer.id,
19
+ :status => 'success',
20
+ :started_at => timestamp - 3645,
21
+ :finished_at => timestamp - 3600,
22
+ }),
23
+ Import.create({
24
+ :importer_id => @importer.id,
25
+ :status => 'success',
26
+ :started_at => timestamp - 45,
27
+ :finished_at => timestamp,
28
+ }),
29
+ ]
30
+ end
31
+
32
+ describe ".get" do
33
+ it "should return an import as a basic user" do
34
+ import = DataCatalog.with_key(@user.primary_api_key) do
35
+ Import.get(@imports[0].id)
36
+ end
37
+ import.should be_an_instance_of(Import)
38
+ import.id.should == @imports[0].id
39
+ end
40
+
41
+ it "should raise NotFound if no import exists" do
42
+ executing do
43
+ Import.get(mangle(@imports[0].id))
44
+ end.should raise_error(NotFound)
45
+ end
46
+ end
47
+
48
+ describe ".create" do
49
+ # (successful create is exercised in before block)
50
+
51
+ it "a basic user should be unauthorized" do
52
+ executing do
53
+ DataCatalog.with_key(@user.primary_api_key) do
54
+ Import.create(:name => "Idaho Data Catalog")
55
+ end
56
+ end.should raise_error(Unauthorized)
57
+ end
58
+
59
+ it "should fail with invalid params" do
60
+ executing do
61
+ Import.create(:cave => "The Batcave")
62
+ end.should raise_error(BadRequest)
63
+ end
64
+
65
+ it "should fail when missing params" do
66
+ executing do
67
+ Import.create()
68
+ end.should raise_error(BadRequest)
69
+ end
70
+ end
71
+
72
+ describe ".all" do
73
+ it "should return an enumeration of 2 imports" do
74
+ imports = Import.all
75
+ imports.length.should == 2
76
+ imports.each do |o|
77
+ o.should be_an_instance_of(Import)
78
+ end
79
+ end
80
+ end
81
+
82
+ describe ".update" do
83
+ it "a basic user should be unauthorized" do
84
+ executing do
85
+ DataCatalog.with_key(@user.primary_api_key) do
86
+ Import.update(@imports[0].id, :status => 'failure')
87
+ end
88
+ end.should raise_error(Unauthorized)
89
+ end
90
+
91
+ it "should update an existing import with valid params" do
92
+ @imports[0].status.should == 'success'
93
+ Import.update(@imports[0].id, :status => 'failure')
94
+ import = Import.get(@imports[0].id)
95
+ import.status.should == 'failure'
96
+ end
97
+ end
98
+
99
+ describe ".destroy" do
100
+ it "should destroy an existing import as an admin" do
101
+ Import.destroy(@imports[0].id).should be_true
102
+ end
103
+
104
+ it "should not destroy an existing import as a basic user" do
105
+ DataCatalog.with_key(@user.primary_api_key) do
106
+ executing do
107
+ Import.destroy(@imports[0].id)
108
+ end.should raise_error(Unauthorized)
109
+ end
110
+ end
111
+
112
+ it "should raise NotFound when attempting to destroy non-existing import" do
113
+ executing do
114
+ Import.destroy(mangle(@imports[0].id))
115
+ end.should raise_error(NotFound)
116
+ end
117
+ end
118
+
119
+ end
@@ -0,0 +1,106 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include DataCatalog
3
+
4
+ describe Importer do
5
+
6
+ before do
7
+ setup_api
8
+ clean_slate
9
+ @user = User.create(
10
+ :name => "Ted Smith",
11
+ :email => "ted@email.com"
12
+ )
13
+ @importers = [
14
+ Importer.create(:name => "National Data Registry of Bats"),
15
+ Importer.create(:name => "Bat-Inspired Superheroes"),
16
+ ]
17
+ end
18
+
19
+ describe ".get" do
20
+ it "should return an importer as a basic user" do
21
+ importer = DataCatalog.with_key(@user.primary_api_key) do
22
+ Importer.get(@importers[0].id)
23
+ end
24
+ importer.should be_an_instance_of(Importer)
25
+ importer.id.should == @importers[0].id
26
+ end
27
+
28
+ it "should raise NotFound if no importer exists" do
29
+ executing do
30
+ Importer.get(mangle(@importers[0].id))
31
+ end.should raise_error(NotFound)
32
+ end
33
+ end
34
+
35
+ describe ".create" do
36
+ # (successful create is exercised in before block)
37
+
38
+ it "a basic user should be unauthorized" do
39
+ executing do
40
+ DataCatalog.with_key(@user.primary_api_key) do
41
+ Importer.create(:name => "Idaho Data Catalog")
42
+ end
43
+ end.should raise_error(Unauthorized)
44
+ end
45
+
46
+ it "should fail with invalid params" do
47
+ executing do
48
+ Importer.create(:cave => "The Batcave")
49
+ end.should raise_error(BadRequest)
50
+ end
51
+
52
+ it "should fail when missing params" do
53
+ executing do
54
+ Importer.create()
55
+ end.should raise_error(BadRequest)
56
+ end
57
+ end
58
+
59
+ describe ".all" do
60
+ it "should return an enumeration of 2 importers" do
61
+ importers = Importer.all
62
+ importers.length.should == 2
63
+ importers.each do |o|
64
+ o.should be_an_instance_of(Importer)
65
+ end
66
+ end
67
+ end
68
+
69
+ describe ".update" do
70
+ it "a basic user should be unauthorized" do
71
+ executing do
72
+ DataCatalog.with_key(@user.primary_api_key) do
73
+ Importer.update(@importers[0].id, :name => "International Bat Registry")
74
+ end
75
+ end.should raise_error(Unauthorized)
76
+ end
77
+
78
+ it "should update an existing importer with valid params" do
79
+ @importers[0].name.should == "National Data Registry of Bats"
80
+ Importer.update(@importers[0].id, :name => "International Bat Registry")
81
+ importer = Importer.get(@importers[0].id)
82
+ importer.name.should == "International Bat Registry"
83
+ end
84
+ end
85
+
86
+ describe ".destroy" do
87
+ it "should destroy an existing importer as an admin" do
88
+ Importer.destroy(@importers[0].id).should be_true
89
+ end
90
+
91
+ it "should not destroy an existing importer as a basic user" do
92
+ DataCatalog.with_key(@user.primary_api_key) do
93
+ executing do
94
+ Importer.destroy(@importers[0].id)
95
+ end.should raise_error(Unauthorized)
96
+ end
97
+ end
98
+
99
+ it "should raise NotFound when attempting to destroy non-existing importer" do
100
+ executing do
101
+ Importer.destroy(mangle(@importers[0].id))
102
+ end.should raise_error(NotFound)
103
+ end
104
+ end
105
+
106
+ end
data/spec/spec_helper.rb CHANGED
@@ -9,7 +9,9 @@ alias :executing :lambda
9
9
 
10
10
  KLASSES = [
11
11
  DataCatalog::Source,
12
- DataCatalog::Organization
12
+ DataCatalog::Organization,
13
+ DataCatalog::Importer,
14
+ DataCatalog::Import,
13
15
  ]
14
16
 
15
17
  def clean_slate
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 13
9
- version: 0.4.13
8
+ - 14
9
+ version: 0.4.14
10
10
  platform: ruby
11
11
  authors:
12
12
  - Luigi Montanez
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-13 00:00:00 -04:00
18
+ date: 2010-04-28 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -128,6 +128,8 @@ files:
128
128
  - lib/resources/document.rb
129
129
  - lib/resources/download.rb
130
130
  - lib/resources/favorite.rb
131
+ - lib/resources/importers.rb
132
+ - lib/resources/imports.rb
131
133
  - lib/resources/note.rb
132
134
  - lib/resources/organization.rb
133
135
  - lib/resources/rating.rb
@@ -143,6 +145,8 @@ files:
143
145
  - spec/document_spec.rb
144
146
  - spec/download_spec.rb
145
147
  - spec/favorite_spec.rb
148
+ - spec/import_spec.rb
149
+ - spec/importer_spec.rb
146
150
  - spec/note_spec.rb
147
151
  - spec/organization_spec.rb
148
152
  - spec/rating_spec.rb
@@ -194,6 +198,8 @@ test_files:
194
198
  - spec/document_spec.rb
195
199
  - spec/download_spec.rb
196
200
  - spec/favorite_spec.rb
201
+ - spec/import_spec.rb
202
+ - spec/importer_spec.rb
197
203
  - spec/note_spec.rb
198
204
  - spec/organization_spec.rb
199
205
  - spec/rating_spec.rb