datacatalog 0.4.18 → 0.4.19
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/Rakefile +1 -1
- data/datacatalog.gemspec +7 -1
- data/lib/resources/categorization.rb +33 -0
- data/lib/resources/category.rb +33 -0
- data/lib/resources/document.rb +8 -8
- data/lib/resources/download.rb +8 -8
- data/lib/resources/note.rb +8 -8
- data/spec/categorization_spec.rb +129 -0
- data/spec/category_spec.rb +106 -0
- data/spec/spec_helper.rb +2 -0
- metadata +9 -3
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ begin
|
|
4
4
|
require 'jeweler'
|
5
5
|
Jeweler::Tasks.new do |gem|
|
6
6
|
gem.name = "datacatalog"
|
7
|
-
gem.version = '0.4.
|
7
|
+
gem.version = '0.4.19'
|
8
8
|
gem.summary = %Q{Client for the National Data Catalog API}
|
9
9
|
gem.description = %Q{A Ruby client library for the National Data Catalog API}
|
10
10
|
gem.email = "luigi@sunlightfoundation.com"
|
data/datacatalog.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{datacatalog}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.19"
|
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"]
|
@@ -33,6 +33,8 @@ Gem::Specification.new do |s|
|
|
33
33
|
"lib/resources/about.rb",
|
34
34
|
"lib/resources/api_key.rb",
|
35
35
|
"lib/resources/broken_link.rb",
|
36
|
+
"lib/resources/categorization.rb",
|
37
|
+
"lib/resources/category.rb",
|
36
38
|
"lib/resources/comment.rb",
|
37
39
|
"lib/resources/document.rb",
|
38
40
|
"lib/resources/download.rb",
|
@@ -50,6 +52,8 @@ Gem::Specification.new do |s|
|
|
50
52
|
"spec/api_key_spec.rb",
|
51
53
|
"spec/base_spec.rb",
|
52
54
|
"spec/broken_link_spec.rb",
|
55
|
+
"spec/categorization_spec.rb",
|
56
|
+
"spec/category_spec.rb",
|
53
57
|
"spec/comment_spec.rb",
|
54
58
|
"spec/datacatalog_spec.rb",
|
55
59
|
"spec/document_spec.rb",
|
@@ -81,6 +85,8 @@ Gem::Specification.new do |s|
|
|
81
85
|
"spec/api_key_spec.rb",
|
82
86
|
"spec/base_spec.rb",
|
83
87
|
"spec/broken_link_spec.rb",
|
88
|
+
"spec/categorization_spec.rb",
|
89
|
+
"spec/category_spec.rb",
|
84
90
|
"spec/comment_spec.rb",
|
85
91
|
"spec/datacatalog_spec.rb",
|
86
92
|
"spec/document_spec.rb",
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module DataCatalog
|
2
|
+
|
3
|
+
class Categorization < Base
|
4
|
+
|
5
|
+
def self.all(conditions={})
|
6
|
+
cursor(uri, query_hash(conditions))
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.create(params={})
|
10
|
+
one(http_post(uri, :body => params))
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.destroy(id)
|
14
|
+
one(http_delete(uri(id)))
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get(id)
|
18
|
+
one(http_get(uri(id)))
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.update(id, params={})
|
22
|
+
one(http_put(uri(id), :body => params))
|
23
|
+
end
|
24
|
+
|
25
|
+
# == Helpers
|
26
|
+
|
27
|
+
def self.uri(id=nil)
|
28
|
+
"/categorizations/#{id}"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module DataCatalog
|
2
|
+
|
3
|
+
class Category < Base
|
4
|
+
|
5
|
+
def self.all(conditions={})
|
6
|
+
cursor(uri, query_hash(conditions))
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.create(params={})
|
10
|
+
one(http_post(uri, :body => params))
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.destroy(id)
|
14
|
+
one(http_delete(uri(id)))
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get(id)
|
18
|
+
one(http_get(uri(id)))
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.update(id, params={})
|
22
|
+
one(http_put(uri(id), :body => params))
|
23
|
+
end
|
24
|
+
|
25
|
+
# == Helpers
|
26
|
+
|
27
|
+
def self.uri(id=nil)
|
28
|
+
"/categories/#{id}"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/resources/document.rb
CHANGED
@@ -6,22 +6,22 @@ module DataCatalog
|
|
6
6
|
cursor(uri, query_hash(conditions))
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.get(id)
|
10
|
-
one(http_get(uri(id)))
|
11
|
-
end
|
12
|
-
|
13
9
|
def self.create(params={})
|
14
10
|
one(http_post(uri, :body => params))
|
15
11
|
end
|
16
12
|
|
17
|
-
def self.update(id, params={})
|
18
|
-
one(http_put(uri(id), :body => params))
|
19
|
-
end
|
20
|
-
|
21
13
|
def self.destroy(id)
|
22
14
|
one(http_delete(uri(id)))
|
23
15
|
end
|
24
16
|
|
17
|
+
def self.get(id)
|
18
|
+
one(http_get(uri(id)))
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.update(id, params={})
|
22
|
+
one(http_put(uri(id), :body => params))
|
23
|
+
end
|
24
|
+
|
25
25
|
# == Helpers
|
26
26
|
|
27
27
|
def self.uri(id=nil)
|
data/lib/resources/download.rb
CHANGED
@@ -6,22 +6,22 @@ module DataCatalog
|
|
6
6
|
cursor(uri, query_hash(conditions))
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.get(id)
|
10
|
-
one(http_get(uri(id)))
|
11
|
-
end
|
12
|
-
|
13
9
|
def self.create(params={})
|
14
10
|
one(http_post(uri, :body => params))
|
15
11
|
end
|
16
12
|
|
17
|
-
def self.update(id, params={})
|
18
|
-
one(http_put(uri(id), :body => params))
|
19
|
-
end
|
20
|
-
|
21
13
|
def self.destroy(id)
|
22
14
|
one(http_delete(uri(id)))
|
23
15
|
end
|
24
16
|
|
17
|
+
def self.get(id)
|
18
|
+
one(http_get(uri(id)))
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.update(id, params={})
|
22
|
+
one(http_put(uri(id), :body => params))
|
23
|
+
end
|
24
|
+
|
25
25
|
# == Helpers
|
26
26
|
|
27
27
|
def self.uri(id=nil)
|
data/lib/resources/note.rb
CHANGED
@@ -6,22 +6,22 @@ module DataCatalog
|
|
6
6
|
cursor(uri, query_hash(conditions))
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.get(id)
|
10
|
-
one(http_get(uri(id)))
|
11
|
-
end
|
12
|
-
|
13
9
|
def self.create(params={})
|
14
10
|
one(http_post(uri, :body => params))
|
15
11
|
end
|
16
12
|
|
17
|
-
def self.update(id, params={})
|
18
|
-
one(http_put(uri(id), :body => params))
|
19
|
-
end
|
20
|
-
|
21
13
|
def self.destroy(id)
|
22
14
|
one(http_delete(uri(id)))
|
23
15
|
end
|
24
16
|
|
17
|
+
def self.get(id)
|
18
|
+
one(http_get(uri(id)))
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.update(id, params={})
|
22
|
+
one(http_put(uri(id), :body => params))
|
23
|
+
end
|
24
|
+
|
25
25
|
# == Helpers
|
26
26
|
|
27
27
|
def self.uri(id=nil)
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
include DataCatalog
|
3
|
+
|
4
|
+
describe Categorization 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
|
+
@sources = [
|
14
|
+
Source.create(
|
15
|
+
:title => "Some Bat Data",
|
16
|
+
:url => "http://bats.doi.gov/bat_data.csv",
|
17
|
+
:source_type => "dataset"
|
18
|
+
),
|
19
|
+
Source.create(
|
20
|
+
:title => "Bat Flying Simulation",
|
21
|
+
:url => "http://bats.doi.gov/bat-sim",
|
22
|
+
:source_type => "interactive"
|
23
|
+
),
|
24
|
+
]
|
25
|
+
@category = Category.create(:name => "Bat Policy")
|
26
|
+
@categorizations = [
|
27
|
+
Categorization.create({
|
28
|
+
:source_id => @sources[0].id,
|
29
|
+
:category_id => @category.id
|
30
|
+
}),
|
31
|
+
Categorization.create({
|
32
|
+
:source_id => @sources[1].id,
|
33
|
+
:category_id => @category.id
|
34
|
+
})
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
describe ".all" do
|
39
|
+
it "should return an enumeration of 2 categorizations" do
|
40
|
+
categorizations = Categorization.all
|
41
|
+
categorizations.length.should == 2
|
42
|
+
categorizations.each do |o|
|
43
|
+
o.should be_an_instance_of(Categorization)
|
44
|
+
end
|
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
|
+
Categorization.create(
|
55
|
+
:source_id => @sources[0].id,
|
56
|
+
:category_id => @category.id
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end.should raise_error(Unauthorized)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should fail with invalid params" do
|
63
|
+
executing do
|
64
|
+
Categorization.create(:cave => "The Batcave")
|
65
|
+
end.should raise_error(BadRequest)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should fail when missing params" do
|
69
|
+
executing do
|
70
|
+
Categorization.create()
|
71
|
+
end.should raise_error(BadRequest)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe ".destroy" do
|
76
|
+
it "should destroy an existing categorization as an admin" do
|
77
|
+
Categorization.destroy(@categorizations[0].id).should be_true
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should not destroy an existing categorization as a basic user" do
|
81
|
+
DataCatalog.with_key(@user.primary_api_key) do
|
82
|
+
executing do
|
83
|
+
Categorization.destroy(@categorizations[0].id)
|
84
|
+
end.should raise_error(Unauthorized)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should raise NotFound when attempting to destroy non-existing categorization" do
|
89
|
+
executing do
|
90
|
+
Categorization.destroy(mangle(@categorizations[0].id))
|
91
|
+
end.should raise_error(NotFound)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe ".get" do
|
96
|
+
it "should return an categorization as a basic user" do
|
97
|
+
categorization = DataCatalog.with_key(@user.primary_api_key) do
|
98
|
+
Categorization.get(@categorizations[0].id)
|
99
|
+
end
|
100
|
+
categorization.should be_an_instance_of(Categorization)
|
101
|
+
categorization.id.should == @categorizations[0].id
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should raise NotFound if no categorization exists" do
|
105
|
+
executing do
|
106
|
+
Categorization.get(mangle(@categorizations[0].id))
|
107
|
+
end.should raise_error(NotFound)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe ".update" do
|
112
|
+
it "a basic user should be unauthorized" do
|
113
|
+
executing do
|
114
|
+
DataCatalog.with_key(@user.primary_api_key) do
|
115
|
+
Categorization.update(@categorizations[0].id, :name => "International Bat Registry")
|
116
|
+
end
|
117
|
+
end.should raise_error(Unauthorized)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should update an existing categorization with valid params" do
|
121
|
+
@categorizations[0].category_id.should == @category.id
|
122
|
+
new_category = Category.create(:name => "Wombat Policy")
|
123
|
+
Categorization.update(@categorizations[0].id, :category_id => new_category.id)
|
124
|
+
categorization = Categorization.get(@categorizations[0].id)
|
125
|
+
categorization.category_id == new_category.id
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
include DataCatalog
|
3
|
+
|
4
|
+
describe Category 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
|
+
@categories = [
|
14
|
+
Category.create(:name => "Bat Policy"),
|
15
|
+
Category.create(:name => "Bear Policy"),
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".all" do
|
20
|
+
it "should return an enumeration of 2 categories" do
|
21
|
+
categories = Category.all
|
22
|
+
categories.length.should == 2
|
23
|
+
categories.each do |o|
|
24
|
+
o.should be_an_instance_of(Category)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe ".create" do
|
30
|
+
# (successful create is exercised in before block)
|
31
|
+
|
32
|
+
it "a basic user should be unauthorized" do
|
33
|
+
executing do
|
34
|
+
DataCatalog.with_key(@user.primary_api_key) do
|
35
|
+
Category.create(:name => "Wombat Policy")
|
36
|
+
end
|
37
|
+
end.should raise_error(Unauthorized)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should fail with invalid params" do
|
41
|
+
executing do
|
42
|
+
Category.create(:cave => "The Batcave")
|
43
|
+
end.should raise_error(BadRequest)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should fail when missing params" do
|
47
|
+
executing do
|
48
|
+
Category.create()
|
49
|
+
end.should raise_error(BadRequest)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe ".destroy" do
|
54
|
+
it "should destroy an existing category as an admin" do
|
55
|
+
Category.destroy(@categories[0].id).should be_true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should not destroy an existing category as a basic user" do
|
59
|
+
DataCatalog.with_key(@user.primary_api_key) do
|
60
|
+
executing do
|
61
|
+
Category.destroy(@categories[0].id)
|
62
|
+
end.should raise_error(Unauthorized)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should raise NotFound when attempting to destroy non-existing category" do
|
67
|
+
executing do
|
68
|
+
Category.destroy(mangle(@categories[0].id))
|
69
|
+
end.should raise_error(NotFound)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe ".get" do
|
74
|
+
it "should return an category as a basic user" do
|
75
|
+
category = DataCatalog.with_key(@user.primary_api_key) do
|
76
|
+
Category.get(@categories[0].id)
|
77
|
+
end
|
78
|
+
category.should be_an_instance_of(Category)
|
79
|
+
category.id.should == @categories[0].id
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should raise NotFound if no category exists" do
|
83
|
+
executing do
|
84
|
+
Category.get(mangle(@categories[0].id))
|
85
|
+
end.should raise_error(NotFound)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe ".update" do
|
90
|
+
it "a basic user should be unauthorized" do
|
91
|
+
executing do
|
92
|
+
DataCatalog.with_key(@user.primary_api_key) do
|
93
|
+
Category.update(@categories[0].id, :name => "International Bat Policy")
|
94
|
+
end
|
95
|
+
end.should raise_error(Unauthorized)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should update an existing category with valid params" do
|
99
|
+
@categories[0].name.should == "Bat Policy"
|
100
|
+
Category.update(@categories[0].id, :name => "International Bat Policy")
|
101
|
+
category = Category.get(@categories[0].id)
|
102
|
+
category.name.should == "International Bat Policy"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datacatalog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 41
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 19
|
10
|
+
version: 0.4.19
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Luigi Montanez
|
@@ -173,6 +173,8 @@ files:
|
|
173
173
|
- lib/resources/about.rb
|
174
174
|
- lib/resources/api_key.rb
|
175
175
|
- lib/resources/broken_link.rb
|
176
|
+
- lib/resources/categorization.rb
|
177
|
+
- lib/resources/category.rb
|
176
178
|
- lib/resources/comment.rb
|
177
179
|
- lib/resources/document.rb
|
178
180
|
- lib/resources/download.rb
|
@@ -190,6 +192,8 @@ files:
|
|
190
192
|
- spec/api_key_spec.rb
|
191
193
|
- spec/base_spec.rb
|
192
194
|
- spec/broken_link_spec.rb
|
195
|
+
- spec/categorization_spec.rb
|
196
|
+
- spec/category_spec.rb
|
193
197
|
- spec/comment_spec.rb
|
194
198
|
- spec/datacatalog_spec.rb
|
195
199
|
- spec/document_spec.rb
|
@@ -249,6 +253,8 @@ test_files:
|
|
249
253
|
- spec/api_key_spec.rb
|
250
254
|
- spec/base_spec.rb
|
251
255
|
- spec/broken_link_spec.rb
|
256
|
+
- spec/categorization_spec.rb
|
257
|
+
- spec/category_spec.rb
|
252
258
|
- spec/comment_spec.rb
|
253
259
|
- spec/datacatalog_spec.rb
|
254
260
|
- spec/document_spec.rb
|