Class: Chain::Middleware::HashieMashResponse

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/chain/middleware/hashie_mash_response.rb

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/chain/middleware/hashie_mash_response.rb', line 4

def on_complete(env)
  body = JSON.parse(env[:body].to_s.encode('UTF-8', {:invalid => :replace, :undef => :replace, :replace => '?'}))
  headers = env[:response_headers]
  env[:body] = Hashie::Mash.new(body).tap do |item|
    item._headers = Hashie::Mash.new(headers)
    item._status  = env[:status]
  end
end