From a9991f62b389c9ed5a8f4afc675fc571708094c0 Mon Sep 17 00:00:00 2001 From: Wesley Beary Date: Thu, 30 Jul 2009 23:13:48 -0700 Subject: [PATCH] AmazonCase simpledb stuff --- lib/fog/aws/parsers/simpledb/basic.rb | 6 ++-- .../aws/parsers/simpledb/domain_metadata.rb | 17 +++++---- .../aws/parsers/simpledb/get_attributes.rb | 17 ++++++--- lib/fog/aws/parsers/simpledb/list_domains.rb | 12 ++++--- lib/fog/aws/parsers/simpledb/select.rb | 24 +++++++++---- .../requests/simpledb/batch_put_attributes.rb | 4 +-- .../aws/requests/simpledb/create_domain.rb | 4 +-- .../requests/simpledb/delete_attributes.rb | 4 +-- .../aws/requests/simpledb/delete_domain.rb | 4 +-- .../aws/requests/simpledb/domain_metadata.rb | 14 ++++---- .../aws/requests/simpledb/get_attributes.rb | 6 ++-- lib/fog/aws/requests/simpledb/list_domains.rb | 16 ++++----- .../aws/requests/simpledb/put_attributes.rb | 4 +-- lib/fog/aws/requests/simpledb/select.rb | 8 ++--- .../aws/simpledb/batch_put_attributes_spec.rb | 4 +-- spec/aws/simpledb/create_domain_spec.rb | 4 +-- spec/aws/simpledb/delete_attributes.rb | 34 ------------------ spec/aws/simpledb/delete_attributes_spec.rb | 20 +++++++++++ spec/aws/simpledb/delete_domain_spec.rb | 4 +-- spec/aws/simpledb/domain_metadata_spec.rb | 36 +++++++++---------- spec/aws/simpledb/get_attributes_spec.rb | 4 +-- spec/aws/simpledb/list_domains_spec.rb | 8 ++--- spec/aws/simpledb/put_attributes_spec.rb | 4 +-- 23 files changed, 132 insertions(+), 126 deletions(-) delete mode 100644 spec/aws/simpledb/delete_attributes.rb create mode 100644 spec/aws/simpledb/delete_attributes_spec.rb diff --git a/lib/fog/aws/parsers/simpledb/basic.rb b/lib/fog/aws/parsers/simpledb/basic.rb index d6bde6cef..8a653e710 100644 --- a/lib/fog/aws/parsers/simpledb/basic.rb +++ b/lib/fog/aws/parsers/simpledb/basic.rb @@ -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 diff --git a/lib/fog/aws/parsers/simpledb/domain_metadata.rb b/lib/fog/aws/parsers/simpledb/domain_metadata.rb index e0a316c1c..fbda04c55 100644 --- a/lib/fog/aws/parsers/simpledb/domain_metadata.rb +++ b/lib/fog/aws/parsers/simpledb/domain_metadata.rb @@ -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 diff --git a/lib/fog/aws/parsers/simpledb/get_attributes.rb b/lib/fog/aws/parsers/simpledb/get_attributes.rb index 11cee5499..2e07a873d 100644 --- a/lib/fog/aws/parsers/simpledb/get_attributes.rb +++ b/lib/fog/aws/parsers/simpledb/get_attributes.rb @@ -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 diff --git a/lib/fog/aws/parsers/simpledb/list_domains.rb b/lib/fog/aws/parsers/simpledb/list_domains.rb index de89a076e..8bebba14d 100644 --- a/lib/fog/aws/parsers/simpledb/list_domains.rb +++ b/lib/fog/aws/parsers/simpledb/list_domains.rb @@ -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 diff --git a/lib/fog/aws/parsers/simpledb/select.rb b/lib/fog/aws/parsers/simpledb/select.rb index 3d8beb20c..f8ddb9cdc 100644 --- a/lib/fog/aws/parsers/simpledb/select.rb +++ b/lib/fog/aws/parsers/simpledb/select.rb @@ -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 diff --git a/lib/fog/aws/requests/simpledb/batch_put_attributes.rb b/lib/fog/aws/requests/simpledb/batch_put_attributes.rb index 20c7a24fe..8bb9e9bab 100644 --- a/lib/fog/aws/requests/simpledb/batch_put_attributes.rb +++ b/lib/fog/aws/requests/simpledb/batch_put_attributes.rb @@ -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', diff --git a/lib/fog/aws/requests/simpledb/create_domain.rb b/lib/fog/aws/requests/simpledb/create_domain.rb index b278f7a09..1681feda1 100644 --- a/lib/fog/aws/requests/simpledb/create_domain.rb +++ b/lib/fog/aws/requests/simpledb/create_domain.rb @@ -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', diff --git a/lib/fog/aws/requests/simpledb/delete_attributes.rb b/lib/fog/aws/requests/simpledb/delete_attributes.rb index 2b43d0393..d0283e8bf 100644 --- a/lib/fog/aws/requests/simpledb/delete_attributes.rb +++ b/lib/fog/aws/requests/simpledb/delete_attributes.rb @@ -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', diff --git a/lib/fog/aws/requests/simpledb/delete_domain.rb b/lib/fog/aws/requests/simpledb/delete_domain.rb index 6c5516539..26c14df4b 100644 --- a/lib/fog/aws/requests/simpledb/delete_domain.rb +++ b/lib/fog/aws/requests/simpledb/delete_domain.rb @@ -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', diff --git a/lib/fog/aws/requests/simpledb/domain_metadata.rb b/lib/fog/aws/requests/simpledb/domain_metadata.rb index 39ec7a6a5..61cfc3037 100644 --- a/lib/fog/aws/requests/simpledb/domain_metadata.rb +++ b/lib/fog/aws/requests/simpledb/domain_metadata.rb @@ -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', diff --git a/lib/fog/aws/requests/simpledb/get_attributes.rb b/lib/fog/aws/requests/simpledb/get_attributes.rb index d06dd74ae..cceb3b1bd 100644 --- a/lib/fog/aws/requests/simpledb/get_attributes.rb +++ b/lib/fog/aws/requests/simpledb/get_attributes.rb @@ -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', diff --git a/lib/fog/aws/requests/simpledb/list_domains.rb b/lib/fog/aws/requests/simpledb/list_domains.rb index cc102ca10..177e8443a 100644 --- a/lib/fog/aws/requests/simpledb/list_domains.rb +++ b/lib/fog/aws/requests/simpledb/list_domains.rb @@ -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 diff --git a/lib/fog/aws/requests/simpledb/put_attributes.rb b/lib/fog/aws/requests/simpledb/put_attributes.rb index 8ce58853d..30a491d2c 100644 --- a/lib/fog/aws/requests/simpledb/put_attributes.rb +++ b/lib/fog/aws/requests/simpledb/put_attributes.rb @@ -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 diff --git a/lib/fog/aws/requests/simpledb/select.rb b/lib/fog/aws/requests/simpledb/select.rb index 0171109a9..02f7abd96 100644 --- a/lib/fog/aws/requests/simpledb/select.rb +++ b/lib/fog/aws/requests/simpledb/select.rb @@ -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', diff --git a/spec/aws/simpledb/batch_put_attributes_spec.rb b/spec/aws/simpledb/batch_put_attributes_spec.rb index 904997491..ec7119b4d 100644 --- a/spec/aws/simpledb/batch_put_attributes_spec.rb +++ b/spec/aws/simpledb/batch_put_attributes_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/aws/simpledb/create_domain_spec.rb b/spec/aws/simpledb/create_domain_spec.rb index 123748749..393aab290 100644 --- a/spec/aws/simpledb/create_domain_spec.rb +++ b/spec/aws/simpledb/create_domain_spec.rb @@ -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 diff --git a/spec/aws/simpledb/delete_attributes.rb b/spec/aws/simpledb/delete_attributes.rb deleted file mode 100644 index dd27ee775..000000000 --- a/spec/aws/simpledb/delete_attributes.rb +++ /dev/null @@ -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 diff --git a/spec/aws/simpledb/delete_attributes_spec.rb b/spec/aws/simpledb/delete_attributes_spec.rb new file mode 100644 index 000000000..4105938be --- /dev/null +++ b/spec/aws/simpledb/delete_attributes_spec.rb @@ -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 diff --git a/spec/aws/simpledb/delete_domain_spec.rb b/spec/aws/simpledb/delete_domain_spec.rb index f65761f4c..180814c8e 100644 --- a/spec/aws/simpledb/delete_domain_spec.rb +++ b/spec/aws/simpledb/delete_domain_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/aws/simpledb/domain_metadata_spec.rb b/spec/aws/simpledb/domain_metadata_spec.rb index c47707621..56eb64d54 100644 --- a/spec/aws/simpledb/domain_metadata_spec.rb +++ b/spec/aws/simpledb/domain_metadata_spec.rb @@ -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 diff --git a/spec/aws/simpledb/get_attributes_spec.rb b/spec/aws/simpledb/get_attributes_spec.rb index 26e0fa093..967d84f5d 100644 --- a/spec/aws/simpledb/get_attributes_spec.rb +++ b/spec/aws/simpledb/get_attributes_spec.rb @@ -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 diff --git a/spec/aws/simpledb/list_domains_spec.rb b/spec/aws/simpledb/list_domains_spec.rb index e1ac57bd6..b62ce8178 100644 --- a/spec/aws/simpledb/list_domains_spec.rb +++ b/spec/aws/simpledb/list_domains_spec.rb @@ -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 diff --git a/spec/aws/simpledb/put_attributes_spec.rb b/spec/aws/simpledb/put_attributes_spec.rb index 2c1070d7f..c2b283eb9 100644 --- a/spec/aws/simpledb/put_attributes_spec.rb +++ b/spec/aws/simpledb/put_attributes_spec.rb @@ -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