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

deprecate but fallback to older api support

This commit is contained in:
Damien Mathieu 2015-12-23 16:24:02 +01:00
parent 9e5c3be923
commit b190a36857
2 changed files with 21 additions and 5 deletions

View file

@ -26,14 +26,22 @@ module Fog
#
# See DynamoDB Documentation: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html
#
def query(table_name, options = {})
def query(table_name, options = {}, hash_key_deprecated = nil)
if hash_key_deprecated || (options.keys.length == 1 && [:S, :N, :B].include?(options.keys.first.to_sym))
Fog::Logger.deprecation("The `20111205` API version is deprecated. You need to use `KeyConditionExpression` instead of `HashKey`.")
apiVersion = '20111205'
hash_key = options
options = hash_key_deprecated
end
body = {
'TableName' => table_name
'TableName' => table_name,
'HashKeyValue' => hash_key
}.merge(options)
request(
:body => Fog::JSON.encode(body),
:headers => {'x-amz-target' => 'DynamoDB_20120810.Query'}
:headers => {'x-amz-target' => "DynamoDB_#{apiVersion || '20120810'}.Query"}
)
end
end

View file

@ -2,6 +2,7 @@ module Fog
module AWS
class DynamoDB
class Real
class DeprecatedAttributeUpdates < Exception; end
# Update DynamoDB item
#
# ==== Parameters
@ -24,10 +25,17 @@ module Fog
#
# See DynamoDB Documentation: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html
#
def update_item(table_name, key, options = {})
def update_item(table_name, key, options = {}, deprecated_attribute_updates = nil)
if deprecated_attribute_updates
raise DeprecatedAttributeUpdates, "The `20111205` DynamoDB API is deprecated. You need to use `ExpressionAttributeValues` instead of `AttributeUpdates`."
attribute_updates = options
options = deprecated_attribute_updates
end
body = {
'Key' => key,
'TableName' => table_name
'TableName' => table_name,
'AttributeUpdates' => attribute_updates,
}.merge(options)
request(