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:
parent
a36c3aaf67
commit
241ac21910
3 changed files with 51 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ module Fog
|
||||||
|
|
||||||
request_path 'fog/aws/requests/dynamodb'
|
request_path 'fog/aws/requests/dynamodb'
|
||||||
request :batch_get_item
|
request :batch_get_item
|
||||||
|
request :batch_put_item
|
||||||
request :create_table
|
request :create_table
|
||||||
request :delete_item
|
request :delete_item
|
||||||
request :delete_table
|
request :delete_table
|
||||||
|
|
|
||||||
30
lib/fog/aws/requests/dynamodb/batch_put_item.rb
Normal file
30
lib/fog/aws/requests/dynamodb/batch_put_item.rb
Normal 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
|
||||||
|
|
@ -43,6 +43,26 @@ Shindo.tests('Fog::AWS[:dynamodb] | item requests', ['aws']) do
|
||||||
).body
|
).body
|
||||||
end
|
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 = {
|
@get_item_format = {
|
||||||
'ConsumedCapacityUnits' => Float,
|
'ConsumedCapacityUnits' => Float,
|
||||||
'Item' => {
|
'Item' => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue