Class: WorkSnaps::Response::ParseXML

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/worksnaps/response/parse_xml.rb

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



17
18
19
20
21
# File 'lib/worksnaps/response/parse_xml.rb', line 17

def on_complete(env)
  if respond_to?(:parse)
    env[:body] = parse(env[:body]) unless [204, 301, 302, 304].include?(env[:status])
  end
end

#parse(body) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/worksnaps/response/parse_xml.rb', line 8

def parse(body)
  body = Crack::XML.parse(body)
  if body['method'] == :post or body['method'] == :put
    reply = body.delete('reply')
    body.merge reply if reply.is_a(Hash)
  end
  body
end