Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Can pass strings directly to #post

It is possible to pass a string containing JSON instead of a hash. It
makes possible to use Jedlik with builders such as Jbuilder or
json_builder.
  • Loading branch information...
commit 51d95950eaaba5321658def6d082b64124abed19 1 parent 551618a
@hashmal authored
View
6 README.mkd
@@ -24,6 +24,12 @@ request body.
conn.post :GetItem, {:TableName => "table1", :Key => {:S => "foo"}}
# => Hash
+It is also possible to pass a string that will be used directly for the
+request body:
+
+ conn.post :GetItem, '{"TableName": "table1", "Key": {"S": "foo"}}'
+ # => Hash
+
License
-------
View
2  jedlik.gemspec
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = 'jedlik'
- s.version = '0.0.5'
+ s.version = '0.1.0'
s.summary = "Communicate with Amazon DynamoDB."
s.description = "Communicate with Amazon DynamoDB. Raw access to the full API without having to handle temporary credentials or HTTP requests by yourself."
s.authors = ["Hashmal", "Brandon Keene"]
View
9 lib/jedlik/connection.rb
@@ -31,7 +31,14 @@ def initialize access_key_id, secret_access_key, opts={}
# http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide
#
def post operation, data={}
- request = new_request operation, Yajl::Encoder.encode(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
View
40 spec/jedlik/connection_spec.rb
@@ -3,17 +3,25 @@
describe Jedlik::Connection do
describe "#post" do
- before do
- Time.stub!(:now).and_return(Time.at(1332635893)) # Sat Mar 24 20:38:13 -0400 2012
- end
-
- it "signs and posts a request" do
- mock_service = mock(Jedlik::SecurityTokenService,
+ let(:mock_service) {
+ mock(Jedlik::SecurityTokenService,
:session_token => "session_token",
:access_key_id => "access_key_id",
:secret_access_key => "secret_access_key"
)
+ }
+
+ let(:connection) {
+ Jedlik::Connection.new("key_id", "secret")
+ }
+
+ before do
+ Time.stub!(:now).and_return(Time.at(1332635893)) # Sat Mar 24 20:38:13 -0400 2012
+
+ Jedlik::SecurityTokenService.stub!(:new).and_return(mock_service)
+ end
+ it "signs and posts a request" do
stub_request(:post, "https://dynamodb.us-east-1.amazonaws.com/").
with(
:body => "{}",
@@ -27,15 +35,27 @@
}
).
to_return(
- :status => 200,
- :body => '{"TableNames":["example"]}',
+ :status => 200,
+ :body => '{"TableNames":["example"]}',
:headers => {}
)
- Jedlik::SecurityTokenService.stub!(:new).and_return(mock_service)
- connection = Jedlik::Connection.new("key_id", "secret")
result = connection.post :ListTables
result.should == {"TableNames" => ["example"]}
end
+
+ it "converts a hash to JSON" do
+ stub_request(:post, "https://dynamodb.us-east-1.amazonaws.com/").
+ with(:body => %({"foo":"bar"}))
+
+ connection.post :Query, {:foo => "bar"}
+ end
+
+ it "sends a string as it is" do
+ stub_request(:post, "https://dynamodb.us-east-1.amazonaws.com/").
+ with(:body => %(hello world))
+
+ connection.post :Query, "hello world"
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.