Class: Malcolm::SOAPParser

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

Overview

Response middleware that unwraps a SOAP envelope for you

Instance Method Summary collapse

Constructor Details

#initialize(env, *args) ⇒ SOAPParser

Returns a new instance of SOAPParser.



4
5
6
7
# File 'lib/malcolm/response/soap_parser.rb', line 4

def initialize(env, *args)
  key = args[0]
  super(env)
end

Instance Method Details

#on_complete(env) ⇒ Object

Expects response XML to already be parsed

Raises:



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/malcolm/response/soap_parser.rb', line 10

def on_complete(env)
  env[:body] = Nori.new(
    strip_namespaces: true,
    convert_tags_to: ->(tag) { tag.snakecase.to_sym }
  ).parse(env[:body])

  raise SOAPError, "Invalid SOAP response" if env[:body].empty?

  env[:body] = env[:body][:envelope][:body]
  env[:body] = find_key_in_hash(env[:body], @key)
end