Skip to content

Commit

Permalink
Version 1.6.2 of the AWS SDK for Ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorrowe committed Aug 8, 2012
1 parent b3b180b commit 53d960f
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 14 deletions.
31 changes: 31 additions & 0 deletions lib/aws/api_config/Route53-2012-02-29.yml
Expand Up @@ -23,19 +23,23 @@
:hosted_zone_id:
:type: :string
:required: true
:position: 0
:lstrip: /hostedzone/
:change_batch:
:name: ChangeBatch
:type: :hash
:required: true
:position: 1
:members:
:comment:
:name: Comment
:type: :string
:position: 0
:changes:
:name: Changes
:type: :array
:required: true
:position: 1
:members:
:name: Change
:type: :hash
Expand All @@ -44,34 +48,43 @@
:name: Action
:type: :string
:required: true
:position: 0
:resource_record_set:
:name: ResourceRecordSet
:type: :hash
:required: true
:position: 1
:members:
:name:
:name: Name
:type: :string
:required: true
:position: 0
:type:
:name: Type
:type: :string
:required: true
:position: 1
:set_identifier:
:name: SetIdentifier
:type: :string
:position: 2
:weight:
:name: Weight
:type: :integer
:position: 3
:region:
:name: Region
:type: :string
:position: 4
:ttl:
:name: TTL
:type: :integer
:position: 5
:resource_records:
:name: ResourceRecords
:type: :array
:position: 6
:members:
:name: ResourceRecord
:type: :hash
Expand All @@ -80,19 +93,23 @@
:name: Value
:type: :string
:required: true
:position: 0
:alias_target:
:name: AliasTarget
:type: :hash
:position: 7
:members:
:hosted_zone_id:
:name: HostedZoneId
:type: :string
:required: true
:position: 0
:lstrip: /hostedzone/
:dns_name:
:name: DNSName
:type: :string
:required: true
:position: 1
:outputs:
:children:
ChangeInfo:
Expand All @@ -118,17 +135,21 @@
:name: Name
:type: :string
:required: true
:position: 0
:caller_reference:
:name: CallerReference
:type: :string
:required: true
:position: 1
:hosted_zone_config:
:name: HostedZoneConfig
:type: :hash
:position: 2
:members:
:comment:
:name: Comment
:type: :string
:position: 0
:outputs:
:children:
HostedZone:
Expand Down Expand Up @@ -173,6 +194,7 @@
:id:
:type: :string
:required: true
:position: 0
:lstrip: /hostedzone/
:outputs:
:children:
Expand All @@ -195,6 +217,7 @@
:id:
:type: :string
:required: true
:position: 0
:lstrip: /change/
:outputs:
:children:
Expand All @@ -217,6 +240,7 @@
:id:
:type: :string
:required: true
:position: 0
:lstrip: /hostedzone/
:outputs:
:children:
Expand Down Expand Up @@ -251,8 +275,10 @@
:inputs:
:marker:
:type: :string
:position: 0
:max_items:
:type: :integer
:position: 1
:outputs:
:children:
HostedZones:
Expand Down Expand Up @@ -291,15 +317,20 @@
:hosted_zone_id:
:type: :string
:required: true
:position: 0
:lstrip: /hostedzone/
:start_record_name:
:type: :string
:position: 1
:start_record_type:
:type: :string
:position: 2
:start_record_identifier:
:type: :string
:position: 3
:max_items:
:type: :integer
:position: 4
:outputs:
:children:
ResourceRecordSets:
Expand Down
2 changes: 1 addition & 1 deletion lib/aws/core.rb
Expand Up @@ -69,7 +69,7 @@
module AWS

# Current version of the AWS SDK for Ruby
VERSION = "1.6.1"
VERSION = "1.6.2"

register_autoloads(self) do
autoload :Errors, 'errors'
Expand Down
15 changes: 13 additions & 2 deletions lib/aws/core/options/xml_serializer.rb
Expand Up @@ -76,11 +76,16 @@ def to_xml builder, opt_name, rules, value

case value
when Hash

builder.tag!(xml_name) do
value.each_pair do |m_name, m_value|
to_xml(builder, m_name, rules[:members][m_name], m_value)
xml_ordered_members(rules[:members]).each do |member_name|
if value.key?(member_name)
member_value = value[member_name]
to_xml(builder, member_name, rules[:members][member_name], member_value)
end
end
end

when Array
builder.tag!(xml_name) do
value.each do |member_value|
Expand All @@ -92,6 +97,12 @@ def to_xml builder, opt_name, rules, value

end

def xml_ordered_members members
members.inject([]) do |list,(member_name, member)|
list << [member[:position] || 0, member_name]
end.sort_by(&:first).map(&:last)
end

end
end
end
Expand Down
19 changes: 11 additions & 8 deletions lib/aws/core/xml/grammar.rb
Expand Up @@ -16,10 +16,10 @@ module Core
module XML

# A class that simplifies building XML {Parser} rules. This is also
# a compatability layer between the old and new formats of the api
# a compatability layer between the old and new formats of the api
# config.
class Grammar

def initialize rules = {}, options = {}
@rules = rules
@context = @rules
Expand All @@ -28,7 +28,7 @@ def initialize rules = {}, options = {}
options[:inflect_rename] : true
end

# Parses the XML with the rules provided by the current grammar.
# Parses the XML with the rules provided by the current grammar.
# This method is meant to provide backwards compatability with
# the old XmlGrammar class that handled rules and parsing.
# @param [String] xml
Expand Down Expand Up @@ -86,7 +86,7 @@ def self.parse xml

protected

# Performs a deep copy of the rules hash so that it can be
# Performs a deep copy of the rules hash so that it can be
# customized without chaning the parent grammar.
def self.deep_copy rules
rules.inject({}) do |copy,(key,value)|
Expand Down Expand Up @@ -129,6 +129,7 @@ def validate_config_method(method)
allow_methods = %w(
rename attribute_name boolean integer long float list force string
ignore collect_values symbol_value timestamp map_entry map blob
position
)
unless allow_methods.include?(method.to_s)
raise "#{method} cannot be used in configuration"
Expand All @@ -151,21 +152,21 @@ def inflect value
end

##
## customization methods
## customization methods
##

def element element_name, &block

parent_context = @context
parent_element_name = @element_name

@context = context_for_child(element_name)

@element_name = element_name

begin
if block_given?
block.arity == 1 ? yield(parent_element_name) : yield
block.arity == 1 ? yield(parent_element_name) : yield
end
ensure
@context = parent_context
Expand Down Expand Up @@ -223,7 +224,7 @@ def map_entry key_element_name, value_element_name
def map map_element_name, key_element_name, value_element_name
ignore
element(map_element_name) do |parent_element_name|
rename(parent_element_name)
rename(parent_element_name)
map_entry(key_element_name, value_element_name)
end
end
Expand Down Expand Up @@ -285,12 +286,14 @@ def eql? other
end
alias_method :==, :eql?

def position *args; end
def http_trait *args; end
alias_method :http_header, :http_trait
alias_method :http_uri_label, :http_trait
alias_method :http_payload, :http_trait
alias_method :http_status, :http_trait


protected
def context_for_child child_element_name
@context[:children] ||= {}
Expand Down
35 changes: 35 additions & 0 deletions spec/aws/core/options/xml_serializer_spec.rb
Expand Up @@ -149,6 +149,41 @@ module Options
XML
end

context 'with ordered members' do

## route53 cares about the order of sibling xml elements
## so we are adding support for :order to the xml serializer

it 'encodes hashes into nested xml elements in the order' do
rules[:ordered_hash] = {
:name => 'OrderedHash',
:type => :hash,
:members => {
:last => { :name => 'Last', :position => 2 },
:first => { :name => 'First', :position => 0 },
:second => { :name => 'Second', :position => 1 },
},
}

options[:ordered_hash] = {
:second => 'b',
:last => 'c',
:first => 'a',
}

xml.should == <<-XML.strip + "\n"
<OperationNameRequest xmlns="http://namespace.com/doc/">
<OrderedHash>
<First>a</First>
<Second>b</Second>
<Last>c</Last>
</OrderedHash>
</OperationNameRequest>
XML
end

end

end

context 'arrays' do
Expand Down
8 changes: 5 additions & 3 deletions spec/aws/route_53/client_spec.rb
Expand Up @@ -45,19 +45,21 @@ class Route53
{
:action => 'CREATE',
:resource_record_set => {
:name => 'sub.domain.com',
:type => 'CNAME',
# order of hash keys purposefully jumbled to test
# xml member ordering
:ttl => 3600,
:resource_records => [
{ :value => 'value1' },
],
:type => 'CNAME',
:name => 'sub.domain.com',
},
},
]
}
}}

it 'makes a POST request', :ruby => '1.9' do
it 'makes a POST request' do
handler.should_receive(:handle) do |req,resp|
req.http_method.should eq("POST")
req.uri.should eq('/2012-02-29/hostedzone/zone-id/rrset/')
Expand Down

0 comments on commit 53d960f

Please sign in to comment.