Module: Soaspec::ExchangeExtractor

Included in:
Exchange
Defined in:
lib/soaspec/exchange/exchange_extractor.rb

Overview

Methods for extracting aspects of the traffic for a request / response in an exchange from the ExchangeHandler that it’s tied to

Instance Method Summary collapse

Instance Method Details

#[](path) ⇒ String

Extract value from path api class

Parameters:

  • path (Object)

    Path to return element for api class E.g - for SOAP this is XPath string. For JSON, this is Hash dig Array

Returns:

  • (String)

    Value at path



34
35
36
# File 'lib/soaspec/exchange/exchange_extractor.rb', line 34

def [](path)
  exchange_handler.value_from_path(response, path.to_s)
end

#element?(path) ⇒ Boolean

Returns Whether an element exists at the path.

Returns:

  • (Boolean)

    Whether an element exists at the path



24
25
26
27
28
29
# File 'lib/soaspec/exchange/exchange_extractor.rb', line 24

def element?(path)
  self[path]
  true
rescue NoElementAtPath
  false
end

#methods_for_element(element) ⇒ Object

Parameters:

  • element (String)

    Element to define methods for



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/soaspec/exchange/exchange_extractor.rb', line 39

def methods_for_element(element)
  element_name = element.to_s.split('__custom_path_').last
  define_singleton_method(element_name) do
    exchange_handler.__send__(element, response) # Forward the call onto handler to retrieve the element for the response
  end
  define_singleton_method("#{element_name}?") do
    begin
      __send__ element_name
      true
    rescue NoElementAtPath
      false
    end
  end
end

#requestObject

Request of API call. Either intended request or actual request



13
14
15
# File 'lib/soaspec/exchange/exchange_extractor.rb', line 13

def request
  exchange_handler.request(@response)
end

#status_codeInteger

Get status code from api class. This is http response for Web Api

Returns:

  • (Integer)

    Status code from api class



19
20
21
# File 'lib/soaspec/exchange/exchange_extractor.rb', line 19

def status_code
  exchange_handler.status_code_for(response)
end

#to_hashHash

Returns Hash representing the response of the API.

Returns:

  • (Hash)

    Hash representing the response of the API



55
56
57
# File 'lib/soaspec/exchange/exchange_extractor.rb', line 55

def to_hash
  exchange_handler.to_hash(response)
end

#values_from_path(path, attribute: nil) ⇒ Array

Returns List of values found at path.

Parameters:

  • path (String)

    XPath, JSONPath to extract value

  • attribute (String) (defaults to: nil)

    Attribute to obtain from XML element

Returns:

  • (Array)

    List of values found at path



8
9
10
# File 'lib/soaspec/exchange/exchange_extractor.rb', line 8

def values_from_path(path, attribute: nil)
  exchange_handler.values_from_path(response, path, attribute: attribute)
end