Class: Omnivore::HttpClient
- Inherits:
-
Object
- Object
- Omnivore::HttpClient
- Defined in:
- lib/omnivore/http_client.rb
Overview
A simple HTTP client with a redirect feature.
Class Method Summary collapse
-
.get(url, redirects = 3) ⇒ String
Sends a ‘GET` request to the specified url, following the provided number of maximum redirects.
Class Method Details
.get(url, redirects = 3) ⇒ String
Sends a ‘GET` request to the specified url, following the provided number of maximum redirects.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/omnivore/http_client.rb', line 15 def self.get(url, redirects=3) raise ArgumentError, 'HTTP redirect too deep' if redirects == 0 response = Net::HTTP.get_response(URI.parse(url)) case response when Net::HTTPSuccess then response.body when Net::HTTPRedirection then HttpClient.get(response['location'], redirects - 1) else response.error! end end |