ipify 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/ipify.rb +13 -4
- 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: 0f6ed2e822a7daffac35154bf508112e4d6df5df
|
4
|
+
data.tar.gz: c1832e18eba09cd705e8c45632fbb373eee21779
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ee22bb67a8ff713295afc629c8de6a3b99c20bb494519254c58f25296fd52cf02431567ff424fbb98985a6458bd2097da188396d9dcb19c856ddcb4e61833ae
|
7
|
+
data.tar.gz: 44e842f67c93881e163aef294cc6a46bfa2266f23988b1951e54820599385b0375b73d8ac09f770f938b9dd979ab7516a35d34066d71ef442e2916c038e824f9
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Ipify [![Build Status](https://travis-ci.org/code-lever/ipify-gem.png)](https://travis-ci.org/code-lever/ipify-gem) [![Dependency Status](https://gemnasium.com/code-lever/ipify-gem.png)](https://gemnasium.com/code-lever/ipify-gem) [![Code Climate](https://codeclimate.com/github/code-lever/ipify-gem.png)](https://codeclimate.com/github/code-lever/ipify-gem)
|
1
|
+
# Ipify [![Build Status](https://travis-ci.org/code-lever/ipify-gem.png)](https://travis-ci.org/code-lever/ipify-gem) [![Dependency Status](https://gemnasium.com/code-lever/ipify-gem.png)](https://gemnasium.com/code-lever/ipify-gem) [![Code Climate](https://codeclimate.com/github/code-lever/ipify-gem.png)](https://codeclimate.com/github/code-lever/ipify-gem) [![Gem Version](https://badge.fury.io/rb/ipify.svg)](http://badge.fury.io/rb/ipify)
|
2
2
|
|
3
3
|
An unofficial [ipify](http://ipify.org) Ruby gem. Get your external IP address.
|
4
4
|
|
data/lib/ipify.rb
CHANGED
@@ -4,6 +4,9 @@ require 'retriable'
|
|
4
4
|
|
5
5
|
module Ipify
|
6
6
|
|
7
|
+
ConnectionError = Class.new(StandardError)
|
8
|
+
ServiceError = Class.new(StandardError)
|
9
|
+
|
7
10
|
# Requests this machine's IP address from the ipify.org service. Will retry up to 3 times
|
8
11
|
# until ultimately returning +nil+.
|
9
12
|
#
|
@@ -16,11 +19,17 @@ module Ipify
|
|
16
19
|
# until ultimately raising the last exception encountered.
|
17
20
|
#
|
18
21
|
# @return [String] external ip address
|
22
|
+
# @raise [Ipify::ConnectionError] if unable to reach the ipify service
|
23
|
+
# @raise [Ipify::ServiceError] if the ipify service returns status other than 200(OK)
|
19
24
|
def self.ip!
|
20
25
|
http = build_http
|
21
|
-
Retriable.retriable tries: 3 do
|
22
|
-
http.get('/')
|
26
|
+
response = Retriable.retriable tries: 3 do
|
27
|
+
http.get('/')
|
23
28
|
end
|
29
|
+
raise ServiceError, "ipify.org returned status #{response.code}" if '200' != response.code
|
30
|
+
response.body
|
31
|
+
rescue Net::OpenTimeout
|
32
|
+
raise ConnectionError, "ipify.org timed out"
|
24
33
|
end
|
25
34
|
|
26
35
|
private
|
@@ -30,8 +39,8 @@ module Ipify
|
|
30
39
|
uri = URI('https://api.ipify.org')
|
31
40
|
http = Net::HTTP.new(uri.host, uri.port)
|
32
41
|
http.use_ssl = true
|
33
|
-
http.open_timeout =
|
34
|
-
http.read_timeout =
|
42
|
+
http.open_timeout = 1
|
43
|
+
http.read_timeout = 1
|
35
44
|
http
|
36
45
|
end
|
37
46
|
|
data/lib/ipify/version.rb
CHANGED