Class: Soaspec::ExchangeHandler
- Inherits:
-
Object
- Object
- Soaspec::ExchangeHandler
- Extended by:
- HandlerAccessors
- Defined in:
- lib/soaspec/exchange_handlers/exchange_handler.rb
Overview
Inherit this for a class describing how to implement a particular exchange. Has basic methods common for methods defining RSpec tests in YAML
Direct Known Subclasses
Instance Attribute Summary collapse
-
#template_name ⇒ Object
Retrieve the name of the template file to be used in the API request.
Instance Method Summary collapse
-
#convert_to_lower? ⇒ Boolean
Whether all xpaths will be done with XML that is converted to lower case.
-
#default_hash=(hash) ⇒ Object
Set the default hash representing data to be used in making a request This will set the @request_option instance variable too.
-
#elements ⇒ Object
Explicitly defined elements for which a path has been predefined.
-
#expected_mandatory_elements ⇒ Array
Will be used in ‘success_scenarios’ shared examples.
-
#expected_mandatory_json_values ⇒ Hash
Change this through ‘mandatory_json_values’ method to specify json results that must be present in the response Will be used in ‘success_scenarios’ shared examples.
-
#expected_mandatory_xpath_values ⇒ Hash
Change this through ‘mandatory_xpath_values’ method to specify xpath results that must be present in the response Will be used in ‘success_scenarios’ shared examples.
-
#initialize(name = self.class.to_s, _options = {}) ⇒ ExchangeHandler
constructor
Set instance variable name.
-
#request(response) ⇒ Object
Request of API call.
-
#set_remove_key(hash, key) ⇒ Object
Set instance variable and remove it from Hash.
-
#set_remove_keys(hash, keys) ⇒ Object
Set instance variable for each key in hash remove it from Hash.
-
#store(name, value) ⇒ Object
Stores a value in a method that can be accessed by the provided name.
-
#strip_namespaces? ⇒ Boolean
Whether to remove namespaces in xpath assertion automatically.
-
#to_s ⇒ String
Sets api handler variable globally.
-
#use ⇒ Self
Set Api handler used by Exchange class to this handler.
Methods included from HandlerAccessors
attribute, convert_to_lower, default_hash, element, mandatory_elements, mandatory_json_values, mandatory_xpath_values, strip_namespaces
Constructor Details
#initialize(name = self.class.to_s, _options = {}) ⇒ ExchangeHandler
Set instance variable name
20 21 22 23 24 25 26 27 28 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 20 def initialize(name = self.class.to_s, = {}) use @request_option = :hash raise ArgumentError, 'Cannot define both template_name and default_hash' if respond_to?(:template_name_value) && respond_to?(:default_hash_value) @template_name = respond_to?(:template_name_value) ? template_name_value : '' @default_hash = respond_to?(:default_hash_value) ? default_hash_value : {} @name = name end |
Instance Attribute Details
#template_name ⇒ Object
Retrieve the name of the template file to be used in the API request
10 11 12 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 10 def template_name @template_name end |
Instance Method Details
#convert_to_lower? ⇒ Boolean
Returns Whether all xpaths will be done with XML that is converted to lower case.
81 82 83 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 81 def convert_to_lower? false end |
#default_hash=(hash) ⇒ Object
Set the default hash representing data to be used in making a request This will set the @request_option instance variable too
46 47 48 49 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 46 def default_hash=(hash) @request_option = :hash @default_hash = Soaspec.always_use_keys? ? hash.transform_keys_to_symbols : hash end |
#elements ⇒ Object
Explicitly defined elements for which a path has been predefined
13 14 15 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 13 def elements public_methods.select { |i| i[/__custom_path_.+/] } end |
#expected_mandatory_elements ⇒ Array
Will be used in ‘success_scenarios’ shared examples. Set though ‘mandatory_elements’ method
62 63 64 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 62 def expected_mandatory_elements [] end |
#expected_mandatory_json_values ⇒ Hash
Change this through ‘mandatory_json_values’ method to specify json results that must be present in the response Will be used in ‘success_scenarios’ shared examples
76 77 78 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 76 def expected_mandatory_json_values {} end |
#expected_mandatory_xpath_values ⇒ Hash
Change this through ‘mandatory_xpath_values’ method to specify xpath results that must be present in the response Will be used in ‘success_scenarios’ shared examples
69 70 71 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 69 def expected_mandatory_xpath_values {} end |
#request(response) ⇒ Object
Request of API call. Either intended request or actual request
116 117 118 119 120 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 116 def request(response) return "Request not yet sent Request option is #{@request_option}" unless response 'Specific API handler should implement this' end |
#set_remove_key(hash, key) ⇒ Object
Set instance variable and remove it from Hash
102 103 104 105 106 107 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 102 def set_remove_key(hash, key) return unless hash.key? key __send__("#{key}=", hash[key]) hash.delete key end |
#set_remove_keys(hash, keys) ⇒ Object
Set instance variable for each key in hash remove it from Hash
95 96 97 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 95 def set_remove_keys(hash, keys) keys.each { |key| set_remove_key(hash, key) } end |
#store(name, value) ⇒ Object
Stores a value in a method that can be accessed by the provided name
88 89 90 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 88 def store(name, value) define_singleton_method('__stored_val__' + name.to_s) { value } end |
#strip_namespaces? ⇒ Boolean
Returns Whether to remove namespaces in xpath assertion automatically.
110 111 112 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 110 def strip_namespaces? false end |
#to_s ⇒ String
Sets api handler variable globally. This is used in ‘Exchange’ class
39 40 41 42 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 39 def to_s use @name.to_s end |
#use ⇒ Self
Set Api handler used by Exchange class to this handler
32 33 34 35 |
# File 'lib/soaspec/exchange_handlers/exchange_handler.rb', line 32 def use Soaspec.api_handler = self self end |