Class: AutoPilot::Request
- Inherits:
-
Object
- Object
- AutoPilot::Request
- Includes:
- HTTParty
- Defined in:
- lib/auto_pilot/request.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #get_document(url) ⇒ Object
-
#initialize(url, options = {}) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(url, options = {}) ⇒ Request
Returns a new instance of Request.
20 21 22 23 |
# File 'lib/auto_pilot/request.rb', line 20 def initialize(url, = {}) @url, = AutoPilot::URLFormatter.default_to_http(url), @document = get_document(url) end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
18 19 20 |
# File 'lib/auto_pilot/request.rb', line 18 def document @document end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
18 19 20 |
# File 'lib/auto_pilot/request.rb', line 18 def error @error end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
18 19 20 |
# File 'lib/auto_pilot/request.rb', line 18 def end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
18 19 20 |
# File 'lib/auto_pilot/request.rb', line 18 def url @url end |
Class Method Details
.error ⇒ Object
14 15 16 |
# File 'lib/auto_pilot/request.rb', line 14 def self.error Log.red 'invalid url' end |
.fetch(url, options = {}) ⇒ Object
9 10 11 12 |
# File 'lib/auto_pilot/request.rb', line 9 def self.fetch(url, = {}) error unless url new(url, ).document end |
Instance Method Details
#get_document(url) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/auto_pilot/request.rb', line 25 def get_document(url) response = self.class.get(url, ) throttle log_response(url, response) response rescue => error Log.red "request failed for #{url} #{error}" false end |