I am using a third-party API (Spreadshirt's API) and in order to perform a basket creation, I need to send an xml through a POST request. I am trying to do this with the available Net::HTTP functions and this is how I am doing it
def get_session
@time = Time.now.to_i * 1000 #get the current time as integer
@sha1 = Digest::SHA1.hexdigest("POST http://api.spreadshirt.com/api/v1/baskets #{@time} #{ENV['SPREADSHIRT_SECRET_KEY']}") #encrypt the signature
@http = Net::HTTP.new("http://api.spreadshirt.com")
@path = "/api/v1/baskets?apiKey=#{ENV['SPREADSHIRT_API_KEY']}&sig=#{@sha1}&time=#{@time}"
@payload = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
<basket xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns=\"http://api.spreadshirt.net\">
</basket>"
@response = @http.request_post(@path, @payload)
end
time => "The timestamp as milliseconds used in signature, e.g. 1240575575156."
sig =>"The signature as SHA-1 as Hex of string 'METHOD URL_WITHOUT_QUERY TIMESTAMP SECRET', e.g. 'POST http://localhost:8080/api/v1/users/42/productPriceCalculator 1240575575156 987654321'.(use your own secret on live system)."
apiKey => "The requested API key, e.g. 123456789 (use your own key on live system)."
More about the spec can be found on these links: http://api.spreadshirt.net/api/v1/metaData/api.html#N218D1 http://wiki.developer.spreadshirt.net/display/API/Basket+Resources
I am just wondering whether I have used the Net::HTTP function correctly or not assuming that I have used the correct secret key and api key.
EDIT:
The vendor has provided a sample code in PHP which can be found here http://spreadshirtapps.svn.sourceforge.net/viewvc/spreadshirtapps/php/sod/ the file sprd/CheckoutController.php is the one that is analogous to what I want to do.