Class: MetaInspector::Request
- Inherits:
-
Object
- Object
- MetaInspector::Request
- Extended by:
- Forwardable
- Includes:
- Exceptionable
- Defined in:
- lib/meta_inspector/request.rb
Overview
Makes the request to the server
Instance Method Summary collapse
- #content_type ⇒ Object
-
#initialize(initial_url, options = {}) ⇒ Request
constructor
A new instance of Request.
- #read ⇒ Object
- #response ⇒ Object
Constructor Details
#initialize(initial_url, options = {}) ⇒ Request
Returns a new instance of Request.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/meta_inspector/request.rb', line 11 def initialize(initial_url, = {}) @url = initial_url @allow_redirections = [:allow_redirections] @connection_timeout = [:connection_timeout] @read_timeout = [:read_timeout] @retries = [:retries] @exception_log = [:exception_log] @headers = [:headers] response # request early so we can fail early end |
Instance Method Details
#content_type ⇒ Object
31 32 33 34 |
# File 'lib/meta_inspector/request.rb', line 31 def content_type return nil if response.headers['content-type'].nil? response.headers['content-type'].split(';')[0] if response end |
#read ⇒ Object
27 28 29 |
# File 'lib/meta_inspector/request.rb', line 27 def read response.body if response end |
#response ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/meta_inspector/request.rb', line 36 def response @response ||= fetch rescue Faraday::TimeoutError, Faraday::Error::ConnectionFailed, RuntimeError, URI::InvalidURIError => e @exception_log << e nil end |