Class: Uber::Response::ParseJson
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- Uber::Response::ParseJson
- Defined in:
- lib/uber/parse_json.rb
Constant Summary collapse
- WHITESPACE_REGEX =
/\A^\s*$\z/
Instance Method Summary collapse
Instance Method Details
#on_complete(response) ⇒ Object
18 19 20 |
# File 'lib/uber/parse_json.rb', line 18 def on_complete(response) response.body = parse(response.body) if respond_to?(:parse) && !unparsable_status_codes.include?(response.status) end |
#parse(body) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/uber/parse_json.rb', line 9 def parse(body) case body when WHITESPACE_REGEX, nil nil else JSON.parse(body, :symbolize_names => true) end end |
#unparsable_status_codes ⇒ Object
22 23 24 |
# File 'lib/uber/parse_json.rb', line 22 def unparsable_status_codes [204, 301, 302, 304] end |