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, rules) ⇒ XMLSerializer

Returns a new instance of XMLSerializer.

Parameters:

  • namespace (String)
  • operation_name (String)
  • rules (Hash)

    A hash of option rules to validate against.



28
29
30
31
32
33
# File 'lib/aws/core/options/xml_serializer.rb', line 28

def initialize namespace, operation_name, rules
  @namespace = namespace
  @operation_name = operation_name
  @rules = rules
  @validator = Validator.new(rules)
end

Instance Attribute Details

#namespaceString (readonly)

Returns:

  • (String)


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

def namespace
  @namespace
end

#operation_nameString (readonly)

Returns the name of the API operation.

Returns:

  • (String)

    Returns the name of the API operation.



36
37
38
# File 'lib/aws/core/options/xml_serializer.rb', line 36

def operation_name
  @operation_name
end

#rulesHash (readonly)

Returns:

  • (Hash)


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

def rules
  @rules
end

#validatorValidator (readonly)

Returns:



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

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.



52
53
54
55
56
57
58
# File 'lib/aws/core/options/xml_serializer.rb', line 52

def serialize request_options
  xml = Nokogiri::XML::Builder.new
  xml.send("#{operation_name}Request", :xmlns => namespace) do |xml|
    hash_members_xml(request_options, rules, xml)
  end
  xml.doc.root.to_xml
end