Class: AWS::Core::Options::XMLSerializer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(namespace, operation_name, operation) ⇒ XMLSerializer

Returns a new instance of XMLSerializer.

Parameters:

  • namespace (String)
  • operation_name (String)
  • operation (Hash)


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

#httpHash? (readonly)

Returns:

  • (Hash, nil)


46
47
48
# File 'lib/aws/core/options/xml_serializer.rb', line 46

def http
  @http
end

#namespaceString (readonly)

Returns:

  • (String)


40
41
42
# File 'lib/aws/core/options/xml_serializer.rb', line 40

def namespace
  @namespace
end

#operation_nameString (readonly)

Returns the name of the API operation.

Returns:

  • (String)

    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

#rulesHash (readonly)

Returns:

  • (Hash)


43
44
45
# File 'lib/aws/core/options/xml_serializer.rb', line 43

def rules
  @rules
end

#validatorValidator (readonly)

Returns:



49
50
51
# File 'lib/aws/core/options/xml_serializer.rb', line 49

def validator
  @validator
end

Instance Method Details

#serialize!(request_options) ⇒ String

Returns an string of the request parameters serialized into XML.

Parameters:

  • request_options (Hash)

    A hash of already validated request options with normalized values.

Returns:

  • (String)

    Returns an string of the request parameters serialized into XML.



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 request_options
  if http && http[:request_payload]
    payload = http[:request_payload]
    root_node_name = rules[payload][:name]
    params = request_options[payload]
    rules = self.rules[payload][:members]
  else
    root_node_name = "#{operation_name}Request"
    params = request_options
    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