Skip to content

Instantly share code, notes, and snippets.

@hungryblank
Created June 1, 2009 18:23
Show Gist options
  • Save hungryblank/121638 to your computer and use it in GitHub Desktop.
Save hungryblank/121638 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'aws_sdb_bare'
require 'nokogiri'
require 'net/http'
require 'uuid'
include AwsSdb
include AwsSdb::Request
module HttpHandler
def handle
Response.parse(Net::HTTP.get(URI.parse(uri)))
end
end
Request::Template.send :include, HttpHandler
class Domain
class << self
def find(name)
new(name)
end
def create!(name)
CreateDomain.new(:name => name).handle
new(name)
end
end
def initialize(name)
@uuid = UUID.new
@name = name
end
def put(attributes)
new_id = @uuid.generate(:compact)
PutAttributes.new(:domain => @name, :name => new_id, :attributes => attributes).handle
new_id
end
def get(id)
response = GetAttributes.new(:domain => @name, :name => id).handle
response.attributes
end
end
#== demo ==
domain = Domain.create!('get_put_test')
id = domain.put(:foo => 'bar')
p domain.get(id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment