world-flags 0.4.7 → 0.4.8.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,10 @@
1
1
  source :rubygems
2
2
 
3
- gem 'hashie', '~> 1.2'
4
- gem 'i18n', '~> 0.6'
3
+ gem "mechanize"
4
+ gem "resourceful", "~> 1.0.1"
5
+ gem "rubyzip", "~> 0.9.8"
6
+ gem 'hashie', '~> 1.2'
7
+ gem 'i18n', '~> 0.6'
5
8
 
6
9
  # Add dependencies to develop your gem here.
7
10
  # Include everything needed to run rake, tests, features, etc.
data/Gemfile.lock CHANGED
@@ -28,14 +28,19 @@ GEM
28
28
  activesupport (3.2.2)
29
29
  i18n (~> 0.6)
30
30
  multi_json (~> 1.0)
31
+ addressable (2.2.8)
31
32
  arel (3.0.2)
32
33
  builder (3.0.0)
33
34
  diff-lcs (1.1.3)
35
+ domain_name (0.5.3)
36
+ unf (~> 0.0.3)
34
37
  erubis (2.7.0)
38
+ fattr (2.2.1)
35
39
  geoip (1.1.2)
36
40
  git (1.2.5)
37
41
  hashie (1.2.0)
38
42
  hike (1.2.1)
43
+ httpauth (0.1)
39
44
  i18n (0.6.0)
40
45
  jeweler (1.8.3)
41
46
  bundler (~> 1.0)
@@ -48,8 +53,22 @@ GEM
48
53
  i18n (>= 0.4.0)
49
54
  mime-types (~> 1.16)
50
55
  treetop (~> 1.4.8)
56
+ mechanize (2.5.1)
57
+ domain_name (~> 0.5, >= 0.5.1)
58
+ mime-types (~> 1.17, >= 1.17.2)
59
+ net-http-digest_auth (~> 1.1, >= 1.1.1)
60
+ net-http-persistent (~> 2.5, >= 2.5.2)
61
+ nokogiri (~> 1.4)
62
+ ntlm-http (~> 0.1, >= 0.1.1)
63
+ webrobots (~> 0.0, >= 0.0.9)
51
64
  mime-types (1.17.2)
52
65
  multi_json (1.1.0)
66
+ net-http-digest_auth (1.2.1)
67
+ net-http-persistent (2.6)
68
+ nokogiri (1.5.2)
69
+ ntlm-http (0.1.1)
70
+ options (2.3.0)
71
+ fattr
53
72
  polyglot (0.3.3)
54
73
  rack (1.4.1)
55
74
  rack-cache (1.2)
@@ -76,6 +95,10 @@ GEM
76
95
  rake (0.9.2.2)
77
96
  rdoc (3.12)
78
97
  json (~> 1.4)
98
+ resourceful (1.0.1)
99
+ addressable (>= 2.1.0)
100
+ httpauth
101
+ options (>= 2.1.1)
79
102
  rspec (2.9.0)
80
103
  rspec-core (~> 2.9.0)
81
104
  rspec-expectations (~> 2.9.0)
@@ -84,6 +107,7 @@ GEM
84
107
  rspec-expectations (2.9.0)
85
108
  diff-lcs (~> 1.1.3)
86
109
  rspec-mocks (2.9.0)
110
+ rubyzip (0.9.8)
87
111
  simplecov (0.6.1)
88
112
  multi_json (~> 1.0)
89
113
  simplecov-html (~> 0.5.3)
@@ -98,6 +122,10 @@ GEM
98
122
  polyglot
99
123
  polyglot (>= 0.3.1)
100
124
  tzinfo (0.3.32)
125
+ unf (0.0.5)
126
+ unf_ext
127
+ unf_ext (0.0.4)
128
+ webrobots (0.0.13)
101
129
 
102
130
  PLATFORMS
103
131
  ruby
@@ -108,7 +136,10 @@ DEPENDENCIES
108
136
  hashie (~> 1.2)
109
137
  i18n (~> 0.6)
110
138
  jeweler (>= 1.8.3)
139
+ mechanize
111
140
  rails (>= 3.1)
112
141
  rdoc (>= 3.12)
142
+ resourceful (~> 1.0.1)
113
143
  rspec (>= 2.8.0)
144
+ rubyzip (~> 0.9.8)
114
145
  simplecov (>= 0.5)
data/README.md CHANGED
@@ -142,6 +142,14 @@ Extract and put latest `GeoIP.dat` file in `db/GeoIP.dat` of your Rails app. Alt
142
142
 
143
143
  The _world-flags_ engine comes pre-packaged with a recent version of `GeoIP.dat` in the `db` folder of the engine itself.
144
144
 
145
+ ### GeoIP generator
146
+
147
+ Copy WorldFlags GeoIP.dat to Rails app '/db/GeoIP.dat'
148
+
149
+ TODO: Should optimally fetch the one from maxmind.com
150
+
151
+ `rails g world_flags:geoip`
152
+
145
153
  ### Localhosts filtering
146
154
 
147
155
  Also set `WorldFlags.localhost_list` if you have localhosts other than the default `127.0.0.1`.
@@ -160,7 +168,7 @@ Code extract of the locale source logic for browser IP country code detection:
160
168
 
161
169
  ```ruby
162
170
  when :ip
163
- ip_country_code(browser_ip)
171
+ country_code_from_ip browser_ip
164
172
  ```
165
173
 
166
174
  ## TODO for version 1.0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.7
1
+ 0.4.8.2
@@ -0,0 +1,87 @@
1
+ # require 'generators/world_flags/redirect_follower'
2
+ require 'resourceful'
3
+ require 'mechanize'
4
+ require 'zip/zip'
5
+ require 'fileutils'
6
+
7
+ module WorldFlags
8
+ module Generators
9
+ class GeoipGenerator < ::Rails::Generators::Base
10
+ desc "Copy IP database - GeoIP.dat"
11
+
12
+ class_option :local, :type => :boolean, :default => true, :desc => 'Use local cached GeoIP or retrieve latest from maxmind.com'
13
+
14
+ source_root File.dirname(__FILE__)
15
+
16
+ def main_flow
17
+ puts "local: #{local?}"
18
+ local? ? copy_local : download_latest
19
+ end
20
+
21
+ protected
22
+
23
+ def local?
24
+ !(options[:local] == false)
25
+ end
26
+
27
+ def copy_local
28
+ copy_file "GeoIP.dat", "db/GeoIP.dat"
29
+ end
30
+
31
+ def download_latest
32
+ # http = ::Resourceful::HttpAccessor.new
33
+ # resource = http.resource( zip_adr )
34
+ # # resource.on_redirect { |req, resp| resp.header['Location'] =~ /example.com/ }
35
+ # resp = resource.get # Will only follow the redirect if the new location is example.com
36
+
37
+ puts "get: #{file_name} from #{zip_adr}"
38
+
39
+ agent = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari'}
40
+ agent.robots = false
41
+
42
+ # puts "robots allowed? #{agent.robots_allowed?}"
43
+
44
+ agent.pluggable_parser.default = Mechanize::Download
45
+ agent.get(zip_adr).save(file_name)
46
+
47
+ # File.open(file_name, 'w+') do |zip_file|
48
+ # zip_file.write(resp.body)
49
+ # end
50
+ #zf is an instance of class Tempfile
51
+ puts "zip path: #{zf.path}"
52
+
53
+ Zip::ZipFile.open(file_name) do |zipfile|
54
+ puts "zipfile: #{zipfile}"
55
+ #zipfile.class is Zip::ZipFile
56
+ zipfile.each do |e|
57
+ #e is an instance of Zip::ZipEntry
58
+ fpath = File.join file_name, e.to_s
59
+ FileUtils.mkdir_p File.dirname(target_location)
60
+ #the block is for handling an existing file. returning true will overwrite the files.
61
+ zipfile.extract(e, target_location) { true }
62
+ end
63
+ end
64
+ FileUtils.rm(file_name) # if options[:cleanup]
65
+ end
66
+
67
+ def agent_options
68
+ {"User-Agent" => "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100402 Ubuntu/9.10 (karmic) Firefox/3.5.9", "From" => "foo@bar.com", "Referer" => "http://www.foo.bar/"}
69
+ end
70
+
71
+ def target_location
72
+ ::Rails.root.join 'db', 'GeoIP.dat'
73
+ end
74
+
75
+ def zip_adr
76
+ "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/#{file_name}"
77
+ end
78
+
79
+ def file_name
80
+ 'GeoIP.dat.gz'
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+
87
+
@@ -3,11 +3,11 @@ module WorldFlags
3
3
 
4
4
  module Helper
5
5
  module Geo
6
- def self.ip_country_code ip = nil
6
+ def self.country_code_from_ip ip = nil
7
7
  ip ||= request.remote_ip
8
8
  raise WorldFlags::GeoIPError, "IP address #{ip} is a localhost address" if local_ip?(ip)
9
9
 
10
- @geoip ||= GeoIP.new WorldFlags.geo_ip_db_path
10
+ @geoip ||= ::GeoIP.new WorldFlags.geo_ip_db_path
11
11
  country = @geoip.country(ip)
12
12
  return country[2] unless country.nil?
13
13
  raise WorldFlags::GeoIPError, "No country code could be found for IP: #{ip}"
@@ -17,8 +17,8 @@ module WorldFlags
17
17
  WorldFlags.localhost_list.include?(ip)
18
18
  end
19
19
 
20
- def ip_country_code ip = nil
21
- WorldFlags::Helper::Geo.ip_country_code ip
20
+ def country_code_from_ip ip = nil
21
+ WorldFlags::Helper::Geo.country_code_from_ip ip
22
22
  end
23
23
  end
24
24
  end
@@ -35,7 +35,7 @@ module WorldFlags
35
35
  when :browser
36
36
  browser_locale # http://www.metamodpro.com/browser-language-codes
37
37
  when :ip
38
- ip_country_code(browser_ip)
38
+ country_code_from_ip(browser_ip)
39
39
  when :default
40
40
  I18n.default_locale
41
41
  end
@@ -6,7 +6,7 @@ module WorldFlags
6
6
  attr_writer :locale_source_priority, :geo_ip_db_path, :localhost_list
7
7
 
8
8
  def geo_ip_db_path
9
- @geo_ip_db_path ||= "#{Rails.root}/db/GeoIP.dat"
9
+ @geo_ip_db_path ||= ::Rails.root.join 'db', 'GeoIP.dat'
10
10
  end
11
11
 
12
12
  def localhost_list
data/world-flags.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "world-flags"
8
- s.version = "0.4.7"
8
+ s.version = "0.4.8.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = "2012-05-16"
12
+ s.date = "2012-05-21"
13
13
  s.description = "Use world flag icons in your Rails app"
14
14
  s.email = "kmandrup@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -30,6 +30,8 @@ Gem::Specification.new do |s|
30
30
  "config/languages/locale_languages.en.json",
31
31
  "config/locale_map/locale_to_country_code.json",
32
32
  "db/GeoIP.dat",
33
+ "lib/generators/world_flags/GeoIP.dat",
34
+ "lib/generators/world_flags/geoip_generator.rb",
33
35
  "lib/generators/world_flags/init_generator.rb",
34
36
  "lib/generators/world_flags/templates/world_flags.erb",
35
37
  "lib/world-flags.rb",
@@ -95,6 +97,9 @@ Gem::Specification.new do |s|
95
97
  s.specification_version = 3
96
98
 
97
99
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
100
+ s.add_runtime_dependency(%q<mechanize>, [">= 0"])
101
+ s.add_runtime_dependency(%q<resourceful>, ["~> 1.0.1"])
102
+ s.add_runtime_dependency(%q<rubyzip>, ["~> 0.9.8"])
98
103
  s.add_runtime_dependency(%q<hashie>, ["~> 1.2"])
99
104
  s.add_runtime_dependency(%q<i18n>, ["~> 0.6"])
100
105
  s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
@@ -103,6 +108,9 @@ Gem::Specification.new do |s|
103
108
  s.add_development_dependency(%q<jeweler>, [">= 1.8.3"])
104
109
  s.add_development_dependency(%q<simplecov>, [">= 0.5"])
105
110
  else
111
+ s.add_dependency(%q<mechanize>, [">= 0"])
112
+ s.add_dependency(%q<resourceful>, ["~> 1.0.1"])
113
+ s.add_dependency(%q<rubyzip>, ["~> 0.9.8"])
106
114
  s.add_dependency(%q<hashie>, ["~> 1.2"])
107
115
  s.add_dependency(%q<i18n>, ["~> 0.6"])
108
116
  s.add_dependency(%q<rspec>, [">= 2.8.0"])
@@ -112,6 +120,9 @@ Gem::Specification.new do |s|
112
120
  s.add_dependency(%q<simplecov>, [">= 0.5"])
113
121
  end
114
122
  else
123
+ s.add_dependency(%q<mechanize>, [">= 0"])
124
+ s.add_dependency(%q<resourceful>, ["~> 1.0.1"])
125
+ s.add_dependency(%q<rubyzip>, ["~> 0.9.8"])
115
126
  s.add_dependency(%q<hashie>, ["~> 1.2"])
116
127
  s.add_dependency(%q<i18n>, ["~> 0.6"])
117
128
  s.add_dependency(%q<rspec>, [">= 2.8.0"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: world-flags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.4.8.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,56 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-16 00:00:00.000000000 Z
12
+ date: 2012-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mechanize
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: resourceful
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.0.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: rubyzip
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.8
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.8
14
62
  - !ruby/object:Gem::Dependency
15
63
  name: hashie
16
64
  requirement: !ruby/object:Gem::Requirement
@@ -144,6 +192,8 @@ files:
144
192
  - config/languages/locale_languages.en.json
145
193
  - config/locale_map/locale_to_country_code.json
146
194
  - db/GeoIP.dat
195
+ - lib/generators/world_flags/GeoIP.dat
196
+ - lib/generators/world_flags/geoip_generator.rb
147
197
  - lib/generators/world_flags/init_generator.rb
148
198
  - lib/generators/world_flags/templates/world_flags.erb
149
199
  - lib/world-flags.rb
@@ -213,7 +263,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
263
  version: '0'
214
264
  segments:
215
265
  - 0
216
- hash: -3422486010185457987
266
+ hash: 2155340704912814203
217
267
  required_rubygems_version: !ruby/object:Gem::Requirement
218
268
  none: false
219
269
  requirements: