datacatalog 0.4.8 → 0.4.9

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.4.8'
8
+ gem.version = '0.4.9'
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.4.8"
8
+ s.version = "0.4.9"
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-12-15}
12
+ s.date = %q{2010-02-01}
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 = [
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  "Rakefile",
24
24
  "datacatalog.gemspec",
25
25
  "lib/base.rb",
26
+ "lib/connection.rb",
26
27
  "lib/cursor.rb",
27
28
  "lib/datacatalog.rb",
28
29
  "lib/main.rb",
@@ -35,6 +36,7 @@ Gem::Specification.new do |s|
35
36
  "lib/resources/note.rb",
36
37
  "lib/resources/organization.rb",
37
38
  "lib/resources/rating.rb",
39
+ "lib/resources/report.rb",
38
40
  "lib/resources/source.rb",
39
41
  "lib/resources/user.rb",
40
42
  "sandbox_api.yml.example",
@@ -49,6 +51,7 @@ Gem::Specification.new do |s|
49
51
  "spec/note_spec.rb",
50
52
  "spec/organization_spec.rb",
51
53
  "spec/rating_spec.rb",
54
+ "spec/report_spec.rb",
52
55
  "spec/setup_api.rb",
53
56
  "spec/source_spec.rb",
54
57
  "spec/spec.opts",
@@ -76,6 +79,7 @@ Gem::Specification.new do |s|
76
79
  "spec/note_spec.rb",
77
80
  "spec/organization_spec.rb",
78
81
  "spec/rating_spec.rb",
82
+ "spec/report_spec.rb",
79
83
  "spec/setup_api.rb",
80
84
  "spec/source_spec.rb",
81
85
  "spec/spec_helper.rb",
data/lib/base.rb CHANGED
@@ -1,40 +1,20 @@
1
1
  module DataCatalog
2
2
 
3
3
  class Base < Mash
4
-
5
- DEFAULT_BASE_URI = 'http://api.nationaldatacatalog.com'
6
-
7
- include HTTParty
8
-
9
- format :json
10
- base_uri DEFAULT_BASE_URI
11
-
12
- class << self
13
- alias_method :_delete, :delete
14
- alias_method :_get, :get
15
- alias_method :_post, :post
16
- alias_method :_put, :put
17
-
18
- undef_method :delete
19
- undef_method :get
20
- undef_method :post
21
- undef_method :put
22
- end
23
-
24
4
  def self.http_delete(path, options={})
25
- check_status(_delete(path, options))
5
+ check_status(Connection.delete(path, options))
26
6
  end
27
-
7
+
28
8
  def self.http_get(path, options={})
29
- check_status(_get(path, options))
9
+ check_status(Connection.get(path, options))
30
10
  end
31
11
 
32
12
  def self.http_post(path, options={})
33
- check_status(_post(path, options))
13
+ check_status(Connection.post(path, options))
34
14
  end
35
15
 
36
16
  def self.http_put(path, options={})
37
- check_status(_put(path, options))
17
+ check_status(Connection.put(path, options))
38
18
  end
39
19
 
40
20
  # == protected
data/lib/connection.rb ADDED
@@ -0,0 +1,14 @@
1
+ module DataCatalog
2
+
3
+ module Connection
4
+ extend self
5
+ include HTTParty
6
+
7
+ DEFAULT_BASE_URI = 'http://api.nationaldatacatalog.com'
8
+
9
+ format :json
10
+ base_uri DEFAULT_BASE_URI
11
+ default_params :api_key => DataCatalog.api_key
12
+ end
13
+
14
+ end
data/lib/datacatalog.rb CHANGED
@@ -5,6 +5,7 @@ require 'httparty'
5
5
  require 'mash'
6
6
 
7
7
  require File.dirname(__FILE__) + '/main'
8
+ require File.dirname(__FILE__) + '/connection'
8
9
  require File.dirname(__FILE__) + '/base'
9
10
  require File.dirname(__FILE__) + '/cursor'
10
11
  Dir.glob(File.dirname(__FILE__) + '/resources/*.rb').each { |f| require f }
data/lib/main.rb CHANGED
@@ -15,19 +15,20 @@ module DataCatalog
15
15
  # == Accessors
16
16
 
17
17
  def self.api_key
18
- Base.default_params[:api_key]
18
+ Connection.default_params[:api_key]
19
19
  end
20
20
 
21
21
  def self.api_key=(key)
22
- Base.default_params :api_key => key
22
+ Connection.default_params[:api_key] = key
23
23
  end
24
24
 
25
25
  def self.base_uri
26
- Base.base_uri
26
+ Connection.base_uri
27
27
  end
28
28
 
29
29
  def self.base_uri=(uri)
30
- Base.base_uri(uri.blank? ? Base::DEFAULT_BASE_URI : uri)
30
+ u = uri.blank? ? Connection::DEFAULT_BASE_URI : uri
31
+ Connection.base_uri(u)
31
32
  end
32
33
 
33
34
  def self.with_key(temp_key)
@@ -0,0 +1,33 @@
1
+ module DataCatalog
2
+
3
+ class Report < 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
+ "/reports/#{id}"
29
+ end
30
+
31
+ end
32
+
33
+ end
data/spec/base_spec.rb CHANGED
@@ -17,7 +17,7 @@ describe Base do
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'
20
- Base.base_uri.should == 'http://api.nationaldatacatalog.com'
20
+ DataCatalog.base_uri.should == 'http://api.nationaldatacatalog.com'
21
21
  end
22
22
  end
23
23
 
@@ -0,0 +1,124 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include DataCatalog
3
+
4
+ describe Report do
5
+
6
+ before do
7
+ setup_api
8
+ clean_slate
9
+ @john = User.create(
10
+ :name => "John M. Porter",
11
+ :email => "john.m.porter@email.com",
12
+ :curator => true
13
+ )
14
+ end
15
+
16
+ describe ".create" do
17
+ it "should create a new report when valid params are passed in" do
18
+ DataCatalog.with_key(@john.primary_api_key) do
19
+ @report = Report.create(
20
+ :text => "Report 1 by John",
21
+ :status => "new"
22
+ )
23
+ end
24
+ @report.should be_an_instance_of(Report)
25
+ refreshed_report = Report.get(@report.id)
26
+ refreshed_report.text.should == "Report 1 by John"
27
+ refreshed_report.status.should == "new"
28
+ refreshed_report.user_id.should == @john.id
29
+ end
30
+ end
31
+
32
+ describe ".get" do
33
+ before do
34
+ DataCatalog.with_key(@john.primary_api_key) do
35
+ @report = Report.create(
36
+ :text => "Report 1 by John",
37
+ :status => "new"
38
+ )
39
+ end
40
+ end
41
+
42
+ it "should return a report" do
43
+ report = Report.get(@report.id)
44
+ report.should be_an_instance_of(Report)
45
+ report.text.should == "Report 1 by John"
46
+ end
47
+
48
+ it "should raise NotFound if no report exists" do
49
+ executing do
50
+ Report.get(mangle(@report.id))
51
+ end.should raise_error(NotFound)
52
+ end
53
+ end
54
+
55
+ describe ".all" do
56
+ before do
57
+ @jane = User.create(
58
+ :name => "Jane M. Porter",
59
+ :email => "jane@email.com",
60
+ :curator => true
61
+ )
62
+ DataCatalog.with_key(@jane.primary_api_key) do
63
+ Report.create(:text => "Report 1 by Jane", :status => "new")
64
+ Report.create(:text => "Report 2 by Jane", :status => "new")
65
+ end
66
+ end
67
+
68
+ it "should return a set of all user's reports" do
69
+ reports = Report.all(:user_id => @jane.id)
70
+ reports.first.should be_an_instance_of(Report)
71
+ [1, 2].each_with_index do |n, i|
72
+ reports[i].text.should == "Report #{n} by Jane"
73
+ end
74
+ end
75
+ end
76
+
77
+ describe ".update" do
78
+ before do
79
+ DataCatalog.with_key(@john.primary_api_key) do
80
+ @report = Report.create(
81
+ :text => "Report 1 by John",
82
+ :status => "new"
83
+ )
84
+ end
85
+ end
86
+
87
+ it "should update an existing report with valid params" do
88
+ DataCatalog.with_key(@john.primary_api_key) do
89
+ Report.update(@report.id, :status => "open")
90
+ end
91
+ refreshed_report = Report.get(@report.id)
92
+ refreshed_report.text.should == "Report 1 by John"
93
+ refreshed_report.status.should == "open"
94
+ end
95
+ end
96
+
97
+ describe ".destroy" do
98
+ before do
99
+ DataCatalog.with_key(@john.primary_api_key) do
100
+ @report = Report.create(
101
+ :text => "Report 1 by John",
102
+ :status => "new"
103
+ )
104
+ end
105
+ end
106
+
107
+ it "should destroy an existing report as an admin" do
108
+ Report.destroy(@report.id).should be_true
109
+ end
110
+
111
+ it "should destroy an existing report as the user" do
112
+ DataCatalog.with_key(@john.primary_api_key) do
113
+ Report.destroy(@report.id).should be_true
114
+ end
115
+ end
116
+
117
+ it "should raise NotFound when attempting to destroy non-existing report" do
118
+ executing do
119
+ Report.destroy(mangle(@report.id))
120
+ end.should raise_error(NotFound)
121
+ end
122
+ end
123
+
124
+ 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.4.8
4
+ version: 0.4.9
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-12-15 00:00:00 -05:00
13
+ date: 2010-02-01 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -89,6 +89,7 @@ files:
89
89
  - Rakefile
90
90
  - datacatalog.gemspec
91
91
  - lib/base.rb
92
+ - lib/connection.rb
92
93
  - lib/cursor.rb
93
94
  - lib/datacatalog.rb
94
95
  - lib/main.rb
@@ -101,6 +102,7 @@ files:
101
102
  - lib/resources/note.rb
102
103
  - lib/resources/organization.rb
103
104
  - lib/resources/rating.rb
105
+ - lib/resources/report.rb
104
106
  - lib/resources/source.rb
105
107
  - lib/resources/user.rb
106
108
  - sandbox_api.yml.example
@@ -115,6 +117,7 @@ files:
115
117
  - spec/note_spec.rb
116
118
  - spec/organization_spec.rb
117
119
  - spec/rating_spec.rb
120
+ - spec/report_spec.rb
118
121
  - spec/setup_api.rb
119
122
  - spec/source_spec.rb
120
123
  - spec/spec.opts
@@ -163,6 +166,7 @@ test_files:
163
166
  - spec/note_spec.rb
164
167
  - spec/organization_spec.rb
165
168
  - spec/rating_spec.rb
169
+ - spec/report_spec.rb
166
170
  - spec/setup_api.rb
167
171
  - spec/source_spec.rb
168
172
  - spec/spec_helper.rb