lib/amazon/ecs.rb in amazon-ecs-0.5.5 vs lib/amazon/ecs.rb in amazon-ecs-0.5.6
- old
+ new
@@ -203,25 +203,41 @@
secret_key = opts.delete(:aWS_secret_key)
request_host = URI.parse(request_url).host
qs = ''
- opts.collect {|a,b| [camelize(a.to_s), b.to_s] }.sort {|c,d| c[0].to_s <=> d[0].to_s}.each {|e|
+
+ opts = opts.collect do |a,b|
+ [camelize(a.to_s), b.to_s]
+ end
+
+ opts = opts.sort do |c,d|
+ c[0].to_s <=> d[0].to_s
+ end
+
+ opts.each do |e|
log "Adding #{e[0]}=#{e[1]}"
next unless e[1]
e[1] = e[1].join(',') if e[1].is_a? Array
- v=URI.encode(e[1].to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
+ # v = URI.encode(e[1].to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
+ v = self.url_encode(e[1].to_s)
qs << "&" unless qs.length == 0
qs << "#{e[0]}=#{v}"
- }
+ end
signature = ''
unless secret_key.nil?
request_to_sign="GET\n#{request_host}\n/onca/xml\n#{qs}"
signature = "&Signature=#{sign_request(request_to_sign, secret_key)}"
end
"#{request_url}#{qs}#{signature}"
+ end
+
+ def self.url_encode(string)
+ string.gsub( /([^a-zA-Z0-9_.~-]+)/ ) do
+ '%' + $1.unpack( 'H2' * $1.size ).join( '%' ).upcase
+ end
end
def self.camelize(s)
s.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
end
\ No newline at end of file