Class: AutoPilot::Request

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/auto_pilot/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  @url, @options = AutoPilot::URLFormatter.default_to_http(url), options
  @document = get_document(url)
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



18
19
20
# File 'lib/auto_pilot/request.rb', line 18

def document
  @document
end

#errorObject (readonly)

Returns the value of attribute error.



18
19
20
# File 'lib/auto_pilot/request.rb', line 18

def error
  @error
end

#optionsObject (readonly)

Returns the value of attribute options.



18
19
20
# File 'lib/auto_pilot/request.rb', line 18

def options
  @options
end

#urlObject (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

.errorObject



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, options = {})
  error unless url
  new(url, options).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, options)
  throttle
  log_response(url, response)
  response
rescue => error
  Log.red "request failed for #{url} #{error}"
  false
end