ipgeo 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 68c1cb1bc29d9f9a5b7eaccc7e217f510bfdc6ed
4
+ data.tar.gz: ec862a01b85fe8ed78cc7bb0feb53553aa465e4e
5
+ SHA512:
6
+ metadata.gz: bbd08169a069583a9947e29bb8be568784354ec4e5cc689629c99aed8ade5eb9e54993d8ff3880943a1f8e88aaa188acb1bf7e148edd158987db4c5d9590cd96
7
+ data.tar.gz: c5bd2b7ac2d0f2f005a9fd5a792bf9a96c996e3d30b82d8032b6b7ab14593a6e64a1eed2fa5777216bf6001941418e4f2d82ebcfba6db290d03d7c7c020fa261
@@ -0,0 +1 @@
1
+ require 'ip_geo/client'
@@ -0,0 +1,26 @@
1
+ require 'net/https'
2
+ require 'json'
3
+ require 'ip_geo/result'
4
+
5
+ module IPGeo
6
+ class Client
7
+
8
+ def initialize(hostname, options = {})
9
+ @hostname = hostname
10
+ @options = options
11
+ end
12
+
13
+ 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
21
+ end
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+ module IPGeo
2
+ class Result
3
+
4
+ def initialize(hash)
5
+ @hash = hash
6
+ end
7
+
8
+ def country
9
+ @hash['country']
10
+ end
11
+
12
+ def country_name
13
+ @hash['country_name']
14
+ end
15
+
16
+ def city
17
+ @hash['city']
18
+ end
19
+
20
+ def latitude
21
+ @hash['latitude']
22
+ end
23
+
24
+ def longitude
25
+ @hash['longitude']
26
+ end
27
+
28
+ def geoname_id
29
+ @hash['geoname_id']
30
+ end
31
+
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ipgeo
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: 2017-03-28 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A client for communicating with an IPGeo server
28
+ email:
29
+ - me@adamcooke.io
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/ip_geo.rb
35
+ - lib/ip_geo/client.rb
36
+ - lib/ip_geo/result.rb
37
+ homepage: https://github.com/adamcooke/ipgeo-ruby
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.5.1
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: A client for communicating with an IPGeo server
61
+ test_files: []