Class: HttpFetcher
- Inherits:
-
Object
- Object
- HttpFetcher
- Defined in:
- lib/http_fetcher.rb
Overview
Fetches the content of a given URL and returns its body only if the HTTP request receives a 200 response.
Class Method Summary collapse
Class Method Details
.call(url) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/http_fetcher.rb', line 5 def self.call(url) uri = ::URI.parse(url) response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(Net::HTTP::Get.new(uri.request_uri)) end response.body if response.code == '200' end |