lib/mako/feed_requester.rb in mako_rss-0.1.0 vs lib/mako/feed_requester.rb in mako_rss-0.2.0
- old
+ new
@@ -1,35 +1,37 @@
# frozen_string_literal: true
module Mako
class FeedRequester
attr_reader :feed_url
- attr_accessor :ok, :body
+ attr_accessor :ok, :body, :headers
def initialize(args)
@ok = true
@body = ''
+ @headers = {}
@feed_url = args.fetch(:feed_url)
end
# Performs HTTP request on the given feed_url. Sets the Mako::FeedRequester
# body attribute equal to the request body if successful and returns self.
# If the request fails, @ok is set to false.
#
# @return [Mako::FeedRequester]
def fetch
begin
- request = Faraday.get(feed_url)
- rescue Faraday::Error
+ request = HTTParty.get(feed_url)
+ rescue SocketError
Mako.errors.add_error "Could not complete request to #{feed_url}."
self.ok = false
return self
end
- unless request.status == 200
- Mako.errors.add_error "Request to #{feed_url} returned #{request.status}."
+ unless request.code == 200
+ Mako.errors.add_error "Request to #{feed_url} returned #{request.code}."
self.ok = false
return self
end
+ self.headers = request.headers
self.body = request.body
self
end
# Predicate method returning the value of @ok