Class: AWS::Core::Options::XMLSerializer
- Inherits:
-
Object
- Object
- AWS::Core::Options::XMLSerializer
- Defined in:
- lib/aws/core/options/xml_serializer.rb
Overview
Given a hash of serialization rules, an XMLSerializer can convert a hash of request options into XML. The request options are validated before returning XML.
Instance Attribute Summary collapse
- #http ⇒ Hash? readonly
- #namespace ⇒ String readonly
-
#operation_name ⇒ String
readonly
Returns the name of the API operation.
- #rules ⇒ Hash readonly
- #validator ⇒ Validator readonly
Instance Method Summary collapse
-
#initialize(namespace, operation_name, operation) ⇒ XMLSerializer
constructor
A new instance of XMLSerializer.
- #serialize!(request_options) ⇒ String
Constructor Details
#initialize(namespace, operation_name, operation) ⇒ XMLSerializer
Returns a new instance of XMLSerializer.
28 29 30 31 32 33 34 |
# File 'lib/aws/core/options/xml_serializer.rb', line 28 def initialize namespace, operation_name, operation @namespace = namespace @operation_name = operation_name @rules = operation[:inputs] @http = operation[:http] @validator = Validator.new(rules) end |
Instance Attribute Details
#http ⇒ Hash? (readonly)
46 47 48 |
# File 'lib/aws/core/options/xml_serializer.rb', line 46 def http @http end |
#namespace ⇒ String (readonly)
40 41 42 |
# File 'lib/aws/core/options/xml_serializer.rb', line 40 def namespace @namespace end |
#operation_name ⇒ String (readonly)
Returns the name of the API operation.
37 38 39 |
# File 'lib/aws/core/options/xml_serializer.rb', line 37 def operation_name @operation_name end |
#rules ⇒ Hash (readonly)
43 44 45 |
# File 'lib/aws/core/options/xml_serializer.rb', line 43 def rules @rules end |
#validator ⇒ Validator (readonly)
49 50 51 |
# File 'lib/aws/core/options/xml_serializer.rb', line 49 def validator @validator end |
Instance Method Details
#serialize!(request_options) ⇒ String
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/aws/core/options/xml_serializer.rb', line 56 def serialize if http && http[:request_payload] payload = http[:request_payload] root_node_name = rules[payload][:name] params = [payload] rules = self.rules[payload][:members] else root_node_name = "#{operation_name}Request" params = rules = self.rules end xml = Nokogiri::XML::Builder.new xml.send(root_node_name, :xmlns => namespace) do |xml| hash_members_xml(params, rules, xml) end xml.doc.root.to_xml end |