datacatalog 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -5,6 +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
9
  gem.rubyforge_project = "datacatalog"
9
10
  gem.summary = %Q{Client for the National Data Catalog API}
10
11
  gem.description = %Q{A Ruby client library for the National Data Catalog API}
data/datacatalog.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{datacatalog}
8
- s.version = "0.3.2"
8
+ s.version = "0.3.3"
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-10-29}
12
+ s.date = %q{2009-11-03}
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 = [
@@ -18,11 +18,9 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".gitignore",
21
- "CHANGES.md",
22
21
  "LICENSE.md",
23
22
  "README.md",
24
23
  "Rakefile",
25
- "VERSION",
26
24
  "datacatalog.gemspec",
27
25
  "lib/base.rb",
28
26
  "lib/datacatalog.rb",
@@ -93,3 +91,4 @@ Gem::Specification.new do |s|
93
91
  s.add_dependency(%q<rspec>, [">= 1.2.8"])
94
92
  end
95
93
  end
94
+
data/lib/base.rb CHANGED
@@ -74,23 +74,11 @@ module DataCatalog
74
74
  end
75
75
 
76
76
  def self.query_hash(conditions)
77
- if conditions.empty?
78
- query_hash = {}
79
- else
80
- query_hash = {:filter => filterize(conditions)}
81
- end
77
+ conditions == {} ? {} : { :filter => filterize(conditions) }
82
78
  end
83
79
 
84
80
  def self.filterize(conditions)
85
- filter_string = ""
86
- new_conditions = {}
87
- conditions.each do |k,v|
88
- new_conditions[k.to_s] = v
89
- end
90
- new_conditions.sort.each do |k,v|
91
- filter_string += "#{k.to_s}:\"#{v}\" "
92
- end
93
- filter_string.strip!
81
+ conditions.map { |k, v| %(#{k}:"#{v}") }.join(" ")
94
82
  end
95
83
 
96
84
  def method_missing(method_name, *args)
@@ -3,7 +3,7 @@ module DataCatalog
3
3
  class ApiKey < Base
4
4
 
5
5
  def self.all(user_id, conditions={})
6
- many(http_get(uri(user_id), :query => conditions))
6
+ many(http_get(uri(user_id), :query => query_hash(conditions)))
7
7
  end
8
8
 
9
9
  def self.create(user_id, params={})
@@ -15,7 +15,7 @@ module DataCatalog
15
15
  end
16
16
 
17
17
  def self.first(user_id, conditions={})
18
- one(http_get(uri(user_id), :query => conditions).first)
18
+ one(http_get(uri(user_id), :query => query_hash(conditions)).first)
19
19
  end
20
20
 
21
21
  def self.get(user_id, id)
@@ -28,7 +28,7 @@ module DataCatalog
28
28
 
29
29
  # == Helpers
30
30
 
31
- def self.uri(user_id, id = nil)
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
@@ -3,27 +3,33 @@ module DataCatalog
3
3
  class Organization < Base
4
4
 
5
5
  def self.all(conditions={})
6
- many(http_get("/organizations", :query => conditions))
6
+ many(http_get(uri, :query => query_hash(conditions)))
7
7
  end
8
8
 
9
9
  def self.create(params={})
10
- one(http_post("/organizations", :body => params))
10
+ one(http_post(uri, :body => params))
11
11
  end
12
12
 
13
- def self.destroy(organization_id)
14
- one(http_delete("/organizations/#{organization_id}"))
13
+ def self.destroy(id)
14
+ one(http_delete(uri(id)))
15
15
  end
16
16
 
17
17
  def self.first(conditions={})
18
- one(http_get("/organizations", :query => conditions).first)
18
+ one(http_get(uri, :query => query_hash(conditions)).first)
19
19
  end
20
20
 
21
21
  def self.get(id)
22
- one(http_get("/organizations/#{id}"))
22
+ one(http_get(uri(id)))
23
23
  end
24
24
 
25
- def self.update(organization_id, params={})
26
- one(http_put("/organizations/#{organization_id}", :body => params))
25
+ def self.update(id, params={})
26
+ one(http_put(uri(id), :body => params))
27
+ end
28
+
29
+ # == Helpers
30
+
31
+ def self.uri(id=nil)
32
+ "/organizations/#{id}"
27
33
  end
28
34
 
29
35
  end
@@ -3,27 +3,33 @@ module DataCatalog
3
3
  class Source < Base
4
4
 
5
5
  def self.all(conditions={})
6
- many(http_get("/sources", :query => query_hash(conditions)))
6
+ many(http_get(uri, :query => query_hash(conditions)))
7
7
  end
8
8
 
9
9
  def self.create(params={})
10
- one(http_post("/sources", :body => params))
10
+ one(http_post(uri, :body => params))
11
11
  end
12
12
 
13
- def self.destroy(source_id)
14
- one(http_delete("/sources/#{source_id}"))
13
+ def self.destroy(id)
14
+ one(http_delete(uri(id)))
15
15
  end
16
16
 
17
- def self.first(conditions={})
18
- one(http_get("/sources", :query => query_hash(conditions)).first)
17
+ def self.first(conditions= {})
18
+ one(http_get(uri, :query => query_hash(conditions)).first)
19
19
  end
20
20
 
21
21
  def self.get(id)
22
- one(http_get("/sources/#{id}"))
22
+ one(http_get(uri(id)))
23
23
  end
24
24
 
25
- def self.update(source_id, params={})
26
- one(http_put("/sources/#{source_id}", :body => params))
25
+ def self.update(id, params={})
26
+ one(http_put(uri(id), :body => params))
27
+ end
28
+
29
+ # == Helpers
30
+
31
+ def self.uri(id=nil)
32
+ "/sources/#{id}"
27
33
  end
28
34
 
29
35
  end
@@ -3,35 +3,35 @@ module DataCatalog
3
3
  class User < Base
4
4
 
5
5
  def self.all(conditions={})
6
- many(http_get("/users", :query => conditions))
6
+ many(http_get(uri, :query => query_hash(conditions)))
7
7
  end
8
8
 
9
9
  def self.create(params={})
10
- with_api_keys(one(http_post("/users", :body => params)))
10
+ with_api_keys(one(http_post(uri, :body => params)))
11
11
  end
12
12
 
13
- def self.destroy(user_id)
14
- one(http_delete("/users/#{user_id}"))
13
+ def self.destroy(id)
14
+ one(http_delete(uri(id)))
15
15
  end
16
16
 
17
17
  def self.first(conditions={})
18
- one(http_get("/users", :query => conditions).first)
18
+ one(http_get(uri, :query => query_hash(conditions)).first)
19
19
  end
20
20
 
21
21
  def self.get(id)
22
- with_api_keys(one(http_get("/users/#{id}")))
22
+ with_api_keys(one(http_get(uri(id))))
23
23
  end
24
24
 
25
25
  def self.get_by_api_key(api_key)
26
26
  DataCatalog.with_key(api_key) do
27
27
  checkup = one(http_get("/checkup"))
28
- raise NotFound unless checkup.valid_api_key
28
+ raise NotFound if checkup.api_key != "valid"
29
29
  get(checkup.user.id)
30
30
  end
31
31
  end
32
32
 
33
- def self.update(user_id, params)
34
- one(http_put("/users/#{user_id}", :body => params))
33
+ def self.update(id, params)
34
+ one(http_put(uri(id), :body => params))
35
35
  end
36
36
 
37
37
  # == Helpers
@@ -41,6 +41,10 @@ module DataCatalog
41
41
  user
42
42
  end
43
43
 
44
+ def self.uri(id=nil)
45
+ "/users/#{id}"
46
+ end
47
+
44
48
  # == Instance Methods
45
49
 
46
50
  def delete_api_key!(api_key_id)
data/spec/base_spec.rb CHANGED
@@ -127,10 +127,16 @@ describe Base do
127
127
  end
128
128
 
129
129
  describe ".filterize" do
130
- it "should create a properly formatted filter string" do
131
- s = Base.filterize(:name => "John", :zip => "20036")
132
- s.should == 'name:"John" zip:"20036"'
133
- end
130
+ it "should work with 1 param" do
131
+ %(name:"John Doe").should == Base.filterize(:name => "John Doe")
132
+ end
133
+
134
+ it "should work with 2 params" do
135
+ [
136
+ %(zip:"20036" name:"John Doe"),
137
+ %(name:"John Doe" zip:"20036")
138
+ ].should include(Base.filterize(:name => "John Doe", :zip => "20036"))
139
+ end
134
140
  end
135
141
 
136
142
  end
@@ -6,7 +6,7 @@ describe Organization do
6
6
  def create_3_organizations
7
7
  @organization_names = ["Federal Communications Commission", "Federal Election Commission", "Department of State"]
8
8
  @organization_names.each do |name|
9
- Organization.create(:name => name)
9
+ Organization.create(:name => name, :org_type => "governmental")
10
10
  end
11
11
  end
12
12
 
@@ -56,7 +56,7 @@ describe Organization do
56
56
  describe ".get" do
57
57
 
58
58
  before do
59
- @organization = Organization.create(:name => "Federal Election Commission")
59
+ @organization = Organization.create(:name => "Federal Election Commission", :org_type => "governmental")
60
60
  end
61
61
 
62
62
  it "should return an organization" do
@@ -76,14 +76,14 @@ describe Organization do
76
76
  describe ".create" do
77
77
 
78
78
  it "should create a new organization when valid params are passed in" do
79
- @organization = Organization.create(:name => "Federal Communications Commission")
79
+ @organization = Organization.create(:name => "Federal Communications Commission", :org_type => "governmental")
80
80
  @organization.should be_an_instance_of(Organization)
81
81
  @organization.name.should == "Federal Communications Commission"
82
82
  end
83
83
 
84
84
  it "should raise BadRequest when a bad URL is passed in" do
85
85
  executing do
86
- Organization.create(:name => "Bad Org", :url => "htt:p//jlkj!3")
86
+ Organization.create(:name => "Bad Org", :url => "htt:p//jlkj!3", :org_type => "governmental")
87
87
  end.should raise_error(BadRequest)
88
88
  end
89
89
 
@@ -92,7 +92,7 @@ describe Organization do
92
92
  describe ".update" do
93
93
 
94
94
  before do
95
- @organization = Organization.create(:name => "Federal Election Commission")
95
+ @organization = Organization.create(:name => "Federal Election Commission", :org_type => "governmental")
96
96
  end
97
97
 
98
98
  it "should update an existing organization from valid params" do
@@ -106,7 +106,7 @@ describe Organization do
106
106
  describe ".destroy" do
107
107
 
108
108
  before do
109
- @organization = Organization.create(:name => "Federal Election Commission")
109
+ @organization = Organization.create(:name => "Federal Election Commission", :org_type => "governmental")
110
110
  end
111
111
 
112
112
  it "should destroy an existing organization" do
data/spec/source_spec.rb CHANGED
@@ -4,8 +4,9 @@ include DataCatalog
4
4
  module SourceHelpers
5
5
  def create_source(params={})
6
6
  valid_params = {
7
- :title => "Some FCC Data",
8
- :url => "http://fcc.gov/somedata.csv"
7
+ :title => "Some FCC Data",
8
+ :url => "http://fcc.gov/somedata.csv",
9
+ :source_type => "dataset"
9
10
  }
10
11
  Source.create(valid_params.merge(params))
11
12
  end
@@ -13,8 +14,9 @@ module SourceHelpers
13
14
  def create_3_sources
14
15
  %w(FCC NASA DOE).each do |name|
15
16
  Source.create({
16
- :title => "#{name} Data",
17
- :url => "http://#{name.downcase}.gov/data.xml"
17
+ :title => "#{name} Data",
18
+ :url => "http://#{name.downcase}.gov/data.xml",
19
+ :source_type => "dataset"
18
20
  })
19
21
  end
20
22
  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.2
4
+ version: 0.3.3
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-10-29 00:00:00 -04:00
13
+ date: 2009-11-03 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -84,11 +84,9 @@ extra_rdoc_files:
84
84
  - README.md
85
85
  files:
86
86
  - .gitignore
87
- - CHANGES.md
88
87
  - LICENSE.md
89
88
  - README.md
90
89
  - Rakefile
91
- - VERSION
92
90
  - datacatalog.gemspec
93
91
  - lib/base.rb
94
92
  - lib/datacatalog.rb
data/CHANGES.md DELETED
@@ -1,2 +0,0 @@
1
- ### 0.1.0 / 2009-08-15
2
- * Initial version
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.2