Class: DynamoDB::SuccessResponse
- Inherits:
-
Object
- Object
- DynamoDB::SuccessResponse
- Defined in:
- lib/dynamodb/success_response.rb
Overview
Successful response from Dynamo
Instance Attribute Summary collapse
-
#http_response ⇒ Object
readonly
Returns the value of attribute http_response.
Instance Method Summary collapse
- #body ⇒ Object
-
#data ⇒ Object
Access the deserialized JSON response body.
- #hash_key_element ⇒ Object
-
#initialize(http_response) ⇒ SuccessResponse
constructor
A new instance of SuccessResponse.
-
#item ⇒ Object
Return single item response as a Hash.
-
#items ⇒ Object
Return an Array of item responses.
- #range_key_element ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(http_response) ⇒ SuccessResponse
Returns a new instance of SuccessResponse.
6 7 8 |
# File 'lib/dynamodb/success_response.rb', line 6 def initialize(http_response) @http_response = http_response end |
Instance Attribute Details
#http_response ⇒ Object (readonly)
Returns the value of attribute http_response.
4 5 6 |
# File 'lib/dynamodb/success_response.rb', line 4 def http_response @http_response end |
Instance Method Details
#body ⇒ Object
42 43 44 |
# File 'lib/dynamodb/success_response.rb', line 42 def body http_response.body end |
#data ⇒ Object
Access the deserialized JSON response body
47 48 49 |
# File 'lib/dynamodb/success_response.rb', line 47 def data @data ||= MultiJson.load(http_response.body) end |
#hash_key_element ⇒ Object
10 11 12 |
# File 'lib/dynamodb/success_response.rb', line 10 def hash_key_element DynamoDB.deserialize(data["LastEvaluatedKey"]["HashKeyElement"]) end |
#item ⇒ Object
Return single item response as a Hash
Some DynamoDB operations, such as ‘GetItem`, will only return a single ’Item’ entry. This converts that entry in a Hash where values have been type-casted into their Ruby equivalents.
23 24 25 26 |
# File 'lib/dynamodb/success_response.rb', line 23 def item return unless data["Item"] @item ||= DynamoDB.deserialize(data["Item"]) end |
#items ⇒ Object
Return an Array of item responses
DynamoDB operations like ‘Query` return a collection of entries under the ’Items’ key. This returns an Array of Hashes where values have been casted to their Ruby equivalents.
33 34 35 36 |
# File 'lib/dynamodb/success_response.rb', line 33 def items return unless data["Items"] @items ||= data["Items"].map { |i| DynamoDB.deserialize(i) } end |
#range_key_element ⇒ Object
14 15 16 |
# File 'lib/dynamodb/success_response.rb', line 14 def range_key_element DynamoDB.deserialize(data["LastEvaluatedKey"]["RangeKeyElement"]) end |
#success? ⇒ Boolean
38 39 40 |
# File 'lib/dynamodb/success_response.rb', line 38 def success? true end |