ipgeo 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 68c1cb1bc29d9f9a5b7eaccc7e217f510bfdc6ed
4
- data.tar.gz: ec862a01b85fe8ed78cc7bb0feb53553aa465e4e
2
+ SHA256:
3
+ metadata.gz: 563b1bbe0427862838716f371c4778c3976b894d3d1e80f3026153204edec44b
4
+ data.tar.gz: a75fb09520d13a10606e1eeffb0e818bb6c067c2295e1f43a5f6f19db6b94165
5
5
  SHA512:
6
- metadata.gz: bbd08169a069583a9947e29bb8be568784354ec4e5cc689629c99aed8ade5eb9e54993d8ff3880943a1f8e88aaa188acb1bf7e148edd158987db4c5d9590cd96
7
- data.tar.gz: c5bd2b7ac2d0f2f005a9fd5a792bf9a96c996e3d30b82d8032b6b7ab14593a6e64a1eed2fa5777216bf6001941418e4f2d82ebcfba6db290d03d7c7c020fa261
6
+ metadata.gz: 9ae15bc388188531d0fa92afbc93a83b20e6e4a362ca4658373c73683b58162bba8e3b142ad70fcfe891a488a426d16df4902d2bcac92414c94b353337da5672
7
+ data.tar.gz: c5a58bdd73b8b9eb775b3bae2bb4c31af38f21d1568ced84b0dfac9125ab0bf3477da71652d55a027e0090d472352404dc7ea1df29962ae552ccd9f8f7cacb7b
@@ -1,6 +1,7 @@
1
1
  require 'net/https'
2
2
  require 'json'
3
3
  require 'ip_geo/result'
4
+ require 'timeout'
4
5
 
5
6
  module IPGeo
6
7
  class Client
@@ -11,15 +12,20 @@ module IPGeo
11
12
  end
12
13
 
13
14
  def lookup(ip)
14
- Net::HTTP.start(@hostname, @options[:port] || (@options[:ssl] == false ? 80 : 443), :use_ssl => @options[:ssl] != false) do |http|
15
- request = Net::HTTP::Get.new("/#{ip}")
16
- response = http.request(request)
17
- if response.is_a?(Net::HTTPOK)
18
- Result.new(JSON.parse(response.body))
19
- else
20
- false
15
+ Timeout.timeout(@options[:timeout] || 2) do
16
+ Net::HTTP.start(@hostname, @options[:port] || (@options[:ssl] == false ? 80 : 443), :use_ssl => @options[:ssl] != false) do |http|
17
+ request = Net::HTTP::Get.new("/#{ip}")
18
+ response = http.request(request)
19
+ if response.is_a?(Net::HTTPOK)
20
+ Result.new(JSON.parse(response.body))
21
+ else
22
+ false
23
+ end
21
24
  end
22
25
  end
26
+ rescue Exception, Timeout::Error => e
27
+ STDERR.puts "Error during IP lookup of #{ip} with #{@hostname}: #{e.class} (#{e.message})"
28
+ false
23
29
  end
24
30
 
25
31
  end
@@ -1,6 +1,10 @@
1
1
  module IPGeo
2
2
  class Result
3
3
 
4
+ EU_COUNTRY_CODES = ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI",
5
+ "FR", "DE", "GB", "GR", "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL",
6
+ "PL", "PT", "RO", "SK", "SI", "ES", "SE"].freeze
7
+
4
8
  def initialize(hash)
5
9
  @hash = hash
6
10
  end
@@ -29,5 +33,9 @@ module IPGeo
29
33
  @hash['geoname_id']
30
34
  end
31
35
 
36
+ def eu?
37
+ EU_COUNTRY_CODES.include?(country)
38
+ end
39
+
32
40
  end
33
41
  end
@@ -0,0 +1 @@
1
+ require 'ip_geo'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipgeo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-28 00:00:00.000000000 Z
11
+ date: 2018-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -34,6 +34,7 @@ files:
34
34
  - lib/ip_geo.rb
35
35
  - lib/ip_geo/client.rb
36
36
  - lib/ip_geo/result.rb
37
+ - lib/ipgeo.rb
37
38
  homepage: https://github.com/adamcooke/ipgeo-ruby
38
39
  licenses:
39
40
  - MIT
@@ -54,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
55
  version: '0'
55
56
  requirements: []
56
57
  rubyforge_project:
57
- rubygems_version: 2.5.1
58
+ rubygems_version: 2.7.4
58
59
  signing_key:
59
60
  specification_version: 4
60
61
  summary: A client for communicating with an IPGeo server