SimpleDB - ActiveResource. Rails

I need a way to map ActiveResource to SimpleDB

I want to avoid plugins / gems as everything I used is outdated / buggy / not done

This does not seem difficult, I wonder if any of you have successfully implemented the rails application with simpleDB as an active resource. How did you do that? Thanks.

+6
ruby-on-rails amazon-web-services amazon-simpledb
source share
2 answers

I did not work with SimpleDB, but I mapped ActiveResource with the Amazon Flexible Payments Service REST api and just look at the documents that they seem similar, so here basically what I have done, maybe you can use this as a starting point.

require 'base64' require 'openssl' class AmazonFlexiblePaymentResource < ActiveResource::Base self.site = AMZ_CONFIG['flexible_api_url'] def self.rest_api(options = {}) params = common_request_params.update(options) sig = compute_signature(AMZ_CONFIG['secret_access_key'], 'get', site, params) rest_req = {'Signature' => sig}.update(params) # make the http get call connection.get("/#{query_string(rest_req)}", headers) end protected # these are the params are common to all rest api calls def self.common_request_params { 'AWSAccessKeyId' => AMZ_CONFIG['access_key_id'], 'SignatureVersion' => 2, 'SignatureMethod' => 'HmacSHA256', 'Timestamp' => Time.now.utc.iso8601, 'Version' => '2008-09-17'} end def self.compute_signature(key, method, end_point_url, params) query_str = parameters.sort.collect {|k, v| v.to_query(k)}.join '&' # cannot use plus for space, and tilde needs to be reversed query_str.gsub!('+', '%20') query_str.gsub!('%7E', '~') to_sign = [method.upcase, end_point_uri.host.downcase, end_point_uri.request_uri, query_str].join "\n" digest = OpenSSL::Digest::Digest.new('sha256') hmac = OpenSSL::HMAC.digest(digest, key, to_sign) Base64.encode64(hmac).chomp end end 

Then i just make such calls

 res = AmazonFlexiblePaymentResource.rest_api({ 'Action' => 'GetTransactionStatus', 'TransactionId' => '1234567890ABCDEFGHIJ' }) 

And the answer is the hash of the parsed xml. This again works for Amazon’s flexible payment service, so you may need to make adjustments to match the SimpleDB REST API.

+2
source share

Do I need to be ActiveResource? If you want this as an ActiveRecord, check out SimpleRecord.

http://github.com/appoxy/simple_record

He is very actively supported.

+1
source share

All Articles