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

adds batch_put_item functionality to AWS dynamodb + test

This commit is contained in:
Alex Gaudio 2012-04-20 15:23:57 -04:00
parent a36c3aaf67
commit 241ac21910
3 changed files with 51 additions and 0 deletions

View file

@ -9,6 +9,7 @@ module Fog
request_path 'fog/aws/requests/dynamodb'
request :batch_get_item
request :batch_put_item
request :create_table
request :delete_item
request :delete_table

View file

@ -0,0 +1,30 @@
module Fog
module AWS
class DynamoDB
class Real
#request_items has form:
#{"table_name"=>
# [{"PutRequest"=>
# {"Item"=>
# {"hash_key"=>{"N"=>"99"},
# "range_key"=>{"N"=>"99"},
# "attribute"=>{"S"=>"hi"}
# }}}, ... ]}
# For more information:
# http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/API_BatchWriteItems.html
def batch_put_item(request_items)
body = {
'RequestItems' => request_items
}
request(
:body => MultiJson.encode(body),
:headers => {'x-amz-target' => 'DynamoDB_20111205.BatchWriteItem'}
)
end
end
end
end
end

View file

@ -43,6 +43,26 @@ Shindo.tests('Fog::AWS[:dynamodb] | item requests', ['aws']) do
).body
end
@batch_put_item_format = {
'Responses'=> {
@table_name => {
'ConsumedCapacityUnits' => Float}
},
'UnprocessedItems'=> {}
}
tests("#batch_put_item({ '#{@table_name}' => [{ 'PutRequest' => { 'Item' =>
{ 'HashKeyElement' => { 'S' => 'key' }, 'RangeKeyElement' => { 'S' => 'key' }}}}]})"
).formats(@batch_put_item_format) do
pending if Fog.mocking?
Fog::AWS[:dynamodb].batch_put_item(
{@table_name => [{'PutRequest'=> {'Item'=>
{'HashKeyElement' => { 'S' => 'key' },
'RangeKeyElement' => { 'S' => 'key' }
}}}]}
).body
end
@get_item_format = {
'ConsumedCapacityUnits' => Float,
'Item' => {