Class: Taxy::Response::ParseJson
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- Taxy::Response::ParseJson
- Defined in:
- lib/response/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 21 |
# File 'lib/response/parse_json.rb', line 18 def on_complete(response) return if unparsable_status_codes.include?(response.status) response.body = parse(response.body) if respond_to?(:parse) end |
#parse(body) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/response/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
23 24 25 |
# File 'lib/response/parse_json.rb', line 23 def unparsable_status_codes [204, 301, 302, 304] end |