Class: Spidy::Connector::TorConnector
- Inherits:
-
Object
- Object
- Spidy::Connector::TorConnector
- Defined in:
- lib/spidy/connector.rb
Overview
tor proxy
Instance Attribute Summary collapse
-
#connector ⇒ Object
readonly
Returns the value of attribute connector.
-
#socks_proxy ⇒ Object
readonly
Returns the value of attribute socks_proxy.
Instance Method Summary collapse
- #call(url) ⇒ Object
-
#initialize(connector, socks_proxy) ⇒ TorConnector
constructor
A new instance of TorConnector.
- #try_connection! ⇒ Object
- #try_connection? ⇒ Boolean
Constructor Details
#initialize(connector, socks_proxy) ⇒ TorConnector
Returns a new instance of TorConnector.
102 103 104 105 |
# File 'lib/spidy/connector.rb', line 102 def initialize(connector, socks_proxy) @connector = connector @socks_proxy = socks_proxy end |
Instance Attribute Details
#connector ⇒ Object (readonly)
Returns the value of attribute connector.
100 101 102 |
# File 'lib/spidy/connector.rb', line 100 def connector @connector end |
#socks_proxy ⇒ Object (readonly)
Returns the value of attribute socks_proxy.
100 101 102 |
# File 'lib/spidy/connector.rb', line 100 def socks_proxy @socks_proxy end |
Instance Method Details
#call(url) ⇒ Object
107 108 109 110 111 |
# File 'lib/spidy/connector.rb', line 107 def call(url, &) Socksify.proxy(socks_proxy[:host], socks_proxy[:port]) do connector.call(url, &) end end |
#try_connection! ⇒ Object
120 121 122 |
# File 'lib/spidy/connector.rb', line 120 def try_connection! Tor::Controller.new(host: @socks_proxy[:host], port: @socks_proxy[:port]).close end |
#try_connection? ⇒ Boolean
113 114 115 116 117 118 |
# File 'lib/spidy/connector.rb', line 113 def try_connection? try_connection! true rescue Errno::ECONNREFUSED false end |