Class: Soaspec::RestHandler
- Defined in:
- lib/soaspec/rest_handler.rb
Overview
Wraps around Savon client defining default values dependent on the soap request
Instance Attribute Summary collapse
-
#client ⇒ Object
Savon client used to make SOAP calls.
-
#operation ⇒ Object
SOAP Operation to use by default.
Attributes inherited from Tester
Instance Method Summary collapse
-
#base_url ⇒ Object
Override in class.
-
#default_options ⇒ Hash
Default Savon options.
- #include_in_body?(response, expected) ⇒ Boolean
-
#initialize(name, specific_options = {}) ⇒ RestHandler
constructor
Setup object to handle communicating with a particular SOAP WSDL.
-
#logging_options ⇒ Object
Options to log xml request and response.
-
#make_request(override_parameters) ⇒ Object
Used in together with Exchange request that passes such override parameters.
-
#mandatory_elements ⇒ Array
Override this to specify elements that must be present in the response Will be used in ‘success_scenarios’ shared examples.
-
#mandatory_xpath_values ⇒ Hash
Override this to specify xpath results that must be present in the response Will be used in ‘success_scenarios’ shared examples.
- #name(name) ⇒ Object
- #override(request_parameters) ⇒ Object
-
#rest_resource_options ⇒ Hash
Add values to here when extending this class to have default REST options.
-
#root_attributes ⇒ Object
Attributes set at the root XML element of SOAP request.
- #status_code_for(response) ⇒ Object
- #value_from_path(exchange, path) ⇒ Object
-
#xpath_value_for(param) ⇒ Object
Returns the value at the provided xpath.
Methods inherited from Tester
Constructor Details
#initialize(name, specific_options = {}) ⇒ RestHandler
Setup object to handle communicating with a particular SOAP WSDL
45 46 47 48 49 50 51 |
# File 'lib/soaspec/rest_handler.rb', line 45 def initialize(name, = {}) = .merge .merge! .merge!() @resource = RestClient::Resource.new(base_url, options: ) # @resource[url_extension].get super end |
Instance Attribute Details
#client ⇒ Object
Savon client used to make SOAP calls
10 11 12 |
# File 'lib/soaspec/rest_handler.rb', line 10 def client @client end |
#operation ⇒ Object
SOAP Operation to use by default
12 13 14 |
# File 'lib/soaspec/rest_handler.rb', line 12 def operation @operation end |
Instance Method Details
#base_url ⇒ Object
Override in class
31 32 33 |
# File 'lib/soaspec/rest_handler.rb', line 31 def base_url '' end |
#default_options ⇒ Hash
Default Savon options. See savonrb.com/version2/globals.html for details
23 24 25 26 27 28 |
# File 'lib/soaspec/rest_handler.rb', line 23 def { # method: :get # headers: { content_type: 'text/plain' } } end |
#include_in_body?(response, expected) ⇒ Boolean
72 73 74 |
# File 'lib/soaspec/rest_handler.rb', line 72 def include_in_body?(response, expected) response.body.include? expected end |
#logging_options ⇒ Object
Options to log xml request and response
15 16 17 18 19 |
# File 'lib/soaspec/rest_handler.rb', line 15 def { # See request and response. (Put this in traffic file) } end |
#make_request(override_parameters) ⇒ Object
Used in together with Exchange request that passes such override parameters
65 66 67 68 69 70 |
# File 'lib/soaspec/rest_handler.rb', line 65 def make_request(override_parameters) test_values = override_parameters test_values[:params] ||= {} @resource[test_values[:suburl]].send(test_values[:method].to_s, test_values[:params]) end |
#mandatory_elements ⇒ Array
Override this to specify elements that must be present in the response Will be used in ‘success_scenarios’ shared examples
83 84 85 |
# File 'lib/soaspec/rest_handler.rb', line 83 def mandatory_elements [] end |
#mandatory_xpath_values ⇒ Hash
Override this to specify xpath results that must be present in the response Will be used in ‘success_scenarios’ shared examples
90 91 92 |
# File 'lib/soaspec/rest_handler.rb', line 90 def mandatory_xpath_values {} end |
#name(name) ⇒ Object
53 54 55 56 57 |
# File 'lib/soaspec/rest_handler.rb', line 53 def name(name) @test_values = {} @test_name = name self end |
#override(request_parameters) ⇒ Object
59 60 61 62 |
# File 'lib/soaspec/rest_handler.rb', line 59 def override(request_parameters) @test_values = request_parameters self end |
#rest_resource_options ⇒ Hash
Add values to here when extending this class to have default REST options. See rest client resource for details
38 39 40 41 |
# File 'lib/soaspec/rest_handler.rb', line 38 def { } end |
#root_attributes ⇒ Object
Attributes set at the root XML element of SOAP request
95 96 97 |
# File 'lib/soaspec/rest_handler.rb', line 95 def root_attributes nil end |
#status_code_for(response) ⇒ Object
76 77 78 |
# File 'lib/soaspec/rest_handler.rb', line 76 def status_code_for(response) response.code end |
#value_from_path(exchange, path) ⇒ Object
114 115 116 117 |
# File 'lib/soaspec/rest_handler.rb', line 114 def value_from_path(exchange, path) path = '//' + path if path[0] != '/' xpath_value_for(exchange: exchange, xpath: path) end |
#xpath_value_for(param) ⇒ Object
Returns the value at the provided xpath
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/soaspec/rest_handler.rb', line 100 def xpath_value_for(param) result = if Soaspec::Environment.strip_namespaces? && !param[:xpath].include?(':') temp_doc = param[:exchange].response.doc temp_doc.remove_namespaces! temp_doc.xpath(param[:xpath]).first else puts 'no strip' + param[:xpath] param[:exchange].response.xpath(param[:xpath]).first end raise NoElementAtXpath, "No value at Xpath '#{param[:xpath]}'" unless result result.inner_text end |