Class: AwsSdb::Request::PutAttributes
- Defined in:
- lib/aws_sdb_bare/request.rb
Overview
Add attributes to an item or create a new item whith the given attributes
req = PutAttributes.new({:name => 'my_item'})
req.attributes = {:color => :black, :shape => {:value => :square, :replace => true}}
Note: in this request the value ‘black’ will be added to other color values if they already exist, while the shape value ‘square’ will replace pre existing values of shape the request, adding the :attributes to the params hash in the new method would have the same effect
Note: in the sample above attributes are defined after initializing the request, adding the :attributes to the params hash in the new method would have the same effect
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
Class Method Summary collapse
-
.batch(*requests) ⇒ Object
multiple PutAttributes requests can be batched in one BatchPutAttributes just define the single PutAttributes and then pass them as args to the PutAttributes::batch method and you’ll be returned the batched request.
Instance Method Summary collapse
Methods inherited from Template
#initialize, #request, shortcuts, #token=
Constructor Details
This class inherits a constructor from AwsSdb::Request::Template
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
220 221 222 |
# File 'lib/aws_sdb_bare/request.rb', line 220 def attributes @attributes end |
Class Method Details
.batch(*requests) ⇒ Object
multiple PutAttributes requests can be batched in one BatchPutAttributes just define the single PutAttributes and then pass them as args to the PutAttributes::batch method and you’ll be returned the batched request. At the moment of writing the maximum number of requests you can batch are 25
230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/aws_sdb_bare/request.rb', line 230 def batch(*requests) items_params = requests.map { |r| r.send(:expand!) } first_request = requests.first.request account = first_request.account secret = first_request.secret batch_params = {} batch_params['DomainName'] ||= first_request.params['DomainName'] items_params.each_with_index do |params, index| params.keys.each do |key| batch_params["Item.#{index.to_s + '.' + key}"] = params[key] if key =~ /^ItemName|Attribute/ end end BatchPutAttributes.new(batch_params, {:account => account, :secret => secret}) end |
Instance Method Details
#expand_attributes! ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/aws_sdb_bare/request.rb', line 248 def index = 0 @attributes.keys.each do |attr_name| replace = nil values = case @attributes[attr_name] when Hash replace = @attributes[attr_name][:replace].to_s @attributes[attr_name][:value].to_s else @attributes[attr_name].to_s end values = [values] unless values.is_a?(Array) values.each do |value| @params["Attribute.#{index}.Replace"] = replace if replace @params["Attribute.#{index}.Name"] = attr_name.to_s @params["Attribute.#{index}.Value"] = value index += 1 end end end |