Class: Soap::Webservice::Request
- Inherits:
-
Object
- Object
- Soap::Webservice::Request
- Defined in:
- lib/soap/webservice/request.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
- #body_params ⇒ Object
- #header_params ⇒ Object
-
#initialize(attributes = {}) ⇒ Request
constructor
A new instance of Request.
- #to_message ⇒ Object
- #to_xml ⇒ Object
- #validate_body_attrs! ⇒ Object
- #validate_header_attrs! ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Request
Returns a new instance of Request.
15 16 17 18 19 |
# File 'lib/soap/webservice/request.rb', line 15 def initialize(attributes = {}) @attributes = attributes validate_header_attrs! validate_body_attrs! end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
13 14 15 |
# File 'lib/soap/webservice/request.rb', line 13 def attributes @attributes end |
Class Method Details
.body_attributes ⇒ Object
10 |
# File 'lib/soap/webservice/request.rb', line 10 def body_attributes; {} end |
.header_attributes ⇒ Object
8 |
# File 'lib/soap/webservice/request.rb', line 8 def header_attributes; {} end |
Instance Method Details
#body_params ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/soap/webservice/request.rb', line 43 def body_params return {} if self.class.body_attributes.nil? self.class.body_attributes.each.with_object({}) do |attr, attrs| name = Soap.to_snakecase(attr[:name]).to_sym value = attributes[name] attrs[name] = value if value end end |
#header_params ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/soap/webservice/request.rb', line 52 def header_params return {} if self.class.header_attributes.nil? self.class.header_attributes.each.with_object({}) do |attr, attrs| name = Soap.to_snakecase(attr[:name]).to_sym value = attributes[name] attrs[name] = value if value end end |
#to_message ⇒ Object
61 62 63 64 65 66 |
# File 'lib/soap/webservice/request.rb', line 61 def { soap_header: header_params, message: body_params } end |
#to_xml ⇒ Object
68 69 70 71 72 73 |
# File 'lib/soap/webservice/request.rb', line 68 def to_xml Gyoku.xml( , key_converter: lambda { |key| Soap.to_camelcase(key) } ) end |
#validate_body_attrs! ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/soap/webservice/request.rb', line 32 def validate_body_attrs! return if required_body.empty? if !required_body.empty? && attributes.empty? raise "Required attributes are missing: #{required_body}" end if !(required_body - attributes.keys).empty? raise "Attribute #{required_body - attributes.keys} must be present" end end |
#validate_header_attrs! ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/soap/webservice/request.rb', line 21 def validate_header_attrs! return if required_header.empty? if !required_header.empty? && attributes.empty? raise "Required attributes are missing: #{required_header}" end if !(required_header - attributes.keys).empty? raise "Attribute #{required_header - attributes.keys} must be present" end end |