datacatalog 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.md CHANGED
@@ -1,11 +1,11 @@
1
- Copyright (c) 2009, Sunlight Foundation.
2
-
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
-
7
- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
- * Neither the name of Sunlight Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
-
11
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1
+ Copyright (c) 2009, Sunlight Foundation.
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+ * Neither the name of Sunlight Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -1,34 +1,34 @@
1
- # Ruby Gem for the National Data Catalog API
2
-
3
- Under heavy development.
4
-
5
- ## Installation
6
-
7
- For now, the gem will not be packaged. Instead, install it manually:
8
-
9
- $ git clone git clone git://github.com/sunlightlabs/ruby-datacatalog.git
10
- $ cd ruby-datacatalog
11
- $ rake check_dependencies
12
- $ rake build
13
- $ rake install # uses sudo
14
- # Or, instead of the line above:
15
- $ gem install pkg/datacatalog-0.1.0.gem
16
-
17
- ## Usage
18
-
19
- require 'rubygems'
20
- require 'datacatalog'
21
-
22
- DataCatalog.api_key = 'c40505247a5e308a24d70a0118f76534b543795b'
23
-
24
- ## Running Specs
25
-
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:
27
-
28
- git clone git://github.com/sunlightlabs/datacatalog-api.git
29
-
30
- Get the app running like any normal Sinatra app, so you can choose to use thin or Passenger or new hotness like [Unicorn](http://unicorn.bogomips.org/). Some special considerations:
31
-
32
- 1. We recommend creating a `sandbox` entry in `datacatalog-api`'s `config.yml`.
33
- 2. Run `RACK_ENV=sandbox rake db:ensure_admin` in the `datacatalog-api` project to create a super admin for the API instance.
34
- 3. Back here in `ruby-datacatalog`, use the example file in `spec/` to create your own `spec/sandbox_api.yml` with the API key of the admin and your local URI.
1
+ # Ruby Gem for the National Data Catalog API
2
+
3
+ Under heavy development.
4
+
5
+ ## Installation
6
+
7
+ For now, the gem will not be packaged. Instead, install it manually:
8
+
9
+ $ git clone git clone git://github.com/sunlightlabs/ruby-datacatalog.git
10
+ $ cd ruby-datacatalog
11
+ $ rake check_dependencies
12
+ $ rake build
13
+ $ rake install # uses sudo
14
+ # Or, instead of the line above:
15
+ $ gem install pkg/datacatalog-0.1.0.gem
16
+
17
+ ## Usage
18
+
19
+ require 'rubygems'
20
+ require 'datacatalog'
21
+
22
+ DataCatalog.api_key = 'c40505247a5e308a24d70a0118f76534b543795b'
23
+
24
+ ## Running Specs
25
+
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:
27
+
28
+ git clone git://github.com/sunlightlabs/datacatalog-api.git
29
+
30
+ Get the app running like any normal Sinatra app, so you can choose to use thin or Passenger or new hotness like [Unicorn](http://unicorn.bogomips.org/). Some special considerations:
31
+
32
+ 1. We recommend creating a `sandbox` entry in `datacatalog-api`'s `config.yml`.
33
+ 2. Run `RACK_ENV=sandbox rake db:ensure_admin` in the `datacatalog-api` project to create a super admin for the API instance.
34
+ 3. Back here in `ruby-datacatalog`, use the example file in `spec/` to create your own `spec/sandbox_api.yml` with the API key of the admin and your local URI.
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.3'
8
+ gem.version = '0.4.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.4.3"
8
+ s.version = "0.4.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-12-09}
12
+ s.date = %q{2009-12-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 = [
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  "lib/resources/api_key.rb",
31
31
  "lib/resources/comment.rb",
32
32
  "lib/resources/document.rb",
33
+ "lib/resources/download.rb",
33
34
  "lib/resources/favorite.rb",
34
35
  "lib/resources/note.rb",
35
36
  "lib/resources/organization.rb",
@@ -69,6 +70,7 @@ Gem::Specification.new do |s|
69
70
  "spec/comment_spec.rb",
70
71
  "spec/datacatalog_spec.rb",
71
72
  "spec/document_spec.rb",
73
+ "spec/download_spec.rb",
72
74
  "spec/favorite_spec.rb",
73
75
  "spec/note_spec.rb",
74
76
  "spec/organization_spec.rb",
data/lib/main.rb CHANGED
@@ -1,41 +1,41 @@
1
- module DataCatalog
2
-
3
- # == Exceptions
4
-
5
- class Error < RuntimeError; end
6
- class BadRequest < Error; end # 400
7
- class Unauthorized < Error; end # 401
8
- class Forbidden < Error; end # 403
9
- class NotFound < Error; end # 404
10
- class Conflict < Error; end # 409
11
- class InternalServerError < Error; end # 500
12
- class ApiKeyNotConfigured < Error; end
13
- class CannotDeletePrimaryApiKey < Error; end
14
-
15
- # == Accessors
16
-
17
- def self.api_key
18
- Base.default_params[:api_key]
19
- end
20
-
21
- def self.api_key=(key)
22
- Base.default_params :api_key => key
23
- end
24
-
25
- def self.base_uri
26
- Base.base_uri
27
- end
28
-
29
- def self.base_uri=(uri)
30
- Base.base_uri(uri.blank? ? Base::DEFAULT_BASE_URI : uri)
31
- end
32
-
33
- def self.with_key(temp_key)
34
- original_key = DataCatalog.api_key
35
- DataCatalog.api_key = temp_key
36
- result = yield
37
- DataCatalog.api_key = original_key
38
- result
39
- end
40
-
41
- end
1
+ module DataCatalog
2
+
3
+ # == Exceptions
4
+
5
+ class Error < RuntimeError; end
6
+ class BadRequest < Error; end # 400
7
+ class Unauthorized < Error; end # 401
8
+ class Forbidden < Error; end # 403
9
+ class NotFound < Error; end # 404
10
+ class Conflict < Error; end # 409
11
+ class InternalServerError < Error; end # 500
12
+ class ApiKeyNotConfigured < Error; end
13
+ class CannotDeletePrimaryApiKey < Error; end
14
+
15
+ # == Accessors
16
+
17
+ def self.api_key
18
+ Base.default_params[:api_key]
19
+ end
20
+
21
+ def self.api_key=(key)
22
+ Base.default_params :api_key => key
23
+ end
24
+
25
+ def self.base_uri
26
+ Base.base_uri
27
+ end
28
+
29
+ def self.base_uri=(uri)
30
+ Base.base_uri(uri.blank? ? Base::DEFAULT_BASE_URI : uri)
31
+ end
32
+
33
+ def self.with_key(temp_key)
34
+ original_key = DataCatalog.api_key
35
+ DataCatalog.api_key = temp_key
36
+ result = yield
37
+ DataCatalog.api_key = original_key
38
+ result
39
+ end
40
+
41
+ end
@@ -0,0 +1,33 @@
1
+ module DataCatalog
2
+
3
+ class Download < Base
4
+
5
+ def self.all(conditions={})
6
+ cursor(uri, 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
+ "/downloads/#{id}"
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -1,2 +1,2 @@
1
- api_key: d193d1523d49e4caf46297ef94d7a2c995d3b2cb # generate with rake db:ensure_admin on datacatalog-api
2
- base_uri: sandbox.dc-api.local
1
+ api_key: d193d1523d49e4caf46297ef94d7a2c995d3b2cb # generate with rake db:ensure_admin on datacatalog-api
2
+ base_uri: sandbox.dc-api.local
@@ -1,36 +1,36 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
- include DataCatalog
3
-
4
- describe DataCatalog do
5
-
6
- describe "module accessors" do
7
- it "should access the API Key" do
8
- DataCatalog.api_key = "4159179f32ff8fefd2c6d48b7e675e7736bf1357"
9
- DataCatalog.api_key.should == "4159179f32ff8fefd2c6d48b7e675e7736bf1357"
10
- end
11
-
12
- it "should access the base URI" do
13
- DataCatalog.base_uri = 'http://somehost.com'
14
- DataCatalog.base_uri.should == 'http://somehost.com'
15
- end
16
- end
17
-
18
- describe ".with_key" do
19
- it "should set the API key within the block" do
20
- regular_key = '4159179f32ff8fefd2c6d48b7e675e7736bf1357'
21
- DataCatalog.api_key = regular_key
22
- temporary_key = '0000123400001234000012340000123400001234'
23
- DataCatalog.with_key(temporary_key) do
24
- DataCatalog.api_key.should == temporary_key
25
- end
26
- DataCatalog.api_key.should == regular_key
27
- end
28
-
29
- it "should return the last value in the block" do
30
- DataCatalog.with_key("0000444400004444") do
31
- 42
32
- end.should == 42
33
- end
34
- end
35
-
36
- end
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include DataCatalog
3
+
4
+ describe DataCatalog do
5
+
6
+ describe "module accessors" do
7
+ it "should access the API Key" do
8
+ DataCatalog.api_key = "4159179f32ff8fefd2c6d48b7e675e7736bf1357"
9
+ DataCatalog.api_key.should == "4159179f32ff8fefd2c6d48b7e675e7736bf1357"
10
+ end
11
+
12
+ it "should access the base URI" do
13
+ DataCatalog.base_uri = 'http://somehost.com'
14
+ DataCatalog.base_uri.should == 'http://somehost.com'
15
+ end
16
+ end
17
+
18
+ describe ".with_key" do
19
+ it "should set the API key within the block" do
20
+ regular_key = '4159179f32ff8fefd2c6d48b7e675e7736bf1357'
21
+ DataCatalog.api_key = regular_key
22
+ temporary_key = '0000123400001234000012340000123400001234'
23
+ DataCatalog.with_key(temporary_key) do
24
+ DataCatalog.api_key.should == temporary_key
25
+ end
26
+ DataCatalog.api_key.should == regular_key
27
+ end
28
+
29
+ it "should return the last value in the block" do
30
+ DataCatalog.with_key("0000444400004444") do
31
+ 42
32
+ end.should == 42
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,86 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ include DataCatalog
3
+
4
+ describe Download do
5
+
6
+ before do
7
+ setup_api
8
+ clean_slate
9
+ @user = User.create(
10
+ :name => "Ted Smith",
11
+ :email => "ted@email.com"
12
+ )
13
+ @source = Source.create(
14
+ :title => "Some FCC Data",
15
+ :url => "http://fcc.gov/somedata.csv",
16
+ :source_type => "dataset"
17
+ )
18
+ @download = Download.create(
19
+ :source_id => @source.id,
20
+ :format => "CSV",
21
+ :url => "http://somedata.gov/test.csv",
22
+ :preview => "1,2,3,4,5"
23
+ )
24
+ end
25
+
26
+ describe ".create" do
27
+
28
+ it "should create a download when valid params are passed in" do
29
+ refreshed_source = Source.get(@source.id)
30
+ refreshed_source.downloads.first.url.should == "http://somedata.gov/test.csv"
31
+ end
32
+
33
+ end # describe ".create"
34
+
35
+ describe ".get" do
36
+
37
+ it "should return a download" do
38
+ download = Download.get(@download.id)
39
+ download.should be_an_instance_of(Download)
40
+ download.source_id.should == @source.id
41
+ end
42
+
43
+ it "should raise NotFound if no download exists" do
44
+ executing do
45
+ Download.get(mangle(@download.id))
46
+ end.should raise_error(NotFound)
47
+ end
48
+
49
+ end # describe ".get"
50
+
51
+ describe ".all" do
52
+
53
+ it "should return an enumeration of downloads" do
54
+ downloads = Download.all(:source_id => @source.id)
55
+ downloads.each do |o|
56
+ o.should be_an_instance_of(Download)
57
+ end
58
+ end
59
+
60
+ end # describe ".all"
61
+
62
+ describe ".update" do
63
+
64
+ it "should update an existing download with valid params" do
65
+ Download.update(@download.id, :preview => "10,11,12,13")
66
+ refreshed_download = Download.get(@download.id)
67
+ refreshed_download.preview.should == "10,11,12,13"
68
+ end
69
+
70
+ end # describe ".update"
71
+
72
+ describe ".destroy" do
73
+
74
+ it "should destroy an existing download as an admin" do
75
+ Download.destroy(@download.id).should be_true
76
+ end
77
+
78
+ it "should raise NotFound when attempting to destroy non-existing download" do
79
+ executing do
80
+ Download.destroy(mangle(@download.id))
81
+ end.should raise_error(NotFound)
82
+ end
83
+
84
+ end # describe ".destroy"
85
+
86
+ 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.3
4
+ version: 0.4.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-12-09 00:00:00 -05:00
13
+ date: 2009-12-10 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -96,6 +96,7 @@ files:
96
96
  - lib/resources/api_key.rb
97
97
  - lib/resources/comment.rb
98
98
  - lib/resources/document.rb
99
+ - lib/resources/download.rb
99
100
  - lib/resources/favorite.rb
100
101
  - lib/resources/note.rb
101
102
  - lib/resources/organization.rb
@@ -156,6 +157,7 @@ test_files:
156
157
  - spec/comment_spec.rb
157
158
  - spec/datacatalog_spec.rb
158
159
  - spec/document_spec.rb
160
+ - spec/download_spec.rb
159
161
  - spec/favorite_spec.rb
160
162
  - spec/note_spec.rb
161
163
  - spec/organization_spec.rb