geolocate 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/geolocate.rb +34 -0
- data/lib/geolocate/result.rb +15 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d6a7eba2569435775f2c246f26f99382283ab8c8
|
4
|
+
data.tar.gz: 8208221df416696fbc6285217e09f09a5c64ea80
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 06a326ef569cef705bcca6af4ea53e491222be309708b4b0315f7b4ffa841e8fad2122687a72224d0ddb4448d1eb46d88bbeb5b9dbf0e4df2a5aadc2af79e845
|
7
|
+
data.tar.gz: 18f4b69205d95e8ebd6df2d4f5495a7a0b6d0750e18d31590435a4be4b9889ef0cebfa762e2b0280526201e7a3009070568a3c8ff70278bb756ded1d6374a3a3
|
data/lib/geolocate.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'geolocate/result'
|
4
|
+
|
5
|
+
module Geolocate
|
6
|
+
|
7
|
+
def self.find_from_ip(ip, options = {})
|
8
|
+
return nil unless ip =~ /\A(\d+)\.(\d+)\.(\d+)\.(\d+)\z/
|
9
|
+
options[:timeout] ||= 4
|
10
|
+
Timeout.timeout(options[:timeout]) do
|
11
|
+
result = Net::HTTP.get("ip-api.com", "/json/#{ip}") rescue nil
|
12
|
+
if result && json = (JSON.parse(result) rescue nil)
|
13
|
+
if json['status'] == 'success'
|
14
|
+
result = Result.new
|
15
|
+
result.ip = json['query']
|
16
|
+
result.country = json['country']
|
17
|
+
result.country_code = json['countryCode']
|
18
|
+
result.city = json['city']
|
19
|
+
result.time_zone = json['timezone']
|
20
|
+
result.latitude = json['lat']
|
21
|
+
result.longitude = json['lon']
|
22
|
+
result.isp = json['isp']
|
23
|
+
result.organization = json['org']
|
24
|
+
result
|
25
|
+
else
|
26
|
+
false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
rescue Timeout::Error
|
31
|
+
false
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Geolocate
|
2
|
+
class Result
|
3
|
+
|
4
|
+
attr_accessor :ip
|
5
|
+
attr_accessor :country
|
6
|
+
attr_accessor :country_code
|
7
|
+
attr_accessor :city
|
8
|
+
attr_accessor :time_zone
|
9
|
+
attr_accessor :latitude
|
10
|
+
attr_accessor :longitude
|
11
|
+
attr_accessor :isp
|
12
|
+
attr_accessor :organization
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geolocate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Cooke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
description: A library to return information about a given IP (currently using ip-api.com)
|
28
|
+
email:
|
29
|
+
- adam@atechmedia.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/geolocate.rb
|
35
|
+
- lib/geolocate/result.rb
|
36
|
+
homepage: http://github.com/adamcooke/geolocate
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.2.2
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: A library to return information about a given IP (currently using ip-api.com)
|
60
|
+
test_files: []
|
61
|
+
has_rdoc:
|