datacatalog 0.4.15 → 0.4.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/Rakefile +6 -6
- data/datacatalog.gemspec +20 -17
- data/lib/base.rb +8 -8
- data/lib/cursor.rb +16 -12
- data/lib/main.rb +8 -8
- data/lib/resources/about.rb +4 -4
- data/lib/resources/api_key.rb +5 -5
- data/lib/resources/broken_link.rb +33 -0
- data/lib/resources/comment.rb +4 -4
- data/lib/resources/document.rb +2 -2
- data/lib/resources/download.rb +2 -2
- data/lib/resources/favorite.rb +3 -3
- data/lib/resources/import.rb +2 -2
- data/lib/resources/importer.rb +2 -2
- data/lib/resources/note.rb +2 -2
- data/lib/resources/organization.rb +1 -1
- data/lib/resources/rating.rb +4 -4
- data/lib/resources/report.rb +4 -4
- data/lib/resources/source.rb +2 -2
- data/lib/resources/user.rb +9 -9
- data/spec/about_spec.rb +5 -5
- data/spec/api_key_spec.rb +12 -12
- data/spec/base_spec.rb +16 -16
- data/spec/comment_spec.rb +9 -9
- data/spec/datacatalog_spec.rb +2 -2
- data/spec/document_spec.rb +18 -18
- data/spec/download_spec.rb +10 -10
- data/spec/empty_spec.rb +61 -0
- data/spec/favorite_spec.rb +14 -14
- data/spec/import_spec.rb +5 -5
- data/spec/importer_spec.rb +5 -5
- data/spec/note_spec.rb +16 -16
- data/spec/organization_spec.rb +20 -20
- data/spec/rating_spec.rb +20 -20
- data/spec/report_spec.rb +11 -11
- data/spec/source_spec.rb +26 -26
- data/spec/spec_helper.rb +10 -3
- data/spec/user_spec.rb +23 -23
- data/tasks/test_api.rake +3 -3
- metadata +20 -17
data/lib/resources/download.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module DataCatalog
|
2
2
|
|
3
3
|
class Download < Base
|
4
|
-
|
4
|
+
|
5
5
|
def self.all(conditions={})
|
6
6
|
cursor(uri, query_hash(conditions))
|
7
7
|
end
|
@@ -23,7 +23,7 @@ module DataCatalog
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# == Helpers
|
26
|
-
|
26
|
+
|
27
27
|
def self.uri(id=nil)
|
28
28
|
"/downloads/#{id}"
|
29
29
|
end
|
data/lib/resources/favorite.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module DataCatalog
|
2
2
|
|
3
3
|
class Favorite < Base
|
4
|
-
|
4
|
+
|
5
5
|
def self.all(conditions={})
|
6
6
|
cursor(uri, query_hash(conditions))
|
7
7
|
end
|
@@ -13,13 +13,13 @@ module DataCatalog
|
|
13
13
|
def self.destroy(id)
|
14
14
|
one(http_delete(uri(id)))
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def self.get(id)
|
18
18
|
one(http_get(uri(id)))
|
19
19
|
end
|
20
20
|
|
21
21
|
# == Helpers
|
22
|
-
|
22
|
+
|
23
23
|
def self.uri(id=nil)
|
24
24
|
"/favorites/#{id}"
|
25
25
|
end
|
data/lib/resources/import.rb
CHANGED
data/lib/resources/importer.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module DataCatalog
|
2
2
|
|
3
3
|
class Importer < Base
|
4
|
-
|
4
|
+
|
5
5
|
def self.all(conditions={})
|
6
6
|
cursor(uri, query_hash(conditions))
|
7
7
|
end
|
@@ -27,7 +27,7 @@ module DataCatalog
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# == Helpers
|
30
|
-
|
30
|
+
|
31
31
|
def self.uri(id=nil)
|
32
32
|
"/importers/#{id}"
|
33
33
|
end
|
data/lib/resources/note.rb
CHANGED
data/lib/resources/rating.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module DataCatalog
|
2
2
|
|
3
3
|
class Rating < Base
|
4
|
-
|
4
|
+
|
5
5
|
def self.all(conditions={})
|
6
6
|
cursor(uri, query_hash(conditions))
|
7
7
|
end
|
@@ -13,17 +13,17 @@ module DataCatalog
|
|
13
13
|
def self.destroy(id)
|
14
14
|
one(http_delete(uri(id)))
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def self.get(id)
|
18
18
|
one(http_get(uri(id)))
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def self.update(id, params={})
|
22
22
|
one(http_put(uri(id), :body => params))
|
23
23
|
end
|
24
24
|
|
25
25
|
# == Helpers
|
26
|
-
|
26
|
+
|
27
27
|
def self.uri(id=nil)
|
28
28
|
"/ratings/#{id}"
|
29
29
|
end
|
data/lib/resources/report.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module DataCatalog
|
2
2
|
|
3
3
|
class Report < Base
|
4
|
-
|
4
|
+
|
5
5
|
def self.all(conditions={})
|
6
6
|
cursor(uri, query_hash(conditions))
|
7
7
|
end
|
@@ -13,17 +13,17 @@ module DataCatalog
|
|
13
13
|
def self.destroy(id)
|
14
14
|
one(http_delete(uri(id)))
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def self.get(id)
|
18
18
|
one(http_get(uri(id)))
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def self.update(id, params={})
|
22
22
|
one(http_put(uri(id), :body => params))
|
23
23
|
end
|
24
24
|
|
25
25
|
# == Helpers
|
26
|
-
|
26
|
+
|
27
27
|
def self.uri(id=nil)
|
28
28
|
"/reports/#{id}"
|
29
29
|
end
|
data/lib/resources/source.rb
CHANGED
data/lib/resources/user.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module DataCatalog
|
2
2
|
|
3
3
|
class User < Base
|
4
|
-
|
4
|
+
|
5
5
|
def self.all(conditions={})
|
6
6
|
cursor(uri, query_hash(conditions))
|
7
7
|
end
|
@@ -17,7 +17,7 @@ module DataCatalog
|
|
17
17
|
def self.first(conditions={})
|
18
18
|
_first(http_get(uri, :query => query_hash(conditions)))
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def self.get(id)
|
22
22
|
with_api_keys(one(http_get(uri(id))))
|
23
23
|
end
|
@@ -29,22 +29,22 @@ module DataCatalog
|
|
29
29
|
get(checkup.user.id)
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def self.update(id, params)
|
34
34
|
one(http_put(uri(id), :body => params))
|
35
35
|
end
|
36
36
|
|
37
37
|
# == Helpers
|
38
|
-
|
38
|
+
|
39
39
|
def self.with_api_keys(user)
|
40
40
|
user.api_keys = ApiKey.all(user.id) if user
|
41
41
|
user
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def self.uri(id=nil)
|
45
45
|
"/users/#{id}"
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
# == Instance Methods
|
49
49
|
|
50
50
|
def delete_api_key!(api_key_id)
|
@@ -61,9 +61,9 @@ module DataCatalog
|
|
61
61
|
ApiKey.update(self.id, api_key_id, params)
|
62
62
|
update_api_keys
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
protected
|
66
|
-
|
66
|
+
|
67
67
|
def update_api_keys
|
68
68
|
self.api_keys = ApiKey.all(self.id)
|
69
69
|
user = User.get(id)
|
@@ -71,7 +71,7 @@ module DataCatalog
|
|
71
71
|
self.valet_api_keys = user.valet_api_keys
|
72
72
|
true
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
end
|
76
76
|
|
77
77
|
end
|
data/spec/about_spec.rb
CHANGED
@@ -17,26 +17,26 @@ describe DataCatalog do
|
|
17
17
|
}
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
describe ".version_at_least?" do
|
22
|
-
|
22
|
+
|
23
23
|
it "should return false if below the actual version" do
|
24
24
|
version_mock = mock(Object.new).version { '1.0.0' }
|
25
25
|
mock(About).get { version_mock }
|
26
26
|
About.version_at_least?('1.1.1').should be false
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it "should return true if at the actual version" do
|
30
30
|
version_mock = mock(Object.new).version { '1.0.0' }
|
31
31
|
mock(About).get { version_mock }
|
32
32
|
About.version_at_least?('1.0.0').should be true
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
it "should return true if above the actual version" do
|
36
36
|
version_mock = mock(Object.new).version { '1.0.0' }
|
37
37
|
mock(About).get { version_mock }
|
38
38
|
About.version_at_least?('0.9.9').should be true
|
39
|
-
end
|
39
|
+
end
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
data/spec/api_key_spec.rb
CHANGED
@@ -8,7 +8,7 @@ module ApiKeyHelpers
|
|
8
8
|
:email => "ted@email.com"
|
9
9
|
})
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def create_user_with_2_keys
|
13
13
|
user = create_user
|
14
14
|
ApiKey.create(user.id, {
|
@@ -32,13 +32,13 @@ describe ApiKey do
|
|
32
32
|
@user = create_user_with_2_keys
|
33
33
|
@api_keys = ApiKey.all(@user.id)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "should return an enumeration of API keys" do
|
37
37
|
@api_keys.each do |api_key|
|
38
38
|
api_key.should be_an_instance_of(ApiKey)
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
it "should return correct titles" do
|
43
43
|
@api_keys.map(&:key_type).should == %w(primary application)
|
44
44
|
end
|
@@ -49,13 +49,13 @@ describe ApiKey do
|
|
49
49
|
@user = create_user_with_2_keys
|
50
50
|
@api_keys = ApiKey.all(@user.id, :key_type => "application")
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
it "should return an enumeration of API keys" do
|
54
54
|
@api_keys.each do |api_key|
|
55
55
|
api_key.should be_an_instance_of(ApiKey)
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
it "should return correct titles" do
|
60
60
|
@api_keys.map(&:key_type).should == %w(application)
|
61
61
|
end
|
@@ -77,13 +77,13 @@ describe ApiKey do
|
|
77
77
|
before do
|
78
78
|
@user = create_user_with_2_keys
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it "should return an API key" do
|
82
82
|
api_key = ApiKey.first(@user.id, :purpose => "Civic hacking")
|
83
83
|
api_key.should be_an_instance_of(ApiKey)
|
84
84
|
api_key.purpose.should == "Civic hacking"
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
it "should return nil if nothing found" do
|
88
88
|
api_key = ApiKey.first(@user.id, :purpose => "Evil")
|
89
89
|
api_key.should be_nil
|
@@ -95,13 +95,13 @@ describe ApiKey do
|
|
95
95
|
@user = create_user_with_2_keys
|
96
96
|
@api_key = @user.api_keys[1]
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
it "should return an API key" do
|
100
100
|
api_key = ApiKey.get(@user.id, @api_key.id)
|
101
101
|
api_key.should be_an_instance_of(ApiKey)
|
102
102
|
api_key.purpose.should == "Civic hacking"
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
it "should raise NotFound if no API key exists" do
|
106
106
|
executing do
|
107
107
|
ApiKey.get(@user.id, mangle(@api_key.id))
|
@@ -114,7 +114,7 @@ describe ApiKey do
|
|
114
114
|
@user = create_user_with_2_keys
|
115
115
|
@api_key = @user.api_keys[1]
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
it "should update an existing source from valid params" do
|
119
119
|
api_key = ApiKey.update(@user.id, @api_key.id, {
|
120
120
|
:purpose => "Local Government Reporting"
|
@@ -129,12 +129,12 @@ describe ApiKey do
|
|
129
129
|
@user = create_user_with_2_keys
|
130
130
|
@api_key = @user.api_keys[1]
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
it "should destroy an existing source" do
|
134
134
|
result = ApiKey.destroy(@user.id, @api_key.id)
|
135
135
|
result.should be_true
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
it "should raise NotFound if API key does not exist" do
|
139
139
|
executing do
|
140
140
|
ApiKey.destroy(@user.id, mangle(@api_key.id))
|
data/spec/base_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe Base do
|
|
13
13
|
DataCatalog.base_uri = 'host.com'
|
14
14
|
DataCatalog.base_uri.should == 'http://host.com'
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "should set the base URI to the default if it's not explicitly defined" do
|
18
18
|
DataCatalog.base_uri = ''
|
19
19
|
DataCatalog.base_uri.should == 'http://api.nationaldatacatalog.com'
|
@@ -26,28 +26,28 @@ describe Base do
|
|
26
26
|
response = HTTParty::Response.new(nil, '{"foo":"bar"}', 200, 'OK', {})
|
27
27
|
Base.check_status(response).should be_nil
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "should raise BadRequest on 400 Bad Request" do
|
31
31
|
response = HTTParty::Response.new(nil, '[]', 400, 'Bad Request', {})
|
32
32
|
executing do
|
33
33
|
Base.check_status(response)
|
34
34
|
end.should raise_error(BadRequest)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it "should raise Unauthorized on 401 Unauthorized" do
|
38
38
|
response = HTTParty::Response.new(nil, '', 401, 'Unauthorized', {})
|
39
39
|
executing do
|
40
40
|
Base.check_status(response)
|
41
41
|
end.should raise_error(Unauthorized)
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
it "should raise NotFound on 404 Not Found" do
|
45
45
|
response = HTTParty::Response.new(nil, '[]', 404, 'Not Found', {})
|
46
46
|
executing do
|
47
47
|
Base.check_status(response)
|
48
48
|
end.should raise_error(NotFound)
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
it "should raise InternalServerError on 500 Internal Server Error" do
|
52
52
|
response = HTTParty::Response.new(nil, '', 500, 'Internal Server Error', {})
|
53
53
|
executing do
|
@@ -67,7 +67,7 @@ describe Base do
|
|
67
67
|
e.errors.should == nil
|
68
68
|
end
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
it "should be correct when body is an empty hash" do
|
72
72
|
response = HTTParty::Response.new(nil, '{}', 404, 'Not Found', {})
|
73
73
|
begin
|
@@ -78,7 +78,7 @@ describe Base do
|
|
78
78
|
e.errors.should == nil
|
79
79
|
end
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
it "should be correct when body is an empty array" do
|
83
83
|
response = HTTParty::Response.new(nil, '[]', 404, 'Not Found', {})
|
84
84
|
begin
|
@@ -89,7 +89,7 @@ describe Base do
|
|
89
89
|
e.errors.should == nil
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
it "should be correct when body has errors hash" do
|
94
94
|
errors = '{"errors":["bad_error"]}'
|
95
95
|
response = HTTParty::Response.new(nil, errors, 400, 'Bad Request', {})
|
@@ -101,7 +101,7 @@ describe Base do
|
|
101
101
|
e.errors.should == ["bad_error"]
|
102
102
|
end
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
it "should be correct when body has hash" do
|
106
106
|
errors = '{"foo":["bar"]}'
|
107
107
|
response = HTTParty::Response.new(nil, errors, 400, 'Bad Request', {})
|
@@ -125,18 +125,18 @@ describe Base do
|
|
125
125
|
hash.name.should == "John Smith"
|
126
126
|
hash.email.should == "john@email.com"
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
it "should return nil from an empty hash" do
|
130
130
|
hash = Base.one({})
|
131
131
|
hash.should be_nil
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
it "should return nil from nil" do
|
135
135
|
hash = Base.one(nil)
|
136
136
|
hash.should be_nil
|
137
137
|
end
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
describe ".filterize" do
|
141
141
|
it "should work with 1 integer param" do
|
142
142
|
Base.filterize(:count => 7).should == %(count=7)
|
@@ -156,7 +156,7 @@ describe Base do
|
|
156
156
|
%(name="John Doe" and zip="20036")
|
157
157
|
].should include(Base.filterize(:name => "John Doe", :zip => "20036"))
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
it "should work with periods" do
|
161
161
|
Base.filterize('released.year' => 2008).should == %(released.year=2008)
|
162
162
|
end
|
@@ -164,13 +164,13 @@ describe Base do
|
|
164
164
|
it "should support 'or' by converting arrays to commas" do
|
165
165
|
Base.filterize('id' => [800, 801, 802]).should == %(id=800,801,802)
|
166
166
|
end
|
167
|
-
|
167
|
+
|
168
168
|
it "should pass through strings" do
|
169
169
|
["count > 0", "count >= 1"].each do |s|
|
170
170
|
Base.filterize(s).should == s
|
171
171
|
end
|
172
172
|
end
|
173
|
-
|
173
|
+
|
174
174
|
it "should work with boolean true" do
|
175
175
|
Base.filterize('is_awesome' => true).should == %(is_awesome=true)
|
176
176
|
end
|
@@ -178,7 +178,7 @@ describe Base do
|
|
178
178
|
it "should work with boolean false" do
|
179
179
|
Base.filterize('is_suck' => false).should == %(is_suck=false)
|
180
180
|
end
|
181
|
-
|
181
|
+
|
182
182
|
it "should raise ArgumentError when appropriate" do
|
183
183
|
[nil, [1]].each do |arg|
|
184
184
|
executing { Base.filterize(arg) }.should raise_error(ArgumentError)
|