Module: UsefulUtilities::Api
Overview
API utilities
Constant Summary collapse
- RESCUE_PORT_OPEN_EXCEPTIONS =
Note:
Exceptions to handle
[ StandardError, SocketError, Timeout::Error].freeze
Instance Method Summary collapse
-
#convert_limit(value) ⇒ FalseClass/Numeric
False if value is infinity or value if not.
-
#port_open?(ip, port, sleep_time: 1, max_attempts: 3) ⇒ Boolean
Check if a port is open or not on a remote host.
Instance Method Details
#convert_limit(value) ⇒ FalseClass/Numeric
Returns false if value is infinity or value if not.
18 19 20 |
# File 'lib/useful_utilities/api.rb', line 18 def convert_limit(value) value == Float::INFINITY ? false : value end |
#port_open?(ip, port, sleep_time: 1, max_attempts: 3) ⇒ Boolean
Returns check if a port is open or not on a remote host.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/useful_utilities/api.rb', line 27 def port_open?(ip, port, sleep_time: 1, max_attempts: 3) try_to(max_attempts: max_attempts, sleep_time: sleep_time, rescue_what: RESCUE_PORT_OPEN_EXCEPTIONS) do Timeout::timeout(sleep_time) do TCPSocket.new(ip, port).close true end end rescue *RESCUE_PORT_OPEN_EXCEPTIONS false end |