Class: ZaloAPI::Middleware::Response::ParseJson
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- ZaloAPI::Middleware::Response::ParseJson
- Defined in:
- lib/zalo_api/middleware/response/parse_json.rb
Constant Summary collapse
- CONTENT_TYPE =
'Content-Type'- VALUES =
['application/json', 'text/json']
Instance Method Summary collapse
Instance Method Details
#on_complete(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/zalo_api/middleware/response/parse_json.rb', line 11 def on_complete(env) type = env[:response_headers][CONTENT_TYPE].to_s type = type.split(';', 2).first if type.index(';') return unless VALUES.include?(type) unless env[:body].strip.empty? env[:body] = JSON.parse(env[:body], symbolize_names: true) end end |