ipify 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46049822ec6b7e96bfa5cba35ea23deb488121b0
4
- data.tar.gz: f0bfbe5590f2b0db342d2d1de3d8d78d1db14c35
3
+ metadata.gz: 0f6ed2e822a7daffac35154bf508112e4d6df5df
4
+ data.tar.gz: c1832e18eba09cd705e8c45632fbb373eee21779
5
5
  SHA512:
6
- metadata.gz: 243b954291d381cccd564d5145e2990fa497171ef43c8acfe8c013055eb60afb04298791cbfc7ee635dab985c1dba7968b383bc3e3127549a0387ecbb22e38b1
7
- data.tar.gz: 2292821c3a48c65b9b7904ab499b8d50fdc4c4eca89fdeae515661f6ff8f2257cd82d372385e02a8169576284dbe678ef9b55bccb6408e2a54eff9aea9b89a43
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
 
@@ -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('/').body
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 = 10
34
- http.read_timeout = 5
42
+ http.open_timeout = 1
43
+ http.read_timeout = 1
35
44
  http
36
45
  end
37
46
 
@@ -1,3 +1,3 @@
1
1
  module Ipify
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Veys