Skip to content

Commit

Permalink
Renaming request_preparation to connection. That makes more sense to me
Browse files Browse the repository at this point in the history
  • Loading branch information
mwunsch committed Mar 6, 2010
1 parent 2357527 commit c63bc78
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
20 changes: 8 additions & 12 deletions lib/weary/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(url, http_verb= :get, options={})
# Create a URI object for the given URL
def uri=(url)
@uri = URI.parse(url)
if (with && !request_preparation.request_body_permitted?)
if (with && !connection.request_body_permitted?)
@uri.query = with
end
end
Expand All @@ -41,7 +41,7 @@ def via
# set the query string for the url.
def with=(params)
@with = (params.respond_to?(:to_params) ? params.to_params : params)
if (!request_preparation.request_body_permitted?)
if (!connection.request_body_permitted?)
uri.query = @with
end
end
Expand Down Expand Up @@ -104,14 +104,14 @@ def perform!(&block)

# Build the HTTP connection.
def http
connection = Net::HTTP.new(uri.host, uri.port)
connection.verify_mode = OpenSSL::SSL::VERIFY_NONE if connection.use_ssl?
connection
socket = Net::HTTP.new(uri.host, uri.port)
socket.verify_mode = OpenSSL::SSL::VERIFY_NONE if socket.use_ssl?
socket
end

# Build the HTTP Request.
def request
req = request_preparation
req = connection

req.body = with if (with && req.request_body_permitted?)
if (credentials)
Expand All @@ -122,11 +122,7 @@ def request
end
end

if headers
headers.each_pair do |key, value|
req[key] = value
end
end
headers.each_pair {|key,value| req[key] = value } if headers

req
end
Expand All @@ -136,7 +132,7 @@ def request
# Prepare with `request_preparation`
# Build with `request`
# Fire with `perform`
def request_preparation
def connection
HTTPVerb.new(via).request_class.new(uri.request_uri)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/weary/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

it 'maps to a Net/HTTPRequest class' do
test = Weary::Request.new("http://google.com")
test.request_preparation.class.should == Net::HTTP::Get
test.connection.class.should == Net::HTTP::Get
end

describe 'Request' do
Expand Down

0 comments on commit c63bc78

Please sign in to comment.