Module: Ipify
- Defined in:
- lib/ipify.rb,
lib/ipify/version.rb
Constant Summary collapse
- ConnectionError =
Class.new(StandardError)
- ServiceError =
Class.new(StandardError)
- VERSION =
'0.5.0'
Class Method Summary collapse
-
.ip ⇒ String
Requests this machine’s IP address from the ipify.org service.
-
.ip! ⇒ String
Requests this machine’s IP address from the ipify.org service.
Class Method Details
.ip ⇒ String
Requests this machine’s IP address from the ipify.org service. Will retry up to 3 times until ultimately returning nil.
14 15 16 |
# File 'lib/ipify.rb', line 14 def self.ip ip! rescue nil end |
.ip! ⇒ String
Requests this machine’s IP address from the ipify.org service. Will retry up to 3 times until ultimately raising the last exception encountered.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ipify.rb', line 24 def self.ip! http = build_http response = Retriable.retriable tries: 3 do http.get('/') end raise ServiceError, "ipify.org returned status #{response.code}" if '200' != response.code response.body rescue Net::OpenTimeout raise ConnectionError, "ipify.org timed out" end |