datacatalog 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
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.1"
8
+ s.version = "0.3.2"
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-22}
12
+ s.date = %q{2009-10-29}
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 = [
data/lib/base.rb CHANGED
@@ -69,9 +69,30 @@ module DataCatalog
69
69
  end
70
70
 
71
71
  def self.one(response)
72
+ return true if response && response.respond_to?(:code) && response.code == 204
72
73
  response.blank? ? nil : new(response)
73
74
  end
74
75
 
76
+ def self.query_hash(conditions)
77
+ if conditions.empty?
78
+ query_hash = {}
79
+ else
80
+ query_hash = {:filter => filterize(conditions)}
81
+ end
82
+ end
83
+
84
+ 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!
94
+ end
95
+
75
96
  def method_missing(method_name, *args)
76
97
  if method_name.to_s.match(/.*_(on|at)\z/)
77
98
  return Time.parse(super)
data/lib/datacatalog.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'activesupport'
3
+ gem 'luigi-httparty'
3
4
  require 'httparty'
4
5
  require 'mash'
5
6
 
@@ -2,8 +2,8 @@ module DataCatalog
2
2
 
3
3
  class Source < Base
4
4
 
5
- def self.all(conditions={})
6
- many(http_get("/sources", :query => conditions))
5
+ def self.all(conditions={})
6
+ many(http_get("/sources", :query => query_hash(conditions)))
7
7
  end
8
8
 
9
9
  def self.create(params={})
@@ -15,7 +15,7 @@ module DataCatalog
15
15
  end
16
16
 
17
17
  def self.first(conditions={})
18
- one(http_get("/sources", :query => conditions).first)
18
+ one(http_get("/sources", :query => query_hash(conditions)).first)
19
19
  end
20
20
 
21
21
  def self.get(id)
data/spec/base_spec.rb CHANGED
@@ -125,5 +125,12 @@ describe Base do
125
125
  hash.should be_nil
126
126
  end
127
127
  end
128
+
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
134
+ end
128
135
 
129
136
  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.1
4
+ version: 0.3.2
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-22 00:00:00 -04:00
13
+ date: 2009-10-29 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency