lib/amazon/ecs.rb in amazon-ecs-2.5.0 vs lib/amazon/ecs.rb in amazon-ecs-2.6.0
- old
+ new
@@ -22,19 +22,18 @@
#++
require 'net/http'
require 'nokogiri'
require 'cgi'
-require 'hmac-sha2'
require 'base64'
require 'openssl'
module Amazon
class RequestError < StandardError; end
class Ecs
- VERSION = '2.5.0'
+ VERSION = '2.6.0'
SERVICE_URLS = {
:us => 'http://webservices.amazon.com/onca/xml',
:uk => 'http://webservices.amazon.co.uk/onca/xml',
:ca => 'http://webservices.amazon.ca/onca/xml',
@@ -44,25 +43,24 @@
:it => 'http://webservices.amazon.it/onca/xml',
:cn => 'http://webservices.amazon.cn/onca/xml',
:es => 'http://webservices.amazon.es/onca/xml',
:in => 'http://webservices.amazon.in/onca/xml',
:br => 'http://webservices.amazon.com.br/onca/xml',
- :mx => 'http://webservices.amazon.com.mx/onca/xml'
+ :mx => 'http://webservices.amazon.com.mx/onca/xml',
+ :au => 'http://webservices.amazon.com.au/onca/xml'
}
- OPENSSL_DIGEST_SUPPORT = OpenSSL::Digest.constants.include?( 'SHA256' ) ||
- OpenSSL::Digest.constants.include?( :SHA256 )
-
- OPENSSL_DIGEST = OpenSSL::Digest.new( 'sha256' ) if OPENSSL_DIGEST_SUPPORT
-
@@options = {
:version => "2013-08-01",
:service => "AWSECommerceService"
}
@@debug = ENV['DEBUG_AMAZON_ECS'] || false
+ # Error response from Amazon API may contain Access key ID
+ @@hideAPIError = ENV['HIDE_AMAZON_ECS_API_ERROR'] || false
+
# Default search options
def self.options
@@options
end
@@ -140,11 +138,11 @@
log("Response:\n#{res.body}\n\n")
ecs_res = Response.new(res.body)
unless res.kind_of? Net::HTTPSuccess
err_msg = "HTTP Response: #{res.code} #{res.message}"
- err_msg += " - #{ecs_res.error}" if ecs_res.error
+ err_msg += " - #{ecs_res.error}" if ecs_res.error && !@@hideAPIError
raise Amazon::RequestError, err_msg
end
ecs_res
end
@@ -303,18 +301,10 @@
s.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
end
def self.sign_request(url, key)
return nil if key.nil?
-
- if OPENSSL_DIGEST_SUPPORT
- signature = OpenSSL::HMAC.digest(OPENSSL_DIGEST, key, url)
- signature = [signature].pack('m').chomp
- else
- signature = Base64.encode64(HMAC::SHA256.digest(key, url)).strip
- end
- signature = CGI.escape(signature)
- return signature
+ return CGI.escape(Base64.strict_encode64(OpenSSL::HMAC.digest("SHA256", key, url)))
end
end
# Internal wrapper class to provide convenient method to access Nokogiri element value.
class Element