datacatalog 0.3.5 → 0.3.6

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.3.5'
8
+ gem.version = '0.3.6'
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.3.5"
8
+ s.version = "0.3.6"
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{2009-11-13}
12
+ s.date = %q{2009-11-17}
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 = [
@@ -28,7 +28,11 @@ Gem::Specification.new do |s|
28
28
  "lib/resources/about.rb",
29
29
  "lib/resources/api_key.rb",
30
30
  "lib/resources/comment.rb",
31
+ "lib/resources/document.rb",
32
+ "lib/resources/favorite.rb",
33
+ "lib/resources/note.rb",
31
34
  "lib/resources/organization.rb",
35
+ "lib/resources/rating.rb",
32
36
  "lib/resources/source.rb",
33
37
  "lib/resources/user.rb",
34
38
  "sandbox_api.yml.example",
@@ -37,7 +41,11 @@ Gem::Specification.new do |s|
37
41
  "spec/base_spec.rb",
38
42
  "spec/comment_spec.rb",
39
43
  "spec/datacatalog_spec.rb",
44
+ "spec/document_spec.rb",
45
+ "spec/favorite_spec.rb",
46
+ "spec/note_spec.rb",
40
47
  "spec/organization_spec.rb",
48
+ "spec/rating_spec.rb",
41
49
  "spec/setup_api.rb",
42
50
  "spec/source_spec.rb",
43
51
  "spec/spec.opts",
@@ -59,7 +67,11 @@ Gem::Specification.new do |s|
59
67
  "spec/base_spec.rb",
60
68
  "spec/comment_spec.rb",
61
69
  "spec/datacatalog_spec.rb",
70
+ "spec/document_spec.rb",
71
+ "spec/favorite_spec.rb",
72
+ "spec/note_spec.rb",
62
73
  "spec/organization_spec.rb",
74
+ "spec/rating_spec.rb",
63
75
  "spec/setup_api.rb",
64
76
  "spec/source_spec.rb",
65
77
  "spec/spec_helper.rb",
@@ -0,0 +1,33 @@
1
+ module DataCatalog
2
+
3
+ class Document < Base
4
+
5
+ def self.all(conditions={})
6
+ many(http_get(uri, :query => 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
+ "/documents/#{id}"
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,29 @@
1
+ module DataCatalog
2
+
3
+ class Favorite < Base
4
+
5
+ def self.all(conditions={})
6
+ many(http_get(uri, :query => 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
+ # == Helpers
22
+
23
+ def self.uri(id=nil)
24
+ "/favorites/#{id}"
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,33 @@
1
+ module DataCatalog
2
+
3
+ class Note < Base
4
+
5
+ def self.all(conditions={})
6
+ many(http_get(uri, :query => 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
+ "/notes/#{id}"
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,33 @@
1
+ module DataCatalog
2
+
3
+ class Rating < Base
4
+
5
+ def self.all(conditions={})
6
+ many(http_get(uri, :query => 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
+ "/ratings/#{id}"
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,96 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include DataCatalog
3
+
4
+ describe Document do
5
+
6
+ before do
7
+ setup_api
8
+ clean_slate
9
+
10
+ @user = User.create(:name => "Ted Smith",
11
+ :email => "ted@email.com")
12
+
13
+ @source = Source.create(:title => "Some FCC Data",
14
+ :url => "http://fcc.gov/somedata.csv",
15
+ :source_type => "dataset")
16
+
17
+ DataCatalog.with_key(@user.primary_api_key) do
18
+ @document = Document.create(:source_id => @source.id, :text => "This is community documentation.")
19
+ end
20
+
21
+ end
22
+
23
+ describe ".create" do
24
+
25
+ it "should create a document when valid params are passed in" do
26
+ DataCatalog.with_key(@user.primary_api_key) do
27
+ refreshed_source = Source.get(@source.id)
28
+ refreshed_source.documents.first.text.should == "This is community documentation."
29
+ end
30
+ end
31
+
32
+ end # describe ".create"
33
+
34
+ describe ".get" do
35
+
36
+ it "should return a document" do
37
+ document = Document.get(@document.id)
38
+ document.should be_an_instance_of(Document)
39
+ document.source_id.should == @source.id
40
+ end
41
+
42
+ it "should raise NotFound if no document exists" do
43
+ executing do
44
+ Document.get(mangle(@document.id))
45
+ end.should raise_error(NotFound)
46
+ end
47
+
48
+ end # describe ".get"
49
+
50
+ describe ".all" do
51
+
52
+ it "should return a collection of all the source's documents" do
53
+ documents = Document.all(:source_id => @source.id)
54
+
55
+ documents.should be_an_instance_of(Array)
56
+ documents[0].should be_an_instance_of(Document)
57
+ end
58
+
59
+ end # describe ".all"
60
+
61
+ describe ".update" do
62
+
63
+ it "should update an existing document with valid params" do
64
+ @document.previous_id.should be nil
65
+ DataCatalog.with_key(@user.primary_api_key) do
66
+ Document.update(@document.id, :text => "This is the updated document.")
67
+ end
68
+
69
+ refreshed_document = Document.get(@document.id)
70
+ refreshed_document.text.should == "This is the updated document."
71
+ refreshed_document.previous_id.should_not be nil
72
+ end
73
+
74
+ end # describe ".update"
75
+
76
+ describe ".destroy" do
77
+
78
+ it "should destroy an existing document as an admin" do
79
+ Document.destroy(@document.id).should be_true
80
+ end
81
+
82
+ it "should not destroy an existing document as the user" do
83
+ DataCatalog.with_key(@user.primary_api_key) do
84
+ executing { Document.destroy(@document.id) }.should raise_error(Unauthorized)
85
+ end
86
+ end
87
+
88
+ it "should raise NotFound when attempting to destroy non-existing document" do
89
+ executing do
90
+ Document.destroy(mangle(@document.id))
91
+ end.should raise_error(NotFound)
92
+ end
93
+
94
+ end # describe ".destroy"
95
+
96
+ end
@@ -0,0 +1,80 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include DataCatalog
3
+
4
+ describe Favorite do
5
+
6
+ before do
7
+ setup_api
8
+ clean_slate
9
+
10
+ @user = User.create(:name => "Ted Smith",
11
+ :email => "ted@email.com")
12
+
13
+ @source = Source.create(:title => "Some FCC Data",
14
+ :url => "http://fcc.gov/somedata.csv",
15
+ :source_type => "dataset")
16
+
17
+ DataCatalog.with_key(@user.primary_api_key) do
18
+ @favorite = Favorite.create(:source_id => @source.id)
19
+ end
20
+
21
+ end
22
+
23
+ describe ".create" do
24
+
25
+ it "should create a favorite when valid params are passed in" do
26
+ refreshed_user = User.get(@user.id)
27
+ refreshed_user.favorites.first.title.should == "Some FCC Data"
28
+ end
29
+
30
+ end # describe ".create"
31
+
32
+ describe ".get" do
33
+
34
+ it "should return a favorite" do
35
+ favorite = Favorite.get(@favorite.id)
36
+ favorite.should be_an_instance_of(Favorite)
37
+ favorite.user_id.should == @user.id
38
+ end
39
+
40
+ it "should raise NotFound if no favorite exists" do
41
+ executing do
42
+ Favorite.get(mangle(@favorite.id))
43
+ end.should raise_error(NotFound)
44
+ end
45
+
46
+ end # describe ".get"
47
+
48
+ describe ".all" do
49
+
50
+ it "should return a collection of all the user's favorites" do
51
+ favorites = Favorite.all(:user_id => @user.id)
52
+
53
+ favorites.should be_an_instance_of(Array)
54
+ favorites[0].should be_an_instance_of(Favorite)
55
+ end
56
+
57
+ end # describe ".all"
58
+
59
+
60
+ describe ".destroy" do
61
+
62
+ it "should destroy an existing favorite as an admin" do
63
+ Favorite.destroy(@favorite.id).should be_true
64
+ end
65
+
66
+ it "should destroy an existing favorite as the user" do
67
+ DataCatalog.with_key(@user.primary_api_key) do
68
+ Favorite.destroy(@favorite.id).should be_true
69
+ end
70
+ end
71
+
72
+ it "should raise NotFound when attempting to destroy non-existing favorite" do
73
+ executing do
74
+ Favorite.destroy(mangle(@favorite.id))
75
+ end.should raise_error(NotFound)
76
+ end
77
+
78
+ end # describe ".destroy"
79
+
80
+ end
data/spec/note_spec.rb ADDED
@@ -0,0 +1,94 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include DataCatalog
3
+
4
+ describe Note do
5
+
6
+ before do
7
+ setup_api
8
+ clean_slate
9
+
10
+ @user = User.create(:name => "Ted Smith",
11
+ :email => "ted@email.com")
12
+
13
+ @source = Source.create(:title => "Some FCC Data",
14
+ :url => "http://fcc.gov/somedata.csv",
15
+ :source_type => "dataset")
16
+
17
+ DataCatalog.with_key(@user.primary_api_key) do
18
+ @note = Note.create(:source_id => @source.id, :text => "This is my note.")
19
+ end
20
+
21
+ end
22
+
23
+ describe ".create" do
24
+
25
+ it "should create a note when valid params are passed in" do
26
+ DataCatalog.with_key(@user.primary_api_key) do
27
+ refreshed_source = Source.get(@source.id)
28
+ refreshed_source.notes.first.text.should == "This is my note."
29
+ end
30
+ end
31
+
32
+ end # describe ".create"
33
+
34
+ describe ".get" do
35
+
36
+ it "should return a note" do
37
+ note = Note.get(@note.id)
38
+ note.should be_an_instance_of(Note)
39
+ note.user_id.should == @user.id
40
+ end
41
+
42
+ it "should raise NotFound if no note exists" do
43
+ executing do
44
+ Note.get(mangle(@note.id))
45
+ end.should raise_error(NotFound)
46
+ end
47
+
48
+ end # describe ".get"
49
+
50
+ describe ".all" do
51
+
52
+ it "should return a collection of all the user's notes" do
53
+ notes = Note.all(:user_id => @user.id)
54
+
55
+ notes.should be_an_instance_of(Array)
56
+ notes[0].should be_an_instance_of(Note)
57
+ end
58
+
59
+ end # describe ".all"
60
+
61
+ describe ".update" do
62
+
63
+ it "should update an existing note with valid params" do
64
+ DataCatalog.with_key(@user.primary_api_key) do
65
+ Note.update(@note.id, :text => "This is my updated note.")
66
+ end
67
+
68
+ refreshed_note = Note.get(@note.id)
69
+ refreshed_note.text.should == "This is my updated note."
70
+ end
71
+
72
+ end # describe ".update"
73
+
74
+ describe ".destroy" do
75
+
76
+ it "should destroy an existing note as an admin" do
77
+ Note.destroy(@note.id).should be_true
78
+ end
79
+
80
+ it "should destroy an existing note as the user" do
81
+ DataCatalog.with_key(@user.primary_api_key) do
82
+ Note.destroy(@note.id).should be_true
83
+ end
84
+ end
85
+
86
+ it "should raise NotFound when attempting to destroy non-existing note" do
87
+ executing do
88
+ Note.destroy(mangle(@note.id))
89
+ end.should raise_error(NotFound)
90
+ end
91
+
92
+ end # describe ".destroy"
93
+
94
+ end
@@ -0,0 +1,139 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include DataCatalog
3
+
4
+ describe Rating do
5
+
6
+ before do
7
+ setup_api
8
+ clean_slate
9
+
10
+ @user = User.create(:name => "Ted Smith",
11
+ :email => "ted@email.com")
12
+ @user2 = User.create(:name => "Chad Johnson",
13
+ :email => "chad@email.com")
14
+
15
+ @source = Source.create(:title => "Some FCC Data",
16
+ :url => "http://fcc.gov/somedata.csv",
17
+ :source_type => "dataset")
18
+
19
+ DataCatalog.with_key(@user.primary_api_key) do
20
+ @comment = Comment.create(:source_id => @source.id, :text => "This is a useful comment.")
21
+ end
22
+ end
23
+
24
+ describe ".create" do
25
+
26
+ it "should create a source rating when valid params are passed in" do
27
+ DataCatalog.with_key(@user.primary_api_key) do
28
+ @rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 5)
29
+ end
30
+
31
+ refreshed_source = Source.get(@source.id)
32
+ refreshed_source.rating_stats.average.should == 5
33
+ refreshed_source.rating_stats.total.should == 5
34
+ end
35
+
36
+ it "should create a comment rating when valid params are passed in" do
37
+ DataCatalog.with_key(@user2.primary_api_key) do
38
+ @rating = Rating.create(:kind => "comment", :comment_id => @comment.id, :value => 1)
39
+ end
40
+
41
+ refreshed_comment = Comment.get(@comment.id)
42
+ refreshed_comment.rating_stats.average.should == 1
43
+ refreshed_comment.rating_stats.total.should == 1
44
+ end
45
+
46
+ end # describe ".create"
47
+
48
+ describe ".get" do
49
+
50
+ before do
51
+ DataCatalog.with_key(@user.primary_api_key) do
52
+ @rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 5)
53
+ end
54
+ end
55
+
56
+ it "should return a rating" do
57
+ rating = Rating.get(@rating.id)
58
+ rating.should be_an_instance_of(Rating)
59
+ rating.value.should == 5
60
+ end
61
+
62
+ it "should raise NotFound if no rating exists" do
63
+ executing do
64
+ Rating.get(mangle(@rating.id))
65
+ end.should raise_error(NotFound)
66
+ end
67
+
68
+ end # describe ".get"
69
+
70
+ describe ".all" do
71
+
72
+ before do
73
+ DataCatalog.with_key(@user.primary_api_key) do
74
+ @rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 5)
75
+ end
76
+
77
+ DataCatalog.with_key(@user2.primary_api_key) do
78
+ @rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 3)
79
+ end
80
+
81
+ end
82
+
83
+ it "should return a collection of all the source's ratings" do
84
+ ratings = Rating.all(:source_id => @source.id)
85
+
86
+ ratings[0].should be_an_instance_of(Rating)
87
+ ratings[0].value.should == 5
88
+ ratings[1].value.should == 3
89
+ end
90
+
91
+ end # describe ".all"
92
+
93
+ describe ".update" do
94
+
95
+ before do
96
+ DataCatalog.with_key(@user.primary_api_key) do
97
+ @rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 5)
98
+ end
99
+ end
100
+
101
+ it "should update an existing rating with valid params" do
102
+ DataCatalog.with_key(@user.primary_api_key) do
103
+ Rating.update(@rating.id, :value => 3)
104
+ end
105
+
106
+ refreshed_rating = Rating.get(@rating.id)
107
+ refreshed_rating.value.should == 3
108
+ refreshed_rating.previous_value.should == 5
109
+ end
110
+
111
+ end # describe ".update"
112
+
113
+ describe ".destroy" do
114
+
115
+ before do
116
+ DataCatalog.with_key(@user.primary_api_key) do
117
+ @rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 5)
118
+ end
119
+ end
120
+
121
+ it "should destroy an existing rating as an admin" do
122
+ Rating.destroy(@rating.id).should be_true
123
+ end
124
+
125
+ it "should destroy an existing rating as the user" do
126
+ DataCatalog.with_key(@user.primary_api_key) do
127
+ Rating.destroy(@rating.id).should be_true
128
+ end
129
+ end
130
+
131
+ it "should raise NotFound when attempting to destroy non-existing rating" do
132
+ executing do
133
+ Rating.destroy(mangle(@rating.id))
134
+ end.should raise_error(NotFound)
135
+ end
136
+
137
+ end # describe ".destroy"
138
+
139
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datacatalog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luigi Montanez
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-11-13 00:00:00 -05:00
13
+ date: 2009-11-17 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -94,7 +94,11 @@ files:
94
94
  - lib/resources/about.rb
95
95
  - lib/resources/api_key.rb
96
96
  - lib/resources/comment.rb
97
+ - lib/resources/document.rb
98
+ - lib/resources/favorite.rb
99
+ - lib/resources/note.rb
97
100
  - lib/resources/organization.rb
101
+ - lib/resources/rating.rb
98
102
  - lib/resources/source.rb
99
103
  - lib/resources/user.rb
100
104
  - sandbox_api.yml.example
@@ -103,7 +107,11 @@ files:
103
107
  - spec/base_spec.rb
104
108
  - spec/comment_spec.rb
105
109
  - spec/datacatalog_spec.rb
110
+ - spec/document_spec.rb
111
+ - spec/favorite_spec.rb
112
+ - spec/note_spec.rb
106
113
  - spec/organization_spec.rb
114
+ - spec/rating_spec.rb
107
115
  - spec/setup_api.rb
108
116
  - spec/source_spec.rb
109
117
  - spec/spec.opts
@@ -146,7 +154,11 @@ test_files:
146
154
  - spec/base_spec.rb
147
155
  - spec/comment_spec.rb
148
156
  - spec/datacatalog_spec.rb
157
+ - spec/document_spec.rb
158
+ - spec/favorite_spec.rb
159
+ - spec/note_spec.rb
149
160
  - spec/organization_spec.rb
161
+ - spec/rating_spec.rb
150
162
  - spec/setup_api.rb
151
163
  - spec/source_spec.rb
152
164
  - spec/spec_helper.rb