citygrid_api 0.0.19 → 0.0.20
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 +1 -1
- data/citygrid_api.gemspec +2 -2
- data/lib/citygrid/api.rb +11 -4
- data/lib/citygrid/citygrid_exceptions.rb +8 -15
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.20
|
data/citygrid_api.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "citygrid_api"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.20"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Elpizo Choi"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-10-22"
|
13
13
|
s.description = "Ruby wrapper for CityGrid APIs"
|
14
14
|
s.email = "fu7iin@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/citygrid/api.rb
CHANGED
@@ -182,12 +182,19 @@ class CityGrid
|
|
182
182
|
|
183
183
|
begin
|
184
184
|
response = req.perform
|
185
|
-
rescue => ex
|
186
|
-
|
185
|
+
rescue => ex
|
186
|
+
if defined?(Rails.logger)
|
187
|
+
Rails.logger.error safe_req_options
|
188
|
+
Rails.logger.error req_to_output
|
189
|
+
Rails.logger.error req_for_airbrake
|
190
|
+
Rails.logger.error ex
|
191
|
+
end
|
192
|
+
raise CityGridExceptions::RequestError.new req_for_airbrake, nil, ex.message, req_to_output.to_curl
|
187
193
|
ensure
|
188
194
|
if CityGrid.print_curls?
|
189
195
|
if defined?(Rails.logger)
|
190
196
|
Rails.logger.info req_to_output.to_curl
|
197
|
+
puts req_to_output.to_curl
|
191
198
|
else
|
192
199
|
puts req_to_output.to_curl
|
193
200
|
end
|
@@ -200,11 +207,11 @@ class CityGrid
|
|
200
207
|
# catch unparsable responses (html etc)
|
201
208
|
if !response.parsed_response.is_a?(Hash)
|
202
209
|
#pp "[gem] the response was unparsable (response was not a hash)"
|
203
|
-
raise CityGridExceptions::ResponseParseError.new req_for_airbrake, response
|
210
|
+
raise CityGridExceptions::ResponseParseError.new req_for_airbrake, response, "the response was unparsable (response was not a hash)", req_to_output.to_curl
|
204
211
|
else
|
205
212
|
# Parse and handle new response codes
|
206
213
|
if !response_status.nil? && response_status["code"] != "SUCCESS" && response_status["code"] != 200
|
207
|
-
raise CityGridExceptions.appropriate_error(response_status["code"]).new req_for_airbrake, response, response_status["message"].to_s
|
214
|
+
raise CityGridExceptions.appropriate_error(response_status["code"]).new req_for_airbrake, response, response_status["message"].to_s, req_to_output.to_curl
|
208
215
|
else
|
209
216
|
return CityGrid::API::Response.new response
|
210
217
|
end
|
@@ -3,11 +3,12 @@ module CityGridExceptions
|
|
3
3
|
# Define parent error classes
|
4
4
|
# All errors thrown in the API should extend APIError - Level 1
|
5
5
|
class APIError < StandardError
|
6
|
-
attr_accessor :request, :response
|
6
|
+
attr_accessor :request, :response, :curl
|
7
7
|
|
8
|
-
def initialize request, response, msg = "An API error occurred"
|
8
|
+
def initialize request, response, msg = "An API error occurred", curl=nil
|
9
9
|
@request = request
|
10
10
|
@response = response
|
11
|
+
@curl = curl
|
11
12
|
super msg
|
12
13
|
end
|
13
14
|
end
|
@@ -19,10 +20,11 @@ module CityGridExceptions
|
|
19
20
|
|
20
21
|
class ResponseParseError < APIError
|
21
22
|
attr_accessor :server_msg, :description, :raw_response
|
22
|
-
def initialize request, response, msg = nil
|
23
|
+
def initialize request, response, msg = nil, curl=nil
|
23
24
|
self.raw_response = response
|
24
25
|
# parse Tomcat error report
|
25
|
-
|
26
|
+
Rails.logger.error response.body if defined?(Rails.logger)
|
27
|
+
if response.body.include?("<title>Apache Tomcat.* - Error report<\/title>")
|
26
28
|
response.scan(/<p><b>(message|description)<\/b> *<u>(.*?)<\/u><\/p>/).each do |match|
|
27
29
|
case match[0]
|
28
30
|
when "message"
|
@@ -150,8 +152,8 @@ module CityGridExceptions
|
|
150
152
|
{
|
151
153
|
0 => ResponseError, nil => ResponseParseError, "" => ResponseParseError, 400 => RequestError,
|
152
154
|
401 => AuthenticationError, 403 => RequestError, 405 => RequestError, 406 => HeaderError,
|
153
|
-
409 => RequestError, 410 => RequestError, 415 => RequestError, 413 => RequestError, 414 => RequestError,
|
154
|
-
|
155
|
+
409 => RequestError, 410 => RequestError, 415 => RequestError, 413 => RequestError, 414 => RequestError,
|
156
|
+
500 => ResponseError, "CONTENT_API_ERROR" => ContentApiError, "SYSTEM_ERROR_TRY_AGAIN" => SystemErrorTryAgainError,
|
155
157
|
"SYSTEM_ERROR_UNKNOWN" => SystemErrorUnknownError, "BAD_REQUEST_TYPE" => BadRequestTypeError,
|
156
158
|
"INVALID_REQUEST_BODY" => InvalidRequestBodyError,
|
157
159
|
"HEADER_CONTENT_TYPE_IS_REQUIRED" => ContentTypeRequiredError, "HEADER_CONTENT_TYPE_INVALID" => ContentTypeInvalidError,
|
@@ -188,13 +190,4 @@ module CityGridExceptions
|
|
188
190
|
end
|
189
191
|
end
|
190
192
|
|
191
|
-
def CityGridExceptions.print_superclasses error_code
|
192
|
-
begin
|
193
|
-
raise appropriate_error[error_code]
|
194
|
-
rescue => ex
|
195
|
-
class_hierarchy = ex.class.ancestors
|
196
|
-
class_hierarchy.slice!(class_hierarchy.index(StandardError)..-1)
|
197
|
-
return class_hierarchy.reverse.join("::")
|
198
|
-
end
|
199
|
-
end
|
200
193
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: citygrid_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.20
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Elpizo Choi
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-10-22 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|