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/README.md
CHANGED
@@ -20,7 +20,7 @@ For now, the gem will not be packaged. Instead, install it manually:
|
|
20
20
|
require 'datacatalog'
|
21
21
|
|
22
22
|
DataCatalog.api_key = 'c40505247a5e308a24d70a0118f76534b543795b'
|
23
|
-
|
23
|
+
|
24
24
|
## Running Specs
|
25
25
|
|
26
26
|
We're not mocking out any of the web API calls in the specs. Instead, we expect developers who wish to run the specs to download and run a local sandbox instance of the [Data Catalog API](http://github.com/sunlightlabs/datacatalog-api), a Sinatra app:
|
data/Rakefile
CHANGED
@@ -5,19 +5,19 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "datacatalog"
|
8
|
-
gem.version = '0.4.
|
8
|
+
gem.version = '0.4.16'
|
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}
|
12
12
|
gem.email = "luigi@sunlightfoundation.com"
|
13
13
|
gem.homepage = "http://github.com/sunlightlabs/datacatalog"
|
14
14
|
gem.authors = ["Luigi Montanez", "David James"]
|
15
|
-
gem.add_dependency('activesupport', ">= 2.3.
|
16
|
-
gem.add_dependency('httparty', ">= 0.
|
17
|
-
gem.add_dependency('mash', ">= 0.
|
15
|
+
gem.add_dependency('activesupport', ">= 2.3.8")
|
16
|
+
gem.add_dependency('httparty', ">= 0.6.1")
|
17
|
+
gem.add_dependency('mash', ">= 0.1.1")
|
18
18
|
gem.add_dependency('version_string', ">= 0.1.0")
|
19
|
-
gem.add_development_dependency("jeweler", ">= 1.
|
20
|
-
gem.add_development_dependency("rspec", ">= 1.
|
19
|
+
gem.add_development_dependency("jeweler", ">= 1.4.0")
|
20
|
+
gem.add_development_dependency("rspec", ">= 1.3.0")
|
21
21
|
# gem is a Gem::Specification...
|
22
22
|
# see http://www.rubygems.org/read/chapter/20 for additional settings
|
23
23
|
end
|
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.
|
8
|
+
s.version = "0.4.16"
|
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-
|
12
|
+
s.date = %q{2010-08-10}
|
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 = [
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/main.rb",
|
30
30
|
"lib/resources/about.rb",
|
31
31
|
"lib/resources/api_key.rb",
|
32
|
+
"lib/resources/broken_link.rb",
|
32
33
|
"lib/resources/comment.rb",
|
33
34
|
"lib/resources/document.rb",
|
34
35
|
"lib/resources/download.rb",
|
@@ -49,6 +50,7 @@ Gem::Specification.new do |s|
|
|
49
50
|
"spec/datacatalog_spec.rb",
|
50
51
|
"spec/document_spec.rb",
|
51
52
|
"spec/download_spec.rb",
|
53
|
+
"spec/empty_spec.rb",
|
52
54
|
"spec/favorite_spec.rb",
|
53
55
|
"spec/import_spec.rb",
|
54
56
|
"spec/importer_spec.rb",
|
@@ -79,6 +81,7 @@ Gem::Specification.new do |s|
|
|
79
81
|
"spec/datacatalog_spec.rb",
|
80
82
|
"spec/document_spec.rb",
|
81
83
|
"spec/download_spec.rb",
|
84
|
+
"spec/empty_spec.rb",
|
82
85
|
"spec/favorite_spec.rb",
|
83
86
|
"spec/import_spec.rb",
|
84
87
|
"spec/importer_spec.rb",
|
@@ -97,27 +100,27 @@ Gem::Specification.new do |s|
|
|
97
100
|
s.specification_version = 3
|
98
101
|
|
99
102
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
100
|
-
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.
|
101
|
-
s.add_runtime_dependency(%q<httparty>, [">= 0.
|
102
|
-
s.add_runtime_dependency(%q<mash>, [">= 0.
|
103
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.8"])
|
104
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
|
105
|
+
s.add_runtime_dependency(%q<mash>, [">= 0.1.1"])
|
103
106
|
s.add_runtime_dependency(%q<version_string>, [">= 0.1.0"])
|
104
|
-
s.add_development_dependency(%q<jeweler>, [">= 1.
|
105
|
-
s.add_development_dependency(%q<rspec>, [">= 1.
|
107
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.4.0"])
|
108
|
+
s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
|
106
109
|
else
|
107
|
-
s.add_dependency(%q<activesupport>, [">= 2.3.
|
108
|
-
s.add_dependency(%q<httparty>, [">= 0.
|
109
|
-
s.add_dependency(%q<mash>, [">= 0.
|
110
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.8"])
|
111
|
+
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
112
|
+
s.add_dependency(%q<mash>, [">= 0.1.1"])
|
110
113
|
s.add_dependency(%q<version_string>, [">= 0.1.0"])
|
111
|
-
s.add_dependency(%q<jeweler>, [">= 1.
|
112
|
-
s.add_dependency(%q<rspec>, [">= 1.
|
114
|
+
s.add_dependency(%q<jeweler>, [">= 1.4.0"])
|
115
|
+
s.add_dependency(%q<rspec>, [">= 1.3.0"])
|
113
116
|
end
|
114
117
|
else
|
115
|
-
s.add_dependency(%q<activesupport>, [">= 2.3.
|
116
|
-
s.add_dependency(%q<httparty>, [">= 0.
|
117
|
-
s.add_dependency(%q<mash>, [">= 0.
|
118
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.8"])
|
119
|
+
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
120
|
+
s.add_dependency(%q<mash>, [">= 0.1.1"])
|
118
121
|
s.add_dependency(%q<version_string>, [">= 0.1.0"])
|
119
|
-
s.add_dependency(%q<jeweler>, [">= 1.
|
120
|
-
s.add_dependency(%q<rspec>, [">= 1.
|
122
|
+
s.add_dependency(%q<jeweler>, [">= 1.4.0"])
|
123
|
+
s.add_dependency(%q<rspec>, [">= 1.3.0"])
|
121
124
|
end
|
122
125
|
end
|
123
126
|
|
data/lib/base.rb
CHANGED
@@ -18,7 +18,7 @@ module DataCatalog
|
|
18
18
|
end
|
19
19
|
|
20
20
|
# == protected
|
21
|
-
|
21
|
+
|
22
22
|
def self.check_status(response)
|
23
23
|
case response.code
|
24
24
|
when 400 then error(BadRequest, response)
|
@@ -30,7 +30,7 @@ module DataCatalog
|
|
30
30
|
end
|
31
31
|
response
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def self.cursor(uri, query_hash)
|
35
35
|
Cursor.new({
|
36
36
|
:klass => self,
|
@@ -39,7 +39,7 @@ module DataCatalog
|
|
39
39
|
:uri => uri,
|
40
40
|
})
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def self.error(exception_class, response)
|
44
44
|
e = exception_class.new
|
45
45
|
e.response_body = response.body
|
@@ -56,7 +56,7 @@ module DataCatalog
|
|
56
56
|
end
|
57
57
|
raise e
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def self._first(response)
|
61
61
|
item = response['members'][0]
|
62
62
|
item.blank? ? nil : new(item)
|
@@ -69,11 +69,11 @@ module DataCatalog
|
|
69
69
|
end
|
70
70
|
response.blank? ? nil : new(response)
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
def self.query_hash(conditions)
|
74
74
|
conditions == {} ? {} : { :filter => filterize(conditions) }
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
def self.filterize(arg)
|
78
78
|
if arg.is_a?(Hash)
|
79
79
|
filterize_hash(arg)
|
@@ -83,7 +83,7 @@ module DataCatalog
|
|
83
83
|
raise ArgumentError
|
84
84
|
end
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
def self.filterize_hash(conditions)
|
88
88
|
filtered_conditions = conditions.map do |k, v|
|
89
89
|
"#{k}" + if v.is_a?(Regexp)
|
@@ -98,7 +98,7 @@ module DataCatalog
|
|
98
98
|
end
|
99
99
|
filtered_conditions.join(" and ")
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
def method_missing(method_name, *args)
|
103
103
|
if method_name.to_s.match(/.*_(on|at)\z/)
|
104
104
|
return Time.parse(super)
|
data/lib/cursor.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module DataCatalog
|
2
2
|
|
3
3
|
class Cursor
|
4
|
-
|
4
|
+
|
5
5
|
attr_reader :document_count
|
6
6
|
attr_reader :page_count
|
7
7
|
attr_reader :page_size
|
8
|
-
|
8
|
+
|
9
9
|
include Enumerable
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(options)
|
12
12
|
@klass = options[:klass]
|
13
13
|
@query_hash = options[:query_hash]
|
@@ -19,7 +19,7 @@ module DataCatalog
|
|
19
19
|
@members = members(@response)
|
20
20
|
@page_count = @response['page_count']
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def [](i)
|
24
24
|
member_at(i)
|
25
25
|
end
|
@@ -27,11 +27,15 @@ module DataCatalog
|
|
27
27
|
def each
|
28
28
|
@document_count.times { |i| yield member_at(i) }
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
|
+
def empty?
|
32
|
+
@document_count == 0
|
33
|
+
end
|
34
|
+
|
31
35
|
def first
|
32
36
|
member_at(0)
|
33
37
|
end
|
34
|
-
|
38
|
+
|
35
39
|
def last
|
36
40
|
member_at(@document_count - 1)
|
37
41
|
end
|
@@ -43,13 +47,13 @@ module DataCatalog
|
|
43
47
|
def page(page_number)
|
44
48
|
page_indices(page_number).map { |i| member_at(i) }
|
45
49
|
end
|
46
|
-
|
50
|
+
|
47
51
|
def size
|
48
52
|
@members.size
|
49
53
|
end
|
50
|
-
|
54
|
+
|
51
55
|
protected
|
52
|
-
|
56
|
+
|
53
57
|
def fetch_members_near_index(index)
|
54
58
|
page_number = page_for_index(index)
|
55
59
|
response = response_for_page(page_number)
|
@@ -60,7 +64,7 @@ module DataCatalog
|
|
60
64
|
end
|
61
65
|
fetched.length
|
62
66
|
end
|
63
|
-
|
67
|
+
|
64
68
|
def member_at(index)
|
65
69
|
if index < 0
|
66
70
|
raise "index (#{index}) must be >= 0"
|
@@ -77,7 +81,7 @@ module DataCatalog
|
|
77
81
|
def members(response)
|
78
82
|
response['members'].map { |x| @klass.new(x) }
|
79
83
|
end
|
80
|
-
|
84
|
+
|
81
85
|
def page_for_index(index)
|
82
86
|
(index / @page_size) + 1
|
83
87
|
end
|
@@ -94,5 +98,5 @@ module DataCatalog
|
|
94
98
|
end
|
95
99
|
|
96
100
|
end
|
97
|
-
|
101
|
+
|
98
102
|
end
|
data/lib/main.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module DataCatalog
|
2
|
-
|
2
|
+
|
3
3
|
# == Exceptions
|
4
|
-
|
4
|
+
|
5
5
|
class Error < RuntimeError
|
6
6
|
attr_accessor :response_body # String
|
7
7
|
attr_accessor :parsed_response_body # Hash
|
@@ -16,26 +16,26 @@ module DataCatalog
|
|
16
16
|
class InternalServerError < Error; end # 500
|
17
17
|
class ApiKeyNotConfigured < Error; end
|
18
18
|
class CannotDeletePrimaryApiKey < Error; end
|
19
|
-
|
19
|
+
|
20
20
|
# == Accessors
|
21
|
-
|
21
|
+
|
22
22
|
def self.api_key
|
23
23
|
Connection.default_params[:api_key]
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def self.api_key=(key)
|
27
27
|
Connection.default_params[:api_key] = key
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def self.base_uri
|
31
31
|
Connection.base_uri
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def self.base_uri=(uri)
|
35
35
|
u = uri.blank? ? Connection::DEFAULT_BASE_URI : uri
|
36
36
|
Connection.base_uri(u)
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def self.with_key(temp_key)
|
40
40
|
original_key = DataCatalog.api_key
|
41
41
|
DataCatalog.api_key = temp_key
|
data/lib/resources/about.rb
CHANGED
@@ -3,17 +3,17 @@ require 'version_string'
|
|
3
3
|
module DataCatalog
|
4
4
|
|
5
5
|
class About < Base
|
6
|
-
|
6
|
+
|
7
7
|
def self.get()
|
8
8
|
one(http_get("/"))
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def self.version_at_least?(minimum)
|
12
12
|
actual = VersionString.new(get.version)
|
13
13
|
floor = VersionString.new(minimum)
|
14
14
|
actual >= floor
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
end
|
data/lib/resources/api_key.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module DataCatalog
|
2
2
|
|
3
3
|
class ApiKey < Base
|
4
|
-
|
4
|
+
|
5
5
|
def self.all(user_id, conditions={})
|
6
6
|
cursor(uri(user_id), query_hash(conditions))
|
7
7
|
end
|
@@ -21,18 +21,18 @@ module DataCatalog
|
|
21
21
|
def self.get(user_id, id)
|
22
22
|
one(http_get(uri(user_id, id)))
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def self.update(user_id, id, params={})
|
26
26
|
one(http_put(uri(user_id, id), :body => params))
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
# == Helpers
|
30
|
-
|
30
|
+
|
31
31
|
def self.uri(user_id, id=nil)
|
32
32
|
raise Error, "user_id cannot be blank" if user_id.blank?
|
33
33
|
"/users/#{user_id}/keys/#{id}"
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module DataCatalog
|
2
|
+
|
3
|
+
class BrokenLink < 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
|
+
"/broken_links/#{id}"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/resources/comment.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module DataCatalog
|
2
2
|
|
3
3
|
class Comment < 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
|
"/comments/#{id}"
|
29
29
|
end
|
data/lib/resources/document.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module DataCatalog
|
2
2
|
|
3
3
|
class Document < 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
|
"/documents/#{id}"
|
29
29
|
end
|