1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

AmazonCase simpledb stuff

This commit is contained in:
Wesley Beary 2009-07-30 23:13:48 -07:00
parent b6085bd369
commit a9991f62b3
23 changed files with 132 additions and 126 deletions

View file

@ -12,8 +12,10 @@ module Fog
def end_element(name)
case(name)
when 'BoxUsage' then response[:box_usage] = @value.to_f
when 'RequestId' then response[:request_id] = @value
when 'BoxUsage'
response[name] = @value.to_f
when 'RequestId'
response[name] = @value
end
end

View file

@ -11,15 +11,14 @@ module Fog
def end_element(name)
case name
when 'AttributeNameCount' then response[:attribute_name_count] = @value.to_i
when 'AttributeNamesSizeBytes' then response[:attribute_names_size_bytes] = @value.to_i
when 'AttributeValueCount' then response[:attribute_value_count] = @value.to_i
when 'AttributeValuesSizeBytes' then response[:attribute_values_size_bytes] = @value.to_i
when 'BoxUsage' then response[:box_usage] = @value.to_f
when 'ItemCount' then response[:item_count] = @value.to_i
when 'ItemNamesSizeBytes' then response[:item_names_size_bytes] = @value.to_i
when 'RequestId' then response[:request_id] = @value
when 'Timestamp' then response[:timestamp] = Time.at(@value.to_i)
when 'AttributeNameCount', 'AttributeNamesSizeBytes', 'AttributeValueCount', 'AttributeValuesSizeBytes', 'ItemCount', 'ItemNamesSizeBytes'
response[name] = @value.to_i
when 'BoxUsage'
response[name] = @value.to_f
when 'RequestId'
response[name] = @value
when 'Timestamp'
response[name] = Time.at(@value.to_i)
end
end

View file

@ -7,15 +7,22 @@ module Fog
def reset
@attribute = nil
@response = { :attributes => {} }
@response = { 'Attributes' => {} }
end
def end_element(name)
case name
when 'BoxUsage' then response[:box_usage] = @value.to_f
when 'Name' then @attribute = @value
when 'RequestId' then response[:request_id] = @value
when 'Value' then (response[:attributes][@attribute] ||= []) << sdb_decode(@value)
when 'Attribute'
@attribute = nil
when 'BoxUsage'
response[name] = @value.to_f
when 'Name'
@attribute = @value
response['Attributes'][@attribute] = []
when 'RequestId'
response[name] = @value
when 'Value'
response['Attributes'][@attribute] << sdb_decode(@value)
end
end

View file

@ -6,15 +6,17 @@ module Fog
class ListDomains < Fog::Parsers::AWS::SimpleDB::Basic
def reset
@response = { :domains => [] }
@response = { 'Domains' => [] }
end
def end_element(name)
case(name)
when 'BoxUsage' then response[:box_usage] = @value.to_f
when 'DomainName' then response[:domains] << @value
when 'NextToken' then response[:next_token] = @value
when 'RequestId' then response[:request_id] = @value
when 'BoxUsage'
response[name] = @value.to_f
when 'DomainName'
response['Domains'] << @value
when 'NextToken', 'RequestId'
response[name] = @value
end
end

View file

@ -7,17 +7,27 @@ module Fog
def reset
@item_name = @attribute_name = nil
@response = { :items => {} }
@response = { 'Items' => {} }
end
def end_element(name)
case name
when 'BoxUsage' then response[:box_usage] = @value.to_f
when 'Item' then @item_name = @attribute_name = nil
when 'Name' then @item_name.nil? ? @item_name = @value : @attribute_name = @value
when 'NextToken' then response[:next_token] = @value
when 'RequestId' then response[:request_id] = @value
when 'Value' then ((response[:items][@item_name] ||= {})[@attribute_name] ||= []) << sdb_decode(@value)
when 'BoxUsage'
response[name] = @value.to_f
when 'Item'
@item_name = @attribute_name = nil
when 'Name'
if @item_name.nil?
@item_name = @value
response['Items'][@item_name] = {}
else
@attribute_name = @value
response['Items'][@item_name][@attribute_name] = []
end
when 'NextToken', 'RequestId'
response[name] = @value
when 'Value'
response['Items'][@item_name][@attribute_name] << sdb_decode(@value)
end
end

View file

@ -17,8 +17,8 @@ module Fog
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :box_usage
# * :request_id
# * 'BoxUsage'
# * 'RequestId'
def batch_put_attributes(domain_name, items, replace_attributes = Hash.new([]))
request({
'Action' => 'BatchPutAttributes',

View file

@ -11,8 +11,8 @@ module Fog
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :box_usage
# * :request_id
# * 'BoxUsage'
# * 'RequestId'
def create_domain(domain_name)
request({
'Action' => 'CreateDomain',

View file

@ -19,8 +19,8 @@ module Fog
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :box_usage
# * :request_id
# * 'BoxUsage'
# * 'RequestId'
def delete_attributes(domain_name, item_name, attributes = nil)
request({
'Action' => 'DeleteAttributes',

View file

@ -11,8 +11,8 @@ module Fog
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :box_usage
# * :request_id
# * 'BoxUsage'
# * 'RequestId'
def delete_domain(domain_name)
request({
'Action' => 'DeleteDomain',

View file

@ -11,13 +11,13 @@ module Fog
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :attribute_name_count - number of unique attribute names in domain
# * :attribute_names_size_bytes - total size of unique attribute names, in bytes
# * :attribute_value_count - number of all name/value pairs in domain
# * :attribute_values_size_bytes - total size of attributes, in bytes
# * :item_count - number of items in domain
# * :item_name_size_bytes - total size of item names in domain, in bytes
# * :timestamp - last update time for metadata.
# * 'AttributeNameCount' - number of unique attribute names in domain
# * 'AttributeNamesSizeBytes' - total size of unique attribute names, in bytes
# * 'AttributeValueCount' - number of all name/value pairs in domain
# * 'AttributeValuesSizeBytes' - total size of attributes, in bytes
# * 'ItemCount' - number of items in domain
# * 'ItemNameSizeBytes' - total size of item names in domain, in bytes
# * 'Timestamp' - last update time for metadata.
def domain_metadata(domain_name)
request({
'Action' => 'DomainMetadata',

View file

@ -19,9 +19,9 @@ module Fog
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :box_usage
# * :request_id
# * :attributes - list of attribute name/values for the item
# * 'Attributes' - list of attribute name/values for the item
# * 'BoxUsage'
# * 'RequestId'
def get_attributes(domain_name, item_name, attributes = nil)
request({
'Action' => 'GetAttributes',

View file

@ -6,22 +6,22 @@ module Fog
#
# ==== Parameters
# * options<~Hash> - options, defaults to {}
# *max_number_of_domains<~Integer> - number of domains to return
# * 'MaxNumberOfDomains'<~Integer> - number of domains to return
# between 1 and 100, defaults to 100
# *next_token<~String> - Offset token to start listing, defaults to nil
# * 'NextToken'<~String> - Offset token to start listing, defaults to nil
#
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :box_usage
# * :request_id
# * :domains - array of domain names.
# * :next_token - offset to start with if there are are more domains to list
# * 'BoxUsage'
# * 'Domains' - array of domain names.
# * 'NextToken' - offset to start with if there are are more domains to list
# * 'RequestId'
def list_domains(options = {})
request({
'Action' => 'ListDomains',
'MaxNumberOfDomains' => options[:max_number_of_domains],
'NextToken' => options[:next_token]
'MaxNumberOfDomains' => options['MaxNumberOfDomains'],
'NextToken' => options['NextToken']
}, Fog::Parsers::AWS::SimpleDB::ListDomains.new(@nil_string))
end

View file

@ -18,8 +18,8 @@ module Fog
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :box_usage
# * :request_id
# * 'BoxUsage'
# * 'RequestId'
def put_attributes(domain_name, item_name, attributes, replace_attributes = [])
batch_put_attributes(domain_name, { item_name => attributes }, { item_name => replace_attributes })
end

View file

@ -11,11 +11,11 @@ module Fog
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :box_usage
# * :request_id
# * :items - list of attribute name/values for the items formatted as
# * 'BoxUsage'<~Float>
# * 'RequestId'<~String>
# * 'Items'<~Hash> - list of attribute name/values for the items formatted as
# { 'item_name' => { 'attribute_name' => ['attribute_value'] }}
# * :next_token - offset to start with if there are are more domains to list
# * 'NextToken'<~String> - offset to start with if there are are more domains to list
def select(select_expression, next_token = nil)
request({
'Action' => 'Select',

View file

@ -13,8 +13,8 @@ describe 'SimpleDB.batch_put_attributes' do
it 'should return proper attributes' do
actual = sdb.batch_put_attributes(@domain_name, { 'a' => { 'b' => 'c' }, 'x' => { 'y' => 'z' } })
actual.body[:request_id].should be_a(String)
actual.body[:box_usage].should be_a(Float)
actual.body['RequestId'].should be_a(String)
actual.body['BoxUsage'].should be_a(Float)
end
end

View file

@ -12,8 +12,8 @@ describe 'SimpleDB.create_domain' do
it 'should return proper attributes' do
actual = sdb.create_domain(@domain_name)
actual.body[:request_id].should be_a(String)
actual.body[:box_usage].should be_a(Float)
actual.body['RequestId'].should be_a(String)
actual.body['BoxUsage'].should be_a(Float)
end
end

View file

@ -1,34 +0,0 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe 'SimpleDB.delete_attributes' do
before(:all) do
sdb.create_domain('delete_attributes')
sdb.put_attributes('delete_attributes', 'foo', { :bar => :baz })
end
after(:all) do
sdb.delete_domain('delete_attributes')
end
it 'should have attributes for foo before delete_attributes' do
eventually do
actual = sdb.get_attributes('delete_attributes', 'foo')
actual.body[:attributes].should == { 'bar' => ['baz'] }
end
end
it 'should return proper attributes from delete_attributes' do
actual = sdb.delete_attributes('delete_attributes', 'foo')
actual.body[:request_id].should be_a(String)
actual.body[:box_usage].should be_a(Float)
end
it 'should have no attributes for foo after delete_attributes' do
eventually do
actual = sdb.get_attributes('delete_attributes', 'foo')
actual.body[:attributes].should be_empty
end
end
end

View file

@ -0,0 +1,20 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe 'SimpleDB.delete_attributes' do
before(:all) do
sdb.create_domain('delete_attributes')
sdb.put_attributes('delete_attributes', 'foo', { :bar => :baz })
end
after(:all) do
sdb.delete_domain('delete_attributes')
end
it 'should return proper attributes from delete_attributes' do
actual = sdb.delete_attributes('delete_attributes', 'foo')
actual.body['RequestId'].should be_a(String)
actual.body['BoxUsage'].should be_a(Float)
end
end

View file

@ -12,8 +12,8 @@ describe 'SimpleDB.delete_domain' do
it 'should return proper attributes' do
actual = sdb.delete_domain(@domain_name)
actual.body[:request_id].should be_a(String)
actual.body[:box_usage].should be_a(Float)
actual.body['RequestId'].should be_a(String)
actual.body['BoxUsage'].should be_a(Float)
end
end

View file

@ -13,29 +13,29 @@ describe 'SimpleDB.domain_metadata' do
it 'should return proper attributes when there are no items' do
results = sdb.domain_metadata(@domain_name)
results.body[:attribute_name_count].should == 0
results.body[:attribute_names_size_bytes].should == 0
results.body[:attribute_value_count].should == 0
results.body[:attribute_values_size_bytes].should == 0
results.body[:box_usage].should be_a(Float)
results.body[:item_count].should == 0
results.body[:item_names_size_bytes].should == 0
results.body[:request_id].should be_a(String)
results.body[:timestamp].should be_a(Time)
results.body['AttributeNameCount'].should == 0
results.body['AttributeNamesSizeBytes'].should == 0
results.body['AttributeValueCount'].should == 0
results.body['AttributeValuesSizeBytes'].should == 0
results.body['BoxUsage'].should be_a(Float)
results.body['ItemCount'].should == 0
results.body['ItemNamesSizeBytes'].should == 0
results.body['RequestId'].should be_a(String)
results.body['Timestamp'].should be_a(Time)
end
it 'should return proper attributes with items' do
sdb.put_attributes(@domain_name, 'foo', { :bar => :baz })
results = sdb.domain_metadata(@domain_name)
results.body[:attribute_name_count].should == 1
results.body[:attribute_names_size_bytes].should == 3
results.body[:attribute_value_count].should == 1
results.body[:attribute_values_size_bytes].should == 3
results.body[:box_usage].should be_a(Float)
results.body[:item_count].should == 1
results.body[:item_names_size_bytes].should == 3
results.body[:request_id].should be_a(String)
results.body[:timestamp].should be_a(Time)
results.body['AttributeNameCount'].should == 1
results.body['AttributeNamesSizeBytes'].should == 3
results.body['AttributeValueCount'].should == 1
results.body['AttributeValuesSizeBytes'].should == 3
results.body['BoxUsage'].should be_a(Float)
results.body['ItemCount'].should == 1
results.body['ItemNamesSizeBytes'].should == 3
results.body['RequestId'].should be_a(String)
results.body['Timestamp'].should be_a(Time)
end
end

View file

@ -14,7 +14,7 @@ describe 'SimpleDB.get_attributes' do
it 'should have no attributes for foo before put_attributes' do
eventually do
actual = sdb.get_attributes(@domain_name, 'foo')
actual.body[:attributes].should be_empty
actual.body['Attributes'].should be_empty
end
end
@ -22,7 +22,7 @@ describe 'SimpleDB.get_attributes' do
sdb.put_attributes(@domain_name, 'foo', { :bar => :baz })
eventually do
actual = sdb.get_attributes(@domain_name, 'foo')
actual.body[:attributes].should == { 'bar' => ['baz'] }
actual.body['Attributes'].should == { 'bar' => ['baz'] }
end
end

View file

@ -12,16 +12,16 @@ describe 'SimpleDB.list_domains' do
it 'should return proper attributes' do
results = sdb.list_domains
results.body[:box_usage].should be_a(Float)
results.body[:domains].should be_an(Array)
results.body[:request_id].should be_a(String)
results.body['BoxUsage'].should be_a(Float)
results.body['Domains'].should be_an(Array)
results.body['RequestId'].should be_a(String)
end
it 'should include created domains' do
sdb.create_domain(@domain_name)
eventually do
actual = sdb.list_domains
actual.body[:domains].should include(@domain_name)
actual.body['Domains'].should include(@domain_name)
end
end

View file

@ -13,8 +13,8 @@ describe 'SimpleDB.put_attributes' do
it 'should return proper attributes from put_attributes' do
actual = sdb.put_attributes(@domain_name, 'foo', { 'bar' => 'baz' })
actual.body[:request_id].should be_a(String)
actual.body[:box_usage].should be_a(Float)
actual.body['RequestId'].should be_a(String)
actual.body['BoxUsage'].should be_a(Float)
end
end