Permalink
Browse files

more convenience methods

  • Loading branch information...
1 parent a4a196c commit 594e9dc1aff01b23e1ca259869d0d0b31711ad13 @pezra committed Jan 26, 2010
Showing with 63 additions and 2 deletions.
  1. +2 −2 History.txt
  2. +20 −0 lib/resourceful/simple.rb
  3. +41 −0 spec/resourceful_spec.rb
View
4 History.txt
@@ -1,7 +1,7 @@
-Version Next
+Version 1.0.0
============
* Added .request() convenience method to Resourceful module.
-
+ * Added .get(), .post(), .put(), .delete() and .head() convenience method to Resourceful module
Version 0.7.0
=============
View
20 lib/resourceful/simple.rb
@@ -11,6 +11,26 @@ def default_accessor
def add_authenticator(an_authenticator)
default_accessor.add_authenticator(an_authenticator)
end
+
+ def get(uri, header = {})
+ request(:get, uri, header)
+ end
+
+ def head(uri, header = {})
+ request(:head, uri, header)
+ end
+
+ def delete(uri, header = {})
+ request(:delete, uri, header)
+ end
+
+ def post(uri, data = nil, header = {})
+ request(:post, uri, header, data)
+ end
+
+ def put(uri, data = nil, header = {})
+ request(:put, uri, header, data)
+ end
end
end
View
41 spec/resourceful_spec.rb
@@ -30,6 +30,47 @@
Resourceful.request(:get, 'http://foo.invalid/bar', {}, 'body')
end
+ it "should allow convenient get requests" do
+ stub_resource = mock(:resource)
+ Resourceful.default_accessor.should_receive(:resource).with( 'http://foo.invalid/bar').and_return(stub_resource)
+ stub_resource.should_receive(:request).with(:get, nil, :header_marker)
+
+ Resourceful.get 'http://foo.invalid/bar', :header_marker
+ end
+
+ it "should allow convenient head requests" do
+ stub_resource = mock(:resource)
+ Resourceful.default_accessor.should_receive(:resource).with( 'http://foo.invalid/bar').and_return(stub_resource)
+ stub_resource.should_receive(:request).with(:head, nil, :header_marker)
+
+ Resourceful.head 'http://foo.invalid/bar', :header_marker
+ end
+
+ it "should allow convenient delete requests" do
+ stub_resource = mock(:resource)
+ Resourceful.default_accessor.should_receive(:resource).with( 'http://foo.invalid/bar').and_return(stub_resource)
+ stub_resource.should_receive(:request).with(:delete, nil, :header_marker)
+
+ Resourceful.delete 'http://foo.invalid/bar', :header_marker
+ end
+
+ it "should allow convenient post requests" do
+ stub_resource = mock(:resource)
+ Resourceful.default_accessor.should_receive(:resource).with( 'http://foo.invalid/bar').and_return(stub_resource)
+ stub_resource.should_receive(:request).with(:post, :body_marker, :header_marker)
+
+ Resourceful.post 'http://foo.invalid/bar', :body_marker, :header_marker
+ end
+
+ it "should allow convenient put requests" do
+ stub_resource = mock(:resource)
+ Resourceful.default_accessor.should_receive(:resource).with( 'http://foo.invalid/bar').and_return(stub_resource)
+ stub_resource.should_receive(:request).with(:put, :body_marker, :header_marker)
+
+ Resourceful.put 'http://foo.invalid/bar', :body_marker, :header_marker
+ end
+
+
it "should allow new authenticators to be added to default accessor" do
Resourceful.default_accessor.should_receive(:add_authenticator).with(:my_authentcator_marker)

0 comments on commit 594e9dc

Please sign in to comment.