datacatalog 0.4.12 → 0.4.13

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/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.12'
8
+ gem.version = '0.4.13'
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}
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{datacatalog}
8
- s.version = "0.4.12"
8
+ s.version = "0.4.13"
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{2010-03-17}
12
+ s.date = %q{2010-04-13}
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 = [
@@ -48,9 +48,9 @@ module DataCatalog
48
48
  rescue JSON::ParserError
49
49
  nil
50
50
  end
51
- if !parsed_response_body.empty?
51
+ if parsed_response_body
52
52
  e.parsed_response_body = parsed_response_body
53
- if parsed_response_body["errors"]
53
+ if parsed_response_body.is_a?(Hash) && parsed_response_body["errors"]
54
54
  e.errors = parsed_response_body["errors"]
55
55
  end
56
56
  end
@@ -89,7 +89,9 @@ module DataCatalog
89
89
  "#{k}" + if v.is_a?(Regexp)
90
90
  %(:"#{v.source}")
91
91
  elsif v.is_a?(Integer) || v.is_a?(TrueClass) || v.is_a?(FalseClass)
92
- %(=#{v})
92
+ %(=#{v})
93
+ elsif v.is_a?(Array)
94
+ %(=#{v.join(',')})
93
95
  else
94
96
  %(="#{v}")
95
97
  end
@@ -39,9 +39,9 @@ module DataCatalog
39
39
  def self.with_key(temp_key)
40
40
  original_key = DataCatalog.api_key
41
41
  DataCatalog.api_key = temp_key
42
- result = yield
42
+ yield
43
+ ensure
43
44
  DataCatalog.api_key = original_key
44
- result
45
45
  end
46
46
 
47
47
  end
@@ -57,31 +57,61 @@ describe Base do
57
57
  end
58
58
 
59
59
  describe ".error" do
60
- it "should return an 'Unable to parse:' message when body is blank" do
60
+ it "should ... when body is blank" do
61
61
  response = HTTParty::Response.new(nil, '', 404, 'Not Found', {})
62
- Base.error(response).should == %(Unable to parse: "")
62
+ begin
63
+ e = Base.error(NotFound, response)
64
+ rescue NotFound => e
65
+ e.response_body.should == ''
66
+ e.parsed_response_body.should == nil
67
+ e.errors.should == nil
68
+ end
63
69
  end
64
70
 
65
- it "should return 'Response was empty' when body is an empty JSON object" do
71
+ it "should be correct when body is an empty hash" do
66
72
  response = HTTParty::Response.new(nil, '{}', 404, 'Not Found', {})
67
- Base.error(response).should == "Response was empty"
73
+ begin
74
+ e = Base.error(NotFound, response).should == "Response was empty"
75
+ rescue NotFound => e
76
+ e.response_body.should == '{}'
77
+ e.parsed_response_body.should == {}
78
+ e.errors.should == nil
79
+ end
68
80
  end
69
81
 
70
- it "should return 'Response was empty' when body is an empty array" do
82
+ it "should be correct when body is an empty array" do
71
83
  response = HTTParty::Response.new(nil, '[]', 404, 'Not Found', {})
72
- Base.error(response).should == "Response was empty"
84
+ begin
85
+ e = Base.error(NotFound, response)
86
+ rescue NotFound => e
87
+ e.response_body.should == '[]'
88
+ e.parsed_response_body.should == []
89
+ e.errors.should == nil
90
+ end
73
91
  end
74
92
 
75
- it "should return the contents of the errors hash when it exists" do
93
+ it "should be correct when body has errors hash" do
76
94
  errors = '{"errors":["bad_error"]}'
77
95
  response = HTTParty::Response.new(nil, errors, 400, 'Bad Request', {})
78
- Base.error(response).should == '["bad_error"]'
96
+ begin
97
+ e = Base.error(BadRequest, response)
98
+ rescue BadRequest => e
99
+ e.response_body.should == '{"errors":["bad_error"]}'
100
+ e.parsed_response_body.should == {"errors" => ["bad_error"]}
101
+ e.errors.should == ["bad_error"]
102
+ end
79
103
  end
80
104
 
81
- it "should return the contents of the response body when no errors hash exists" do
105
+ it "should be correct when body has hash" do
82
106
  errors = '{"foo":["bar"]}'
83
107
  response = HTTParty::Response.new(nil, errors, 400, 'Bad Request', {})
84
- Base.error(response).should == '{"foo":["bar"]}'
108
+ begin
109
+ e = Base.error(BadRequest, response)
110
+ rescue BadRequest => e
111
+ e.response_body.should == '{"foo":["bar"]}'
112
+ e.parsed_response_body.should == {"foo" => ["bar"]}
113
+ e.errors.should == nil
114
+ end
85
115
  end
86
116
  end
87
117
 
@@ -130,6 +160,10 @@ describe Base do
130
160
  it "should work with periods" do
131
161
  Base.filterize('released.year' => 2008).should == %(released.year=2008)
132
162
  end
163
+
164
+ it "should support 'or' by converting arrays to commas" do
165
+ Base.filterize('id' => [800, 801, 802]).should == %(id=800,801,802)
166
+ end
133
167
 
134
168
  it "should pass through strings" do
135
169
  ["count > 0", "count >= 1"].each do |s|
@@ -31,6 +31,18 @@ describe DataCatalog do
31
31
  42
32
32
  end.should == 42
33
33
  end
34
+
35
+ it "should still reset the API key when the block throws an exception" do
36
+ regular_key = '4159179f32ff8fefd2c6d48b7e675e7736bf1357'
37
+ DataCatalog.api_key = regular_key
38
+ temporary_key = '0000123400001234000012340000123400001234'
39
+ expect {
40
+ DataCatalog.with_key(temporary_key) do
41
+ raise Exception
42
+ end
43
+ }.to raise_error(Exception)
44
+ DataCatalog.api_key.should == regular_key
45
+ end
34
46
  end
35
47
 
36
48
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 12
9
- version: 0.4.12
8
+ - 13
9
+ version: 0.4.13
10
10
  platform: ruby
11
11
  authors:
12
12
  - Luigi Montanez
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-03-17 00:00:00 -04:00
18
+ date: 2010-04-13 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency