geo_locale 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +10 -0
- data/geo_locale.gemspec +33 -0
- data/lib/data/GeoIP.dat +0 -0
- data/lib/geo_locale/geo_locale.rb +25 -0
- data/lib/geo_locale/version.rb +3 -0
- data/lib/geo_locale.rb +26 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/tests/geo_ip_part_spec.rb +20 -0
- data/spec/tests/initialize_spec.rb +27 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d3630bc2042f478722327069b9b89537d3edfa75
|
4
|
+
data.tar.gz: 93a05c5cb14ddb962bd0bbfef6c8a598379cfef8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29c014106ca2986094bf8aa6e63ee67676f274d9aee86369cd07a2c9176fa7abb20f61aa759a3e4e6d944a99718e722ced46f2b06aa7d4a359444fecae1edd63
|
7
|
+
data.tar.gz: 2212080c277d6455443c673b982b5f8f89bf9a8ff1f23d0af7cb78a6897f0bb8c8388085b615857863e1b763f8be5ba1bfae0875e9a5c3b70d0b1e3eb2ff341c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Epigene
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# GeoLocale
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'geo_locale'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install geo_locale
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
Configure default locales
|
23
|
+
```ruby
|
24
|
+
GeoLocale.configure do |config|
|
25
|
+
config.dev_country = "fr"
|
26
|
+
config.local_country = "de"
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it ( https://github.com/Epigene/geo_locale/fork )
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/geo_locale.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'geo_locale/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "geo_locale"
|
8
|
+
spec.version = GeoLocale::VERSION
|
9
|
+
spec.date = Date.today.to_s
|
10
|
+
spec.platform = Gem::Platform::RUBY
|
11
|
+
spec.authors = ["Epigene"]
|
12
|
+
spec.email = ["augusts.bautra@gmail.com"]
|
13
|
+
spec.summary = ['A Rails 4+ gem for getting user country']
|
14
|
+
spec.description = ['Uses GeoIP gem and a free country database']
|
15
|
+
spec.homepage = ""
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
#s.rubyforge_project = "ga_collector_pusher"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
spec.add_development_dependency 'rails'
|
28
|
+
|
29
|
+
#spec.add_dependency "rest-client"
|
30
|
+
#spec.add_dependency "activesupport"
|
31
|
+
spec.add_dependency 'geoip'
|
32
|
+
spec.add_dependency 'i18n'
|
33
|
+
end
|
data/lib/data/GeoIP.dat
ADDED
Binary file
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module GeoLocale
|
2
|
+
|
3
|
+
def self.country_code
|
4
|
+
country_code = GeoLocale.geo_ip_try
|
5
|
+
if country_code.present?
|
6
|
+
return
|
7
|
+
else
|
8
|
+
country_code = GeoLocale.config.local_country
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.geo_ip_try
|
13
|
+
begin
|
14
|
+
return GeoIP.new("#{GeoLocale::ROOT}/lib/data/GeoIP.dat").country(request.remote_ip).country_code2.downcase
|
15
|
+
rescue
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def _try
|
21
|
+
# request.location is handled by Geocoder, fails often
|
22
|
+
# request.location.country_code.downcase
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/geo_locale.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "geo_locale/version"
|
2
|
+
require "geo_locale/geo_locale"
|
3
|
+
|
4
|
+
module GeoLocale
|
5
|
+
class << self
|
6
|
+
attr_accessor :config
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.configure
|
10
|
+
self.config ||= Config.new
|
11
|
+
yield(config)
|
12
|
+
end
|
13
|
+
|
14
|
+
class Config
|
15
|
+
attr_accessor :local_country, :dev_country
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@local_country = "en"
|
19
|
+
@dev_country = "en"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
GeoLocale.configure {}
|
24
|
+
ROOT = File.expand_path("../..", __FILE__)
|
25
|
+
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# rspec spec/tests/geo_ip_part_spec.rb
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "GeoIP part" do
|
6
|
+
before :all do
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
it "status should be sent" do
|
11
|
+
# request = stub(host: 'dietbikini.com')
|
12
|
+
# GeoLocale.any_instance.stub request: request
|
13
|
+
helper.request.stub(:path).and_return("/asdf.asdf")
|
14
|
+
request = ActionController::TestRequest.new(host: "www.google.lv", remote_ip: "146.185.168.135")
|
15
|
+
expect(GeoLocale.geo_ip_try).to eq "xx"
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# rspec spec/tests/initialize_spec.rb
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "Initializing" do
|
6
|
+
before :all do
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should set dev_country to en" do
|
11
|
+
expect(GeoLocale.config.dev_country).to eq "en"
|
12
|
+
end
|
13
|
+
it "should set local_country to en" do
|
14
|
+
expect(GeoLocale.config.local_country).to eq "en"
|
15
|
+
end
|
16
|
+
it "should change local_country to de" do
|
17
|
+
GeoLocale.config.local_country = "de"
|
18
|
+
expect(GeoLocale.config.local_country).to eq "de"
|
19
|
+
end
|
20
|
+
it "should change dev_country to fr" do
|
21
|
+
GeoLocale.configure do |c|
|
22
|
+
c.dev_country = "fr"
|
23
|
+
end
|
24
|
+
expect(GeoLocale.config.dev_country).to eq "fr"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geo_locale
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Epigene
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: geoip
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: i18n
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: '["Uses GeoIP gem and a free country database"]'
|
98
|
+
email:
|
99
|
+
- augusts.bautra@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- geo_locale.gemspec
|
111
|
+
- lib/data/GeoIP.dat
|
112
|
+
- lib/geo_locale.rb
|
113
|
+
- lib/geo_locale/geo_locale.rb
|
114
|
+
- lib/geo_locale/version.rb
|
115
|
+
- spec/spec_helper.rb
|
116
|
+
- spec/tests/geo_ip_part_spec.rb
|
117
|
+
- spec/tests/initialize_spec.rb
|
118
|
+
homepage: ''
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.2.2
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: '["A Rails 4+ gem for getting user country"]'
|
142
|
+
test_files:
|
143
|
+
- spec/spec_helper.rb
|
144
|
+
- spec/tests/geo_ip_part_spec.rb
|
145
|
+
- spec/tests/initialize_spec.rb
|