lib/sucker/request.rb in sucker-0.9.2 vs lib/sucker/request.rb in sucker-1.0.0.beta.1
- old
+ new
@@ -1,7 +1,7 @@
# encoding: utf-8
-module Sucker
+module Sucker #:nodoc
# A wrapper around the API request
class Request
HOSTS = {
:us => 'ecs.amazonaws.com',
@@ -22,30 +22,41 @@
attr_accessor :parameters
def initialize(args)
self.parameters = {
"Service" => "AWSECommerceService",
- "Version" => Sucker::AMAZON_API_VERSION
+ "Version" => api_version
}
args.each { |k, v| send("#{k}=", v) }
end
- # A helper method that merges a hash into the parameters
+ # A helper method that merges a hash into existing parameters
def <<(hash)
self.parameters.merge!(hash)
end
+ # Gets Amazon API version.
+ def api_version
+ @api_version ||= CURRENT_AMAZON_API_VERSION
+ end
+
+ # Set Amazon API version.
+ def api_version=(version)
+ @api_version = version
+ end
+
# A helper method that sets the associate tag
def associate_tag=(token)
parameters["AssociateTag"] = token
end
# A reusable, configurable cURL object
def curl
- yield curl_object if block_given?
- curl_object
+ @curl ||= Curl::Easy.new
+ yield @curl if block_given?
+ @curl
end
# Performs the request and returns a response object
def get
curl.url = uri.to_s
@@ -68,13 +79,9 @@
sort.
collect do |k, v|
"#{k}=" + escape(v.is_a?(Array) ? v.join(",") : v.to_s)
end.
join("&")
- end
-
- def curl_object
- @curl ||= Curl::Easy.new
end
def escape(string)
# Shamelessly plagiarized from ruby_aaws, which in turn plagiarizes