geocoder-izi-lookup 0.0.1
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +68 -0
- data/Rakefile +34 -0
- data/lib/geocoder/izi_lookup/version.rb +5 -0
- data/lib/geocoder/izi_lookup.rb +15 -0
- data/lib/geocoder/lookups/izi_geoip.rb +58 -0
- data/lib/geocoder/results/izi_geoip.rb +56 -0
- data/lib/tasks/geocoder/izi/lookup_tasks.rake +4 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5f339981332881321028f94ee76326550659fe29d92861dc4a1466bd093da5d5
|
4
|
+
data.tar.gz: f47222bdd822442a6bd983b5133b98f786160333389ef67034166a3e068c6b68
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 03ac3518e3774eb7a6ff45bcaed7d80d8bff2090f653d8702f582e7a06f42642c1cf79a9c3116273eac70daeb0f76959c7fdb2108035866aa7a600bf2848d197
|
7
|
+
data.tar.gz: e0fbde71a0d3ba2745d2bdd96aa179bdf71afc21dd70af278c5f7a8b3fb8be36f3966e9f7de753652c8d55a630cd28657fe7daebbbf3669b6a8a1cba197b444c
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 IzikAJ
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Geocoder::Izi::Lookup
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'geocoder'
|
12
|
+
gem 'geocoder-izi-lookup', require: 'geocoder/izi_lookup'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
```bash
|
17
|
+
$ bundle
|
18
|
+
```
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
```bash
|
22
|
+
$ gem install geocoder-izi-lookup
|
23
|
+
```
|
24
|
+
|
25
|
+
Now you can use this configuration to use own lookup service:
|
26
|
+
```ruby
|
27
|
+
Geocoder.configure(
|
28
|
+
cache: Rails.cache,
|
29
|
+
cache_prefix: 'geocoder:',
|
30
|
+
ip_lookup: :izi_geoip,
|
31
|
+
izi_geoip: {
|
32
|
+
host: 'https://[YOUR_LOOKUP_SERVICE]'
|
33
|
+
}
|
34
|
+
)
|
35
|
+
```
|
36
|
+
|
37
|
+
your service should respond by url:
|
38
|
+
```
|
39
|
+
https://[YOUR_LOOKUP_SERVICE]/geocode.json?ip=[IP_FOR_LOOKUP]
|
40
|
+
```
|
41
|
+
and return value:
|
42
|
+
```json
|
43
|
+
{
|
44
|
+
"ip": "123.45.67.89",
|
45
|
+
"continent_code": "EU",
|
46
|
+
"continent_name": "Europe",
|
47
|
+
"country_code": "UA",
|
48
|
+
"country_name": "Ukraine",
|
49
|
+
"location_latitude": "",
|
50
|
+
"location_longitude": "",
|
51
|
+
"location_time_zone": "",
|
52
|
+
"postal_code": "",
|
53
|
+
"version": "0.1.1",
|
54
|
+
"in_eu": "false"
|
55
|
+
}
|
56
|
+
```
|
57
|
+
|
58
|
+
server writen on Crystal here:
|
59
|
+
https://hub.docker.com/r/izikaj/geoip/
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
Contribution directions go here.
|
63
|
+
TODO
|
64
|
+
### Tests
|
65
|
+
TODO
|
66
|
+
|
67
|
+
## License
|
68
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Geocoder::Izi::Lookup'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'geocoder'
|
2
|
+
require_relative './lookups/izi_geoip'
|
3
|
+
require_relative './results/izi_geoip'
|
4
|
+
|
5
|
+
module Geocoder
|
6
|
+
module IziLookup
|
7
|
+
class << self
|
8
|
+
def load
|
9
|
+
Geocoder::Lookup.ip_services.push(:izi_geoip)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Geocoder::IziLookup.load
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Geocoder
|
2
|
+
module Lookup
|
3
|
+
class IziGeoip < Geocoder::Lookup::Base
|
4
|
+
def name
|
5
|
+
'IziGeoip'
|
6
|
+
end
|
7
|
+
|
8
|
+
def base_query_url(query)
|
9
|
+
"#{host}/geocode.json?"
|
10
|
+
end
|
11
|
+
|
12
|
+
def query_url(query)
|
13
|
+
"#{host}/geocode.json?ip=#{query.sanitized_text}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def supported_protocols
|
17
|
+
host =~ /https/ ? [:https] : [:http]
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def results(query)
|
23
|
+
return [reserved_result(query.text)] if query.loopback_ip_address?
|
24
|
+
if (doc = fetch_data(query)).nil? or doc['country_code'].blank? or empty_result?(doc)
|
25
|
+
[]
|
26
|
+
else
|
27
|
+
[doc]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def host
|
32
|
+
configuration[:host] || 'localhost:3000'
|
33
|
+
end
|
34
|
+
|
35
|
+
def empty_result?(doc)
|
36
|
+
!doc.is_a?(Hash) or doc.keys == ['ip']
|
37
|
+
end
|
38
|
+
|
39
|
+
def reserved_result(ip)
|
40
|
+
{
|
41
|
+
'ip' => ip,
|
42
|
+
'continent_code' => '',
|
43
|
+
'continent_name' => '',
|
44
|
+
'country_code' => 'RD',
|
45
|
+
'country_name' => '',
|
46
|
+
'location_latitude' => '',
|
47
|
+
'location_longitude' => '',
|
48
|
+
'location_time_zone' => '',
|
49
|
+
'postal_code' => ''
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def query_url_params(query)
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Geocoder
|
2
|
+
module Result
|
3
|
+
class IziGeoip < Geocoder::Result::Base
|
4
|
+
attr_reader :request_country
|
5
|
+
|
6
|
+
def address(format = :full)
|
7
|
+
fail
|
8
|
+
end
|
9
|
+
|
10
|
+
def coordinates
|
11
|
+
[@data['location_latitude'].to_f, @data['location_longitude'].to_f]
|
12
|
+
end
|
13
|
+
|
14
|
+
def latitude
|
15
|
+
@data['location_latitude'].to_f
|
16
|
+
end
|
17
|
+
|
18
|
+
def longitude
|
19
|
+
@data['location_longitude'].to_f
|
20
|
+
end
|
21
|
+
|
22
|
+
def state
|
23
|
+
fail
|
24
|
+
end
|
25
|
+
|
26
|
+
def province
|
27
|
+
fail
|
28
|
+
end
|
29
|
+
|
30
|
+
def state_code
|
31
|
+
fail
|
32
|
+
end
|
33
|
+
|
34
|
+
def province_code
|
35
|
+
fail
|
36
|
+
end
|
37
|
+
|
38
|
+
def country
|
39
|
+
@data['country_name']
|
40
|
+
end
|
41
|
+
|
42
|
+
def country_code
|
43
|
+
@data['country_code']
|
44
|
+
end
|
45
|
+
|
46
|
+
def in_eu?
|
47
|
+
if @data['in_eu'].present?
|
48
|
+
ActiveRecord::ConnectionAdapters::Column.value_to_boolean(@data['in_eu'])
|
49
|
+
else
|
50
|
+
@request_country ||= Country[country_code]
|
51
|
+
@request_country.present? && @request_country.in_eu?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geocoder-izi-lookup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- IzikAJ
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: geocoder
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.0
|
27
|
+
description: Description of Geocoder::Izi::Lookup.
|
28
|
+
email:
|
29
|
+
- izikaj@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/geocoder/izi_lookup.rb
|
38
|
+
- lib/geocoder/izi_lookup/version.rb
|
39
|
+
- lib/geocoder/lookups/izi_geoip.rb
|
40
|
+
- lib/geocoder/results/izi_geoip.rb
|
41
|
+
- lib/tasks/geocoder/izi/lookup_tasks.rake
|
42
|
+
homepage: ''
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.7.3
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Summary of Geocoder::Izi::Lookup.
|
66
|
+
test_files: []
|