Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to specify a body request given a Hash #46

Merged
merged 1 commit into from
Feb 22, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/httpi/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ def gzip
headers["Accept-Encoding"] = "gzip,deflate"
end

attr_accessor :body, :open_timeout, :read_timeout
attr_accessor :open_timeout, :read_timeout
attr_reader :body

# Sets a body request given a String or a Hash.
def body=(params)
@body = params.kind_of?(Hash) ? Rack::Utils.build_query(params) : params
end

# Returns the <tt>HTTPI::Authentication</tt> object.
def auth
Expand Down
7 changes: 6 additions & 1 deletion spec/httpi/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,15 @@
end

describe "#body" do
it "lets you specify the HTTP request body" do
it "lets you specify the HTTP request body using a String" do
request.body = "<some>xml</some>"
request.body.should == "<some>xml</some>"
end

it "lets you specify the HTTP request body using a Hash" do
request.body = {:foo => :bar, :baz => :foo}
request.body.should == "foo=bar&baz=foo"
end
end

describe "#open_timeout" do
Expand Down