geolocal 0.9.3 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile +0 -6
- data/README.md +16 -5
- data/contrib/continents.rb +5 -10
- data/lib/geolocal/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ee0a56261b1f3f51f2415d9caa95a4aa5b85b00
|
4
|
+
data.tar.gz: c40f16d2a55e3b31c161383f61cbd02ab656cbc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ea108d018f1218f49a0c40213a5a87dd8c96f935e99c95fc86e4946a1b5a92a2f8d799bf07fbfc581203f9688e61c4cbc359074cb1c55275bd665f21951f7e9
|
7
|
+
data.tar.gz: 5686fbdee7424dd1892889e2609db759f77a0d65862a5b73afd7ea70de4d22aa0614bf88cab362b1ddbf01e37e6e15dd88ae9a73bc8090db084a120c066bca90
|
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -28,10 +28,12 @@ require 'geolocal/tasks'
|
|
28
28
|
|
29
29
|
## Usage
|
30
30
|
|
31
|
-
|
31
|
+
Geolocal creates routines that return true or false depending on whether a particular IP address is within an area.
|
32
|
+
A config file describes the areas you're interested in.
|
33
|
+
|
34
|
+
If you're using Rails, run `rails generate geolocal` to create the config file.
|
32
35
|
Otherwise, crib from [config/geolocal.rb](https://github.com/bronson/geolocal/tree/master/config/geolocal.rb).
|
33
36
|
|
34
|
-
The configuration file describes the ranges you're interested in.
|
35
37
|
Here's an example that creates three queries: `in_us?`, `in_spain?`,
|
36
38
|
and `in_central_america?`:
|
37
39
|
|
@@ -109,7 +111,16 @@ Run them like this:
|
|
109
111
|
```sh
|
110
112
|
git clone https://github.com/bronson/geolocal
|
111
113
|
cd geolocal
|
112
|
-
rake geolocal config=contrib/continents
|
114
|
+
rake geolocal config=contrib/continents
|
115
|
+
```
|
116
|
+
|
117
|
+
Now look at the `tmp/geolocal.rb` file. Beware, it's big!
|
118
|
+
|
119
|
+
Here's an example of using it from a command. The `-Itmp` argument ensures `require` will
|
120
|
+
load `tmp/geolocal.rb`, then we just look up the IP address `8.8.8.8`.
|
121
|
+
|
122
|
+
```bash
|
123
|
+
ruby -Itmp -e 'require "geolocal"; puts Geolocal.in_north_america?("8.8.8.8") ? "yes!" : "nope"'
|
113
124
|
```
|
114
125
|
|
115
126
|
|
@@ -121,7 +132,7 @@ to create a `Geolocal.in_eu?(ip_addr)` method:
|
|
121
132
|
```ruby
|
122
133
|
require 'countries'
|
123
134
|
|
124
|
-
eu_codes = Country.find_all_by_eu_member(true).map(&:first)
|
135
|
+
eu_codes = ISO3166::Country.find_all_by_eu_member(true).map(&:first)
|
125
136
|
|
126
137
|
Geolocal.configure do |config|
|
127
138
|
config.countries = { us: 'US', eu: eu_codes }
|
@@ -143,7 +154,7 @@ expect to do better than a million lookups every two seconds.
|
|
143
154
|
To see for yourself, run the continents benchmark:
|
144
155
|
|
145
156
|
```sh
|
146
|
-
rake geolocal config=contrib/continents
|
157
|
+
rake geolocal config=contrib/continents
|
147
158
|
ruby contrib/benchmark-continents.rb
|
148
159
|
```
|
149
160
|
|
data/contrib/continents.rb
CHANGED
@@ -5,22 +5,17 @@
|
|
5
5
|
# Now you can call Geolocal.in_africa?, in_antarcitca?, in_asia?, etc.
|
6
6
|
|
7
7
|
|
8
|
-
require 'geolocal'
|
8
|
+
require 'geolocal/configuration'
|
9
9
|
require 'countries'
|
10
10
|
|
11
11
|
|
12
12
|
# creates in_x? methods for each continent: in_north_america?, in_europe?, etc.
|
13
13
|
|
14
14
|
Geolocal.configure do |config|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
continent = country.continent.downcase;
|
20
|
-
hash[continent] ||= [];
|
21
|
-
hash[continent] << country.alpha2;
|
22
|
-
hash
|
23
|
-
}
|
15
|
+
continents = ISO3166::Country.all.group_by(&:continent)
|
16
|
+
by_continent = continents.merge(continents) do |continent, countries|
|
17
|
+
countries.map(&:alpha2)
|
18
|
+
end
|
24
19
|
|
25
20
|
config.countries = by_continent
|
26
21
|
config.ipv6 = false
|
data/lib/geolocal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geolocal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0
|
4
|
+
version: '1.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Bronson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,6 +76,7 @@ extra_rdoc_files: []
|
|
76
76
|
files:
|
77
77
|
- ".gitignore"
|
78
78
|
- ".rspec"
|
79
|
+
- CHANGELOG.md
|
79
80
|
- Gemfile
|
80
81
|
- Guardfile
|
81
82
|
- LICENSE.txt
|
@@ -120,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
121
|
version: '0'
|
121
122
|
requirements: []
|
122
123
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.4.
|
124
|
+
rubygems_version: 2.4.5
|
124
125
|
signing_key:
|
125
126
|
specification_version: 4
|
126
127
|
summary: Generates plain Ruby if statements to geocode IP addresses
|