diff --git a/lib/fog/aws/requests/simpledb/batch_put_attributes.rb b/lib/fog/aws/requests/simpledb/batch_put_attributes.rb index 1af999a7c..69f784360 100644 --- a/lib/fog/aws/requests/simpledb/batch_put_attributes.rb +++ b/lib/fog/aws/requests/simpledb/batch_put_attributes.rb @@ -41,14 +41,15 @@ else def batch_put_attributes(domain_name, items, replace_attributes = Hash.new([])) response = Fog::Response.new if Fog::AWS::SimpleDB.data[:domains][domain_name] - for key, value in items do - for item in value do - if replace_attributes[key] && replace_attributes[key].include?(value) - Fog::AWS::SimpleDB.data[:domains][domain_name][key] = [] + for item_name, attributes in items do + for key, value in attributes do + Fog::AWS::SimpleDB.data[:domains][domain_name][item_name] ||= {} + if replace_attributes[item_name] && replace_attributes[item_name].include?(key) + Fog::AWS::SimpleDB.data[:domains][domain_name][item_name][key.to_s] = [] else - Fog::AWS::SimpleDB.data[:domains][domain_name][key] ||= [] + Fog::AWS::SimpleDB.data[:domains][domain_name][item_name][key.to_s] ||= [] end - Fog::AWS::SimpleDB.data[:domains][domain_name][key] << value.to_s + Fog::AWS::SimpleDB.data[:domains][domain_name][item_name][key.to_s] << value.to_s end end response.status = 200 diff --git a/lib/fog/aws/requests/simpledb/create_domain.rb b/lib/fog/aws/requests/simpledb/create_domain.rb index 2c1c4f263..d090fecbe 100644 --- a/lib/fog/aws/requests/simpledb/create_domain.rb +++ b/lib/fog/aws/requests/simpledb/create_domain.rb @@ -34,7 +34,7 @@ else def create_domain(domain_name) response = Fog::Response.new - Fog::AWS::SimpleDB.data[:domains][domain_name] = { :attributes => {} } + Fog::AWS::SimpleDB.data[:domains][domain_name] = {} response.status = 200 response.body = { 'BoxUsage' => Fog::AWS::Mock.box_usage, diff --git a/lib/fog/aws/requests/simpledb/delete_attributes.rb b/lib/fog/aws/requests/simpledb/delete_attributes.rb index d0283e8bf..e5eb29dca 100644 --- a/lib/fog/aws/requests/simpledb/delete_attributes.rb +++ b/lib/fog/aws/requests/simpledb/delete_attributes.rb @@ -1,34 +1,72 @@ -module Fog - module AWS - class SimpleDB +unless Fog.mocking? + + module Fog + module AWS + class SimpleDB + + # List metadata for SimpleDB domain + # + # ==== Parameters + # * domain_name<~String> - Name of domain. Must be between 3 and 255 of the + # following characters: a-z, A-Z, 0-9, '_', '-' and '.'. + # * item_name<~String> - Name of the item. May use any UTF-8 characters valid + # in xml. Control characters and sequences not allowed in xml are not + # valid. Can be up to 1024 bytes long. + # * attributes<~Hash> - Name/value pairs to remove from the item. Defaults to + # nil, which will delete the entire item. Attribute names and values may + # use any UTF-8 characters valid in xml. Control characters and sequences + # not allowed in xml are not valid. Each name and value can be up to 1024 + # bytes long. + # + # ==== Returns + # * response<~Fog::AWS::Response>: + # * body<~Hash>: + # * 'BoxUsage' + # * 'RequestId' + def delete_attributes(domain_name, item_name, attributes = nil) + request({ + 'Action' => 'DeleteAttributes', + 'DomainName' => domain_name, + 'ItemName' => item_name + }.merge!(encode_attributes(attributes)), Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string)) + end - # List metadata for SimpleDB domain - # - # ==== Parameters - # * domain_name<~String> - Name of domain. Must be between 3 and 255 of the - # following characters: a-z, A-Z, 0-9, '_', '-' and '.'. - # * item_name<~String> - Name of the item. May use any UTF-8 characters valid - # in xml. Control characters and sequences not allowed in xml are not - # valid. Can be up to 1024 bytes long. - # * attributes<~Hash> - Name/value pairs to remove from the item. Defaults to - # nil, which will delete the entire item. Attribute names and values may - # use any UTF-8 characters valid in xml. Control characters and sequences - # not allowed in xml are not valid. Each name and value can be up to 1024 - # bytes long. - # - # ==== Returns - # * response<~Fog::AWS::Response>: - # * body<~Hash>: - # * 'BoxUsage' - # * 'RequestId' - def delete_attributes(domain_name, item_name, attributes = nil) - request({ - 'Action' => 'DeleteAttributes', - 'DomainName' => domain_name, - 'ItemName' => item_name - }.merge!(encode_attributes(attributes)), Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string)) end - end end -end + +else + + module Fog + module AWS + class SimpleDB + + def delete_attributes(domain_name, item_name, attributes = nil) + response = Fog::Response.new + if Fog::AWS::SimpleDB.data[:domains][domain_name] + if attributes + for key, value in attributes + if Fog::AWS::SimpleDB.data[:domains][domain_name][key] + Fog::AWS::SimpleDB.data[:domains][domain_name][key].delete('value') + end + end + else + Fog::AWS::SimpleDB.data[:domains].delete(domain_name) + end + response.status = 200 + response.body = { + 'BoxUsage' => Fog::AWS::Mock.box_usage, + 'RequestId' => Fog::AWS::Mock.request_id + } + else + response.status = 400 + raise(Fog::Errors.status_error(200, 400, response)) + end + response + end + + end + end + end + +end \ No newline at end of file diff --git a/lib/fog/aws/requests/simpledb/domain_metadata.rb b/lib/fog/aws/requests/simpledb/domain_metadata.rb index 61cfc3037..af8e08b5f 100644 --- a/lib/fog/aws/requests/simpledb/domain_metadata.rb +++ b/lib/fog/aws/requests/simpledb/domain_metadata.rb @@ -1,30 +1,80 @@ -module Fog - module AWS - class SimpleDB +unless Fog.mocking? + + module Fog + module AWS + class SimpleDB + + # List metadata for SimpleDB domain + # + # ==== Parameters + # * domain_name<~String> - Name of domain. Must be between 3 and 255 of the + # following characters: a-z, A-Z, 0-9, '_', '-' and '.'. + # + # ==== Returns + # * response<~Fog::AWS::Response>: + # * body<~Hash>: + # * '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 + # * 'BoxUsage' + # * 'ItemCount' - number of items in domain + # * 'ItemNameSizeBytes' - total size of item names in domain, in bytes + # * 'RequestId' + # * 'Timestamp' - last update time for metadata. + def domain_metadata(domain_name) + request({ + 'Action' => 'DomainMetadata', + 'DomainName' => domain_name + }, Fog::Parsers::AWS::SimpleDB::DomainMetadata.new(@nil_string)) + end - # List metadata for SimpleDB domain - # - # ==== Parameters - # * domain_name<~String> - Name of domain. Must be between 3 and 255 of the - # following characters: a-z, A-Z, 0-9, '_', '-' and '.'. - # - # ==== Returns - # * response<~Fog::AWS::Response>: - # * body<~Hash>: - # * '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', - 'DomainName' => domain_name - }, Fog::Parsers::AWS::SimpleDB::DomainMetadata.new(@nil_string)) end - end end + +else + + module Fog + module AWS + class SimpleDB + + def domain_metadata(domain_name) + response = Fog::Response.new + if domain = Fog::AWS::SimpleDB.data[:domains][domain_name] + response.status = 200 + + attribute_names = [] + attribute_values = [] + for item in domain.values + for key, values in item + attribute_names << key + for value in values + attribute_values << value + end + end + end + + response.body = { + 'AttributeNameCount' => attribute_names.length, + 'AttributeNamesSizeBytes' => attribute_names.join('').length, + 'AttributeValueCount' => attribute_values.length, + 'AttributeValuesSizeBytes' => attribute_values.join('').length, + 'BoxUsage' => Fog::AWS::Mock.box_usage, + 'ItemCount' => domain.keys.length, + 'ItemNamesSizeBytes' => domain.keys.join('').length, + 'RequestId' => Fog::AWS::Mock.request_id, + 'Timestamp' => Time.now + } + else + response.status = 400 + raise(Fog::Errors.status_error(200, 400, response)) + end + response + end + + end + end + end + end diff --git a/lib/fog/aws/requests/simpledb/get_attributes.rb b/lib/fog/aws/requests/simpledb/get_attributes.rb index cceb3b1bd..6031374e3 100644 --- a/lib/fog/aws/requests/simpledb/get_attributes.rb +++ b/lib/fog/aws/requests/simpledb/get_attributes.rb @@ -1,35 +1,75 @@ -module Fog - module AWS - class SimpleDB +unless Fog.mocking? + + module Fog + module AWS + class SimpleDB + + # List metadata for SimpleDB domain + # + # ==== Parameters + # * domain_name<~String> - Name of domain. Must be between 3 and 255 of the + # following characters: a-z, A-Z, 0-9, '_', '-' and '.'. + # * item_name<~String> - Name of the item. May use any UTF-8 characters valid + # in xml. Control characters and sequences not allowed in xml are not + # valid. Can be up to 1024 bytes long. + # * attributes<~Array> - Attributes to return from the item. Defaults to + # nil, which will return all attributes. Attribute names and values may use + # any UTF-8 characters valid in xml. Control characters and sequences not + # allowed in xml are not valid. Each name and value can be up to 1024 + # bytes long. + # + # ==== Returns + # * response<~Fog::AWS::Response>: + # * body<~Hash>: + # * 'Attributes' - list of attribute name/values for the item + # * 'BoxUsage' + # * 'RequestId' + def get_attributes(domain_name, item_name, attributes = nil) + request({ + 'Action' => 'GetAttributes', + 'DomainName' => domain_name, + 'ItemName' => item_name, + }.merge!(encode_attribute_names(attributes)), Fog::Parsers::AWS::SimpleDB::GetAttributes.new(@nil_string)) + end - # List metadata for SimpleDB domain - # - # ==== Parameters - # * domain_name<~String> - Name of domain. Must be between 3 and 255 of the - # following characters: a-z, A-Z, 0-9, '_', '-' and '.'. - # * item_name<~String> - Name of the item. May use any UTF-8 characters valid - # in xml. Control characters and sequences not allowed in xml are not - # valid. Can be up to 1024 bytes long. - # * attributes<~Hash> - Name/value pairs to return from the item. Defaults to - # nil, which will return all attributes. Attribute names and values may use - # any UTF-8 characters valid in xml. Control characters and sequences not - # allowed in xml are not valid. Each name and value can be up to 1024 - # bytes long. - # - # ==== Returns - # * response<~Fog::AWS::Response>: - # * body<~Hash>: - # * 'Attributes' - list of attribute name/values for the item - # * 'BoxUsage' - # * 'RequestId' - def get_attributes(domain_name, item_name, attributes = nil) - request({ - 'Action' => 'GetAttributes', - 'DomainName' => domain_name, - 'ItemName' => item_name, - }.merge!(encode_attribute_names(attributes)), Fog::Parsers::AWS::SimpleDB::GetAttributes.new(@nil_string)) end - end end + +else + + module Fog + module AWS + class SimpleDB + + def get_attributes(domain_name, item_name, attributes = nil) + response = Fog::Response.new + if Fog::AWS::SimpleDB.data[:domains][domain_name] + object = {} + if attributes + for attribute in attributes + if Fog::AWS::SimpleDB.data[:domains][domain_name][item_name] && Fog::AWS::SimpleDB.data[:domains][domain_name][item_name] + object[attribute] = Fog::AWS::SimpleDB.data[:domains][domain_name][item_name][attribute] + end + end + elsif Fog::AWS::SimpleDB.data[:domains][domain_name][item_name] + object = Fog::AWS::SimpleDB.data[:domains][domain_name][item_name] + end + response.status = 200 + response.body = { + 'Attributes' => object, + 'BoxUsage' => Fog::AWS::Mock.box_usage, + 'RequestId' => Fog::AWS::Mock.request_id + } + else + response.status = 400 + raise(Fog::Errors.status_error(200, 400, response)) + end + response + end + + end + end + end + end diff --git a/lib/fog/aws/requests/simpledb/put_attributes.rb b/lib/fog/aws/requests/simpledb/put_attributes.rb index 30a491d2c..800e15667 100644 --- a/lib/fog/aws/requests/simpledb/put_attributes.rb +++ b/lib/fog/aws/requests/simpledb/put_attributes.rb @@ -1,29 +1,47 @@ -module Fog - module AWS - class SimpleDB +unless Fog.mocking? + + module Fog + module AWS + class SimpleDB + + # Put item attributes into a SimpleDB domain + # + # ==== Parameters + # * domain_name<~String> - Name of domain. Must be between 3 and 255 of the + # following characters: a-z, A-Z, 0-9, '_', '-' and '.'. + # * item_name<~String> - Name of the item. May use any UTF-8 characters valid + # in xml. Control characters and sequences not allowed in xml are not + # valid. Can be up to 1024 bytes long. + # * attributes<~Hash> - Name/value pairs to add to the item. Attribute names + # and values may use any UTF-8 characters valid in xml. Control characters + # and sequences not allowed in xml are not valid. Each name and value can + # be up to 1024 bytes long. + # + # ==== Returns + # * response<~Fog::AWS::Response>: + # * body<~Hash>: + # * '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 - # Put item attributes into a SimpleDB domain - # - # ==== Parameters - # * domain_name<~String> - Name of domain. Must be between 3 and 255 of the - # following characters: a-z, A-Z, 0-9, '_', '-' and '.'. - # * item_name<~String> - Name of the item. May use any UTF-8 characters valid - # in xml. Control characters and sequences not allowed in xml are not - # valid. Can be up to 1024 bytes long. - # * attributes<~Hash> - Name/value pairs to add to the item. Attribute names - # and values may use any UTF-8 characters valid in xml. Control characters - # and sequences not allowed in xml are not valid. Each name and value can - # be up to 1024 bytes long. - # - # ==== Returns - # * response<~Fog::AWS::Response>: - # * body<~Hash>: - # * '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 - end end + +else + + module Fog + module AWS + class SimpleDb + + def put_attributes(domain_name, item_name, attributes, replace_attributes = []) + batch_put_attributes(domain_name, { item_name => attributes }, { item_name => replace_attributes }) + end + + end + end + end + end