2010-03-14 23:11:43 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
2010-09-03 04:11:45 -04:00
|
|
|
class SimpleDB
|
2010-03-14 23:11:43 -04:00
|
|
|
class Real
|
2009-09-08 22:57:53 -04:00
|
|
|
|
|
|
|
# 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.
|
2010-06-22 14:43:26 -04:00
|
|
|
# * options<~Hash> - Accepts the following keys.
|
2010-06-22 23:03:41 -04:00
|
|
|
# :replace => [Array of keys to replace]
|
2010-06-22 14:43:26 -04:00
|
|
|
# :expect => {name/value pairs for performing conditional put}
|
2009-09-08 22:57:53 -04:00
|
|
|
#
|
|
|
|
# ==== Returns
|
2009-11-02 21:48:49 -05:00
|
|
|
# * response<~Excon::Response>:
|
2009-09-08 22:57:53 -04:00
|
|
|
# * body<~Hash>:
|
|
|
|
# * 'BoxUsage'
|
|
|
|
# * 'RequestId'
|
2010-06-22 14:43:26 -04:00
|
|
|
def put_attributes(domain_name, item_name, attributes, options = {})
|
|
|
|
options[:expect] = {} unless options[:expect]
|
|
|
|
options[:replace] = [] unless options[:replace]
|
2010-06-21 19:56:04 -04:00
|
|
|
request({
|
|
|
|
'Action' => 'PutAttributes',
|
|
|
|
'DomainName' => domain_name,
|
|
|
|
:parser => Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string),
|
|
|
|
'ItemName' => item_name
|
2010-06-22 14:43:26 -04:00
|
|
|
}.merge!(encode_attributes(attributes, options[:replace], options[:expect])))
|
2010-06-02 17:40:25 -04:00
|
|
|
end
|
|
|
|
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
|
|
|
|
2010-03-14 23:11:43 -04:00
|
|
|
class Mock
|
2009-09-08 22:57:53 -04:00
|
|
|
|
2010-06-22 14:43:26 -04:00
|
|
|
def put_attributes(domain_name, item_name, attributes, options = {})
|
|
|
|
options[:expect] = {} unless options[:expect]
|
|
|
|
options[:replace] = [] unless options[:replace]
|
2010-06-21 19:56:04 -04:00
|
|
|
response = Excon::Response.new
|
|
|
|
if @data[:domains][domain_name]
|
2010-06-22 14:43:26 -04:00
|
|
|
options[:expect].each do |ck, cv|
|
2010-06-21 19:56:04 -04:00
|
|
|
if @data[:domains][domain_name][item_name][ck] != [cv]
|
2010-06-02 17:40:25 -04:00
|
|
|
response.status = 409
|
|
|
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
attributes.each do |key, value|
|
|
|
|
@data[:domains][domain_name][item_name] ||= {}
|
2010-06-22 14:43:26 -04:00
|
|
|
@data[:domains][domain_name][item_name][key.to_s] = [] unless @data[:domains][domain_name][item_name][key.to_s]
|
|
|
|
if options[:replace].include?(key.to_s)
|
|
|
|
@data[:domains][domain_name][item_name][key.to_s] = [value.to_s]
|
|
|
|
else
|
|
|
|
@data[:domains][domain_name][item_name][key.to_s] += [value.to_s]
|
|
|
|
end
|
2010-06-02 17:40:25 -04:00
|
|
|
end
|
|
|
|
response.status = 200
|
|
|
|
response.body = {
|
|
|
|
'BoxUsage' => Fog::AWS::Mock.box_usage,
|
|
|
|
'RequestId' => Fog::AWS::Mock.request_id
|
|
|
|
}
|
2010-06-21 19:56:04 -04:00
|
|
|
else
|
|
|
|
response.status = 400
|
|
|
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
|
|
|
|
|
|
|
end
|
2010-06-02 17:40:25 -04:00
|
|
|
response
|
|
|
|
end
|
|
|
|
|
2009-09-08 22:57:53 -04:00
|
|
|
end
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|