Class: Jedlik::Connection
- Inherits:
-
Object
- Object
- Jedlik::Connection
- Defined in:
- lib/jedlik/connection.rb
Overview
Establishes a connection to Amazon DynamoDB using credentials.
Constant Summary collapse
- DEFAULTS =
{ :endpoint => 'dynamodb.us-east-1.amazonaws.com', }
Instance Attribute Summary collapse
-
#sts ⇒ Object
readonly
Returns the value of attribute sts.
Instance Method Summary collapse
-
#initialize(access_key_id, secret_access_key, opts = {}) ⇒ Connection
constructor
Acceptable ‘opts` keys are:.
-
#post(operation, data = {}) ⇒ Object
Create and send a request to DynamoDB.
Constructor Details
#initialize(access_key_id, secret_access_key, opts = {}) ⇒ Connection
Acceptable ‘opts` keys are:
:endpoint # DynamoDB endpoint to use.
# Default: 'dynamodb.us-east-1.amazonaws.com'
18 19 20 21 22 23 |
# File 'lib/jedlik/connection.rb', line 18 def initialize access_key_id, secret_access_key, opts={} opts = DEFAULTS.merge opts @sts = SecurityTokenService.new access_key_id, secret_access_key @endpoint = opts[:endpoint] @debug = opts[:debug] end |
Instance Attribute Details
#sts ⇒ Object (readonly)
Returns the value of attribute sts.
7 8 9 |
# File 'lib/jedlik/connection.rb', line 7 def sts @sts end |
Instance Method Details
#post(operation, data = {}) ⇒ Object
Create and send a request to DynamoDB. Returns a hash extracted from the response body.
‘operation` can be any DynamoDB operation. `data` is a hash that will be used as the request body (in JSON format). More info available at:
docs.amazonwebservices.com/amazondynamodb/latest/developerguide
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jedlik/connection.rb', line 33 def post operation, data={} body = case data when String body = data else Yajl::Encoder.encode(data) end request = new_request operation, body request.sign sts hydra.queue request hydra.run response = request.response puts response.inspect if @debug if response.code == 200 Yajl::Parser.parse response.body else raise_error response end end |