Permalink
Browse files

Implement SimpleDB

  • Loading branch information...
Jason Roelofs
Jason Roelofs committed Mar 24, 2012
1 parent 42ccf62 commit 57d18070f82049aaac0f221efc60bf5a349752ef
Showing with 79 additions and 0 deletions.
  1. +27 −0 lib/simple_aws/simple_db.rb
  2. +16 −0 samples/simple_db.rb
  3. +36 −0 test/simple_aws/simple_db_test.rb
@@ -0,0 +1,27 @@
+require 'simple_aws/api'
+require 'simple_aws/call_types/action_param'
+require 'simple_aws/signing/version2'
+
+module SimpleAWS
+
+ ##
+ # Amazon's SimpleDB
+ #
+ # http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/Welcome.html
+ #
+ # All requests are POST and always through HTTPS. Use the third parameter to
+ # `initialize` if you need to talk to a region other than us-east-1.
+ #
+ # @see SimpleAWS::CallTypes::ActionParam Calling rules
+ # @see SimpleAWS::Response Response handling
+ ##
+ class SimpleDB < API
+ endpoint "sdb"
+ use_https true
+ version "2009-04-15"
+
+ include CallTypes::ActionParam
+ include Signing::Version2
+ end
+
+end
View
@@ -0,0 +1,16 @@
+$: << File.expand_path("../../lib", __FILE__)
+
+require 'simple_aws/simple_db'
+
+##
+# Expects your Amazon keys to be in the environment, something like
+#
+# export AWS_KEY="KEY"
+# export AWS_SECRET="SECRET"
+##
+
+sdb = SimpleAWS::SimpleDB.new ENV["AWS_KEY"], ENV["AWS_SECRET"]
+
+puts "", "All Domains", ""
+
+p sdb.list_domains
@@ -0,0 +1,36 @@
+require 'test_helper'
+require 'simple_aws/simple_db'
+
+describe SimpleAWS::SimpleDB do
+
+ before do
+ @api = SimpleAWS::SimpleDB.new "key", "secret"
+ end
+
+ it "points to the endpoint" do
+ @api.uri.must_equal "https://sdb.amazonaws.com"
+ end
+
+ it "works with the current version" do
+ @api.version.must_equal "2009-04-15"
+ end
+
+ describe "API calls" do
+
+ it "builds and signs calls with ActionParam rules" do
+ SimpleAWS::Connection.any_instance.expects(:call).with do |request|
+ params = request.params
+ params.wont_be_nil
+
+ params["Action"].must_equal "ListDomains"
+ params["Signature"].wont_be_nil
+
+ true
+ end
+
+ obj = SimpleAWS::SimpleDB.new "key", "secret"
+ obj.list_domains
+ end
+
+ end
+end

0 comments on commit 57d1807

Please sign in to comment.