ipify 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ipify.rb +13 -0
- data/lib/ipify/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46049822ec6b7e96bfa5cba35ea23deb488121b0
|
4
|
+
data.tar.gz: f0bfbe5590f2b0db342d2d1de3d8d78d1db14c35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 243b954291d381cccd564d5145e2990fa497171ef43c8acfe8c013055eb60afb04298791cbfc7ee635dab985c1dba7968b383bc3e3127549a0387ecbb22e38b1
|
7
|
+
data.tar.gz: 2292821c3a48c65b9b7904ab499b8d50fdc4c4eca89fdeae515661f6ff8f2257cd82d372385e02a8169576284dbe678ef9b55bccb6408e2a54eff9aea9b89a43
|
data/lib/ipify.rb
CHANGED
@@ -4,7 +4,19 @@ require 'retriable'
|
|
4
4
|
|
5
5
|
module Ipify
|
6
6
|
|
7
|
+
# Requests this machine's IP address from the ipify.org service. Will retry up to 3 times
|
8
|
+
# until ultimately returning +nil+.
|
9
|
+
#
|
10
|
+
# @return [String] external ip address, or +nil+ if unsuccessful
|
7
11
|
def self.ip
|
12
|
+
ip! rescue nil
|
13
|
+
end
|
14
|
+
|
15
|
+
# Requests this machine's IP address from the ipify.org service. Will retry up to 3 times
|
16
|
+
# until ultimately raising the last exception encountered.
|
17
|
+
#
|
18
|
+
# @return [String] external ip address
|
19
|
+
def self.ip!
|
8
20
|
http = build_http
|
9
21
|
Retriable.retriable tries: 3 do
|
10
22
|
http.get('/').body
|
@@ -13,6 +25,7 @@ module Ipify
|
|
13
25
|
|
14
26
|
private
|
15
27
|
|
28
|
+
# @return [Net::HTTP] http client
|
16
29
|
def self.build_http
|
17
30
|
uri = URI('https://api.ipify.org')
|
18
31
|
http = Net::HTTP.new(uri.host, uri.port)
|
data/lib/ipify/version.rb
CHANGED