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.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/meta_inspector/request.rb', line 12 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] @faraday_options = [:faraday_options] || {} @faraday_http_cache = [:faraday_http_cache] response # request early so we can fail early end |
Instance Method Details
#content_type ⇒ Object
34 35 36 37 |
# File 'lib/meta_inspector/request.rb', line 34 def content_type return nil if response.headers['content-type'].nil? response.headers['content-type'].split(';')[0] if response end |
#read ⇒ Object
30 31 32 |
# File 'lib/meta_inspector/request.rb', line 30 def read response.body if response end |
#response ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/meta_inspector/request.rb', line 39 def response @response ||= fetch rescue Faraday::TimeoutError, Faraday::Error::ConnectionFailed, Faraday::SSLError, RuntimeError, URI::InvalidURIError => e @exception_log << e nil end |