Class: Embiggen::HtmlClient
- Inherits:
-
Object
- Object
- Embiggen::HtmlClient
- Defined in:
- lib/embiggen/html_client.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #follow(timeout, selector) ⇒ Object
-
#initialize(uri) ⇒ HtmlClient
constructor
A new instance of HtmlClient.
Constructor Details
#initialize(uri) ⇒ HtmlClient
Returns a new instance of HtmlClient.
9 10 11 12 13 |
# File 'lib/embiggen/html_client.rb', line 9 def initialize(uri) @uri = uri @http = ::Net::HTTP.new(uri.host, uri.port) @http.use_ssl = true if uri.scheme == 'https' end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/embiggen/html_client.rb', line 7 def uri @uri end |
Instance Method Details
#follow(timeout, selector) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/embiggen/html_client.rb', line 15 def follow(timeout, selector) response = request(timeout) return unless response.is_a?(::Net::HTTPOK) document = Nokogiri::HTML(response.body) element = document.at_css(selector) element&.[]('href') rescue ::Timeout::Error => e raise NetworkError.new( "Timeout::Error: could not follow #{uri}: #{e.}", uri ) rescue StandardError => e raise NetworkError.new( "StandardError: could not follow #{uri}: #{e.}", uri ) end |