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, &block) ⇒ 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.
103 104 105 106 |
# File 'lib/spidy/connector.rb', line 103 def initialize(connector, socks_proxy) @connector = connector @socks_proxy = socks_proxy end |
Instance Attribute Details
#connector ⇒ Object (readonly)
Returns the value of attribute connector.
101 102 103 |
# File 'lib/spidy/connector.rb', line 101 def connector @connector end |
#socks_proxy ⇒ Object (readonly)
Returns the value of attribute socks_proxy.
101 102 103 |
# File 'lib/spidy/connector.rb', line 101 def socks_proxy @socks_proxy end |
Instance Method Details
#call(url, &block) ⇒ Object
108 109 110 111 112 |
# File 'lib/spidy/connector.rb', line 108 def call(url, &block) Socksify.proxy(socks_proxy[:host], socks_proxy[:port]) do connector.call(url, &block) end end |
#try_connection! ⇒ Object
121 122 123 |
# File 'lib/spidy/connector.rb', line 121 def try_connection! Tor::Controller.new(host: @socks_proxy[:host], port: @socks_proxy[:port]).close end |
#try_connection? ⇒ Boolean
114 115 116 117 118 119 |
# File 'lib/spidy/connector.rb', line 114 def try_connection? try_connection! true rescue Errno::ECONNREFUSED false end |