class Mako::FeedRequester

Attributes

body[RW]
feed_url[R]
headers[RW]
ok[RW]

Public Class Methods

new(args) click to toggle source
# File lib/mako/feed_requester.rb, line 8
def initialize(args)
  @ok = true
  @body = ''
  @headers = {}
  @feed_url = args.fetch(:feed_url)
end

Public Instance Methods

fetch() click to toggle source

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]

# 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?() click to toggle source

Predicate method returning the value of @ok

@return [Boolean]

# File lib/mako/feed_requester.rb, line 41
def ok?
  ok
end