Class: Plurky::Response::Mashify
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- Plurky::Response::Mashify
- Defined in:
- lib/plurky/response/mashify.rb
Instance Method Summary collapse
-
#on_complete(env) ⇒ Object
Overrides Faraday::Response::Middleware#on_complete.
- #parse(body) ⇒ Object
Instance Method Details
#on_complete(env) ⇒ Object
Overrides Faraday::Response::Middleware#on_complete
20 21 22 23 24 |
# File 'lib/plurky/response/mashify.rb', line 20 def on_complete(env) unless [204, 301, 302, 304].include?(env[:status]) env[:body] = parse(env[:body]) end end |
#parse(body) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/plurky/response/mashify.rb', line 8 def parse(body) case body when Hash Hashie::Mash.new body when Array body.map { |item| item.is_a?(Hash) ? Hashie::Mash.new(item) : item } else body end end |