datacatalog 0.3.3 → 0.3.4

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.3'
8
+ gem.version = '0.3.4'
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.3"
8
+ s.version = "0.3.4"
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-03}
12
+ s.date = %q{2009-11-04}
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 = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "lib/main.rb",
28
28
  "lib/resources/about.rb",
29
29
  "lib/resources/api_key.rb",
30
+ "lib/resources/comment.rb",
30
31
  "lib/resources/organization.rb",
31
32
  "lib/resources/source.rb",
32
33
  "lib/resources/user.rb",
@@ -34,6 +35,7 @@ Gem::Specification.new do |s|
34
35
  "spec/about_spec.rb",
35
36
  "spec/api_key_spec.rb",
36
37
  "spec/base_spec.rb",
38
+ "spec/comment_spec.rb",
37
39
  "spec/datacatalog_spec.rb",
38
40
  "spec/organization_spec.rb",
39
41
  "spec/setup_api.rb",
@@ -55,6 +57,7 @@ Gem::Specification.new do |s|
55
57
  "spec/about_spec.rb",
56
58
  "spec/api_key_spec.rb",
57
59
  "spec/base_spec.rb",
60
+ "spec/comment_spec.rb",
58
61
  "spec/datacatalog_spec.rb",
59
62
  "spec/organization_spec.rb",
60
63
  "spec/setup_api.rb",
@@ -0,0 +1,33 @@
1
+ module DataCatalog
2
+
3
+ class Comment < 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
+ "/comments/#{id}"
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,126 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include DataCatalog
3
+
4
+ describe Comment 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
+ end
17
+
18
+ describe ".create" do
19
+
20
+ it "should create a new comment when valid params are passed in" do
21
+ DataCatalog.with_key(@user.primary_api_key) do
22
+ @comment = Comment.create(:source_id => @source.id, :text => "The first comment.")
23
+ end
24
+ @comment.should be_an_instance_of(Comment)
25
+
26
+ refreshed_source = Source.get(@source.id)
27
+ refreshed_source.comments.first.text.should == "The first comment."
28
+ refreshed_source.comments.first.user.name.should == "Ted Smith"
29
+ end
30
+
31
+ end # describe ".create"
32
+
33
+ describe ".get" do
34
+
35
+ before do
36
+ DataCatalog.with_key(@user.primary_api_key) do
37
+ @comment = Comment.create(:source_id => @source.id, :text => "The first comment.")
38
+ end
39
+ end
40
+
41
+ it "should return a comment" do
42
+ comment = Comment.get(@comment.id)
43
+ comment.should be_an_instance_of(Comment)
44
+ comment.text.should == "The first comment."
45
+ end
46
+
47
+ it "should raise NotFound if no comment exists" do
48
+ executing do
49
+ Comment.get(mangle(@comment.id))
50
+ end.should raise_error(NotFound)
51
+ end
52
+
53
+ end # describe ".get"
54
+
55
+ describe ".all" do
56
+
57
+ before do
58
+ @john = User.create(:name => "John Smith",
59
+ :email => "john@email.com")
60
+ @data = Source.create(:title => "Some FEC Data",
61
+ :url => "http://fec.gov/somedata.csv",
62
+ :source_type => "dataset")
63
+
64
+ DataCatalog.with_key(@john.primary_api_key) do
65
+ Comment.create(:source_id => @data.id, :text => "The first comment.")
66
+ Comment.create(:source_id => @data.id, :text => "The second comment.")
67
+ end
68
+ end
69
+
70
+ it "should return a set of all user's comments" do
71
+ comments = Comment.all(:user_id => @john.id)
72
+ comments.first.should be_an_instance_of(Comment)
73
+ ["first", "second"].each_with_index do |nth, i|
74
+ comments[i].text.should == "The #{nth} comment."
75
+ end
76
+ end
77
+
78
+ end # describe ".all"
79
+
80
+ describe ".update" do
81
+
82
+ before do
83
+ DataCatalog.with_key(@user.primary_api_key) do
84
+ @comment = Comment.create(:source_id => @source.id, :text => "The first comment.")
85
+ end
86
+ end
87
+
88
+ it "should update an existing comment with valid params" do
89
+ DataCatalog.with_key(@user.primary_api_key) do
90
+ Comment.update(@comment.id, :text => "The first comment, updated.")
91
+ end
92
+
93
+ refreshed_source = Source.get(@source.id)
94
+ refreshed_source.comments.first.text.should == "The first comment, updated."
95
+ refreshed_source.comments.first.user.name.should == "Ted Smith"
96
+ end
97
+
98
+ end # describe ".update"
99
+
100
+ describe ".destroy" do
101
+
102
+ before do
103
+ DataCatalog.with_key(@user.primary_api_key) do
104
+ @comment = Comment.create(:source_id => @source.id, :text => "The first comment.")
105
+ end
106
+ end
107
+
108
+ it "should destroy an existing comment as an admin" do
109
+ Comment.destroy(@comment.id).should be_true
110
+ end
111
+
112
+ it "should destroy an existing comment as the user" do
113
+ DataCatalog.with_key(@user.primary_api_key) do
114
+ Comment.destroy(@comment.id).should be_true
115
+ end
116
+ end
117
+
118
+ it "should raise NotFound when attempting to destroy non-existing comment" do
119
+ executing do
120
+ Comment.destroy(mangle(@comment.id))
121
+ end.should raise_error(NotFound)
122
+ end
123
+
124
+ end # describe ".destroy"
125
+
126
+ 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.3
4
+ version: 0.3.4
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-03 00:00:00 -05:00
13
+ date: 2009-11-04 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -93,6 +93,7 @@ files:
93
93
  - lib/main.rb
94
94
  - lib/resources/about.rb
95
95
  - lib/resources/api_key.rb
96
+ - lib/resources/comment.rb
96
97
  - lib/resources/organization.rb
97
98
  - lib/resources/source.rb
98
99
  - lib/resources/user.rb
@@ -100,6 +101,7 @@ files:
100
101
  - spec/about_spec.rb
101
102
  - spec/api_key_spec.rb
102
103
  - spec/base_spec.rb
104
+ - spec/comment_spec.rb
103
105
  - spec/datacatalog_spec.rb
104
106
  - spec/organization_spec.rb
105
107
  - spec/setup_api.rb
@@ -142,6 +144,7 @@ test_files:
142
144
  - spec/about_spec.rb
143
145
  - spec/api_key_spec.rb
144
146
  - spec/base_spec.rb
147
+ - spec/comment_spec.rb
145
148
  - spec/datacatalog_spec.rb
146
149
  - spec/organization_spec.rb
147
150
  - spec/setup_api.rb