Module: NewsScraper::ExtractorsHelpers
- Defined in:
- lib/news_scraper/extractors_helpers.rb
Instance Method Summary collapse
-
#http_request(url) ⇒ Object
Perform an HTTP request with a standardized response.
Instance Method Details
#http_request(url) ⇒ Object
Perform an HTTP request with a standardized response
Params
-
url
: the url on which to perform a get request
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/news_scraper/extractors_helpers.rb', line 8 def http_request(url) url = URIParser.new(url).with_scheme CLI.put_header(url) CLI.log "Beginning HTTP request for #{url}" response = HTTParty.get(url, headers: { "User-Agent" => "news-scraper-#{NewsScraper::VERSION}" }) raise ResponseError.new( error_code: response.code, message: response., url: url ) unless response.code == 200 CLI.log "#{response.code} - #{response.}. Request successful for #{url}" CLI. if block_given? yield response else response end end |