Class: Mako::FeedRequester
- Inherits:
-
Object
- Object
- Mako::FeedRequester
- Defined in:
- lib/mako/feed_requester.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#feed_url ⇒ Object
readonly
Returns the value of attribute feed_url.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#ok ⇒ Object
Returns the value of attribute ok.
Instance Method Summary collapse
-
#fetch ⇒ Mako::FeedRequester
Performs HTTP request on the given feed_url.
-
#initialize(args) ⇒ FeedRequester
constructor
A new instance of FeedRequester.
-
#ok? ⇒ Boolean
Predicate method returning the value of @ok.
Constructor Details
#initialize(args) ⇒ FeedRequester
8 9 10 11 12 13 |
# File 'lib/mako/feed_requester.rb', line 8 def initialize(args) @ok = true @body = '' @headers = {} @feed_url = args.fetch(:feed_url) end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
6 7 8 |
# File 'lib/mako/feed_requester.rb', line 6 def body @body end |
#feed_url ⇒ Object (readonly)
Returns the value of attribute feed_url.
5 6 7 |
# File 'lib/mako/feed_requester.rb', line 5 def feed_url @feed_url end |
#headers ⇒ Object
Returns the value of attribute headers.
6 7 8 |
# File 'lib/mako/feed_requester.rb', line 6 def headers @headers end |
#ok ⇒ Object
Returns the value of attribute ok.
6 7 8 |
# File 'lib/mako/feed_requester.rb', line 6 def ok @ok end |
Instance Method Details
#fetch ⇒ Mako::FeedRequester
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.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mako/feed_requester.rb', line 20 def fetch begin request = HTTParty.get(feed_url) rescue StandardError => e Mako.errors.add_error "Could not complete request to #{feed_url}: #{e.class}." self.ok = false return self end 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 |
#ok? ⇒ Boolean
Predicate method returning the value of @ok
41 42 43 |
# File 'lib/mako/feed_requester.rb', line 41 def ok? ok end |