forked from vcr/vcr
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted the http calls from the specs for each http library into mo…
…dules that we can use in our cucumber features to keep things DRY.
- Loading branch information
1 parent
a40025f
commit 49bf733
Showing
6 changed files
with
97 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
module NetHTTPAdapter | ||
def get_body_string(response); response.body; end | ||
|
||
def get_header(header_key, response) | ||
response.get_fields(header_key) | ||
end | ||
|
||
def make_http_request(method, url, body = {}) | ||
case method | ||
when :get | ||
Net::HTTP.get_response(URI.parse(url)) | ||
when :post | ||
Net::HTTP.post_form(URI.parse(url), body) | ||
end | ||
end | ||
end | ||
|
||
module PatronAdapter | ||
def get_body_string(response); response.body; end | ||
|
||
def get_header(header_key, response) | ||
response.headers[header_key] | ||
end | ||
|
||
def make_http_request(method, url, body = {}) | ||
uri = URI.parse(url) | ||
sess = Patron::Session.new | ||
sess.base_url = "#{uri.scheme}://#{uri.host}:#{uri.port}" | ||
|
||
case method | ||
when :get | ||
sess.get(uri.path) | ||
when :post | ||
sess.post(uri.path, body) | ||
end | ||
end | ||
end | ||
|
||
module HTTPClientAdapter | ||
def get_body_string(response) | ||
string = response.body.content | ||
string.respond_to?(:read) ? string.read : string | ||
end | ||
|
||
def get_header(header_key, response) | ||
response.header[header_key] | ||
end | ||
|
||
def make_http_request(method, url, body = {}) | ||
case method | ||
when :get | ||
HTTPClient.new.get(url) | ||
when :post | ||
HTTPClient.new.post(url, body) | ||
end | ||
end | ||
end | ||
|
||
module EmHTTPRequestAdapter | ||
def get_body_string(response) | ||
response.response | ||
end | ||
|
||
def get_header(header_key, response) | ||
response.response_header[header_key.upcase.gsub('-', '_')].split(', ') | ||
end | ||
|
||
def make_http_request(method, url, body = {}) | ||
http = nil | ||
EventMachine.run do | ||
http = case method | ||
when :get then EventMachine::HttpRequest.new(url).get | ||
when :post then EventMachine::HttpRequest.new(url).post :body => body | ||
end | ||
|
||
http.callback { EventMachine.stop } | ||
end | ||
http | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters