ip_to_country 0.0.1 → 0.0.2

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,14 @@
1
+ "2.22.160.0","2.22.226.255","35037184","35054335","FR","France"
2
+ "2.22.227.0","2.22.227.255","35054336","35054591","GB","United Kingdom"
3
+ "2.22.228.0","2.22.229.255","35054592","35055103","EU","Europe"
4
+ "2.22.230.0","2.22.230.255","35055104","35055359","ES","Spain"
5
+ "2.22.231.0","2.22.232.255","35055360","35055871","EU","Europe"
6
+ "2.22.233.0","2.22.233.255","35055872","35056127","NL","Netherlands"
7
+ "2.22.234.0","2.22.245.255","35056128","35059199","EU","Europe"
8
+ "2.22.246.0","2.22.247.255","35059200","35059711","GB","United Kingdom"
9
+ "2.22.248.0","2.22.251.255","35059712","35060735","EU","Europe"
10
+ "2.22.252.0","2.22.253.255","35060736","35061247","GB","United Kingdom"
11
+ "2.22.254.0","2.22.255.255","35061248","35061759","FR","France"
12
+ "2.23.0.0","2.23.111.255","35061760","35090431","EU","Europe"
13
+ "2.23.112.0","2.23.127.255","35090432","35094527","GR","Greece"
14
+ "2.23.128.0","2.23.255.255","35094528","35127295","EU","Europe"
@@ -0,0 +1,95 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ class LoaderTest < ActiveSupport::TestCase
5
+
6
+ test "ip populate workflow" do
7
+ IpToCountry::Loader.expects(download_and_unzip_ips: true, create_tempo_table: true,
8
+ load_csv_in_tempo_table: true, rename_tempo_into_geoip: true,
9
+ clean_tmp_files: true)
10
+ assert(IpToCountry::Loader.populate!)
11
+ end
12
+
13
+ test "it download and unzip csv with ip address" do
14
+ setup_download_and_extract
15
+
16
+ IpToCountry::Loader.expects(:system).with("wget -N #{IpToCountry::Loader::ARCHIVE_SOURCE}")
17
+ IpToCountry::Loader.expects(:system).with("unzip -j /tmp/test_ips.zip -d /tmp")
18
+ IpToCountry::Loader.download_and_unzip_ips
19
+ assert File.exists?('/tmp/test_ips.csv')
20
+
21
+ teardown_download_and_extract
22
+ end
23
+
24
+ test "it creates a tempo table for ips" do
25
+ assert(IpToCountry::Loader.create_tempo_table)
26
+ assert ActiveRecord::Base.connection.table_exists?('geoips_tempo')
27
+ end
28
+
29
+ test "it loads csv ips into tempo table" do
30
+ setup_load_csv
31
+ IpToCountry::Loader.create_tempo_table
32
+ IpToCountry::Loader.load_csv_in_tempo_table
33
+ IpToCountry::Loader.rename_tempo_into_geoip
34
+ assert_equal 'France', IpToCountry::Geoip.by_ip('2.22.160.0').country_name
35
+ teardown_load_csv
36
+ end
37
+
38
+ test "it renames tempo table into geoips" do
39
+ IpToCountry::Loader.create_tempo_table
40
+ IpToCountry::Loader.rename_tempo_into_geoip
41
+ refute ActiveRecord::Base.connection.table_exists?('geoips_tempo')
42
+ end
43
+
44
+ test "it remove temp files" do
45
+ setup_file_remove
46
+
47
+ IpToCountry::Loader.clean_tmp_files
48
+ refute File.exists?('/tmp/test_ips.csv')
49
+ refute File.exists?('/tmp/test_ips.zip')
50
+
51
+ teardown_file_remove
52
+ end
53
+
54
+ private
55
+
56
+ def redefine_const(name, value)
57
+ IpToCountry::Loader.send(:remove_const, name) if IpToCountry::Loader.const_defined?(name)
58
+ IpToCountry::Loader.const_set(name, value)
59
+ end
60
+
61
+ def setup_download_and_extract
62
+ redefine_const('ARCHIVE_NAME', 'test_ips.zip')
63
+ FileUtils.cp('test/fixtures/ips/test_ips.zip', '.')
64
+ FileUtils.cp('test/fixtures/ips/test_ips.csv', '/tmp')
65
+ end
66
+
67
+ def teardown_download_and_extract
68
+ redefine_const('ARCHIVE_NAME', 'GeoIPCountryCSV.zip')
69
+ FileUtils.rm('/tmp/test_ips.csv')
70
+ FileUtils.rm('/tmp/test_ips.zip')
71
+ end
72
+
73
+ def setup_load_csv
74
+ FileUtils.cp('test/fixtures/ips/test_ips.csv', '/tmp')
75
+ redefine_const('EXTRACTED_IP_FILE', '/tmp/test_ips.csv')
76
+ end
77
+
78
+ def teardown_load_csv
79
+ FileUtils.rm('/tmp/test_ips.csv')
80
+ redefine_const('EXTRACTED_IP_FILE', '/tmp/GeoIPCountryWhois.csv')
81
+ end
82
+
83
+ def setup_file_remove
84
+ FileUtils.cp('test/fixtures/ips/test_ips.zip', "/tmp")
85
+ FileUtils.cp('test/fixtures/ips/test_ips.csv', "/tmp")
86
+ redefine_const('EXTRACTED_IP_FILE', '/tmp/test_ips.csv')
87
+ redefine_const('ARCHIVE_NAME', 'test_ips.zip')
88
+ end
89
+
90
+ def teardown_file_remove
91
+ redefine_const('EXTRACTED_IP_FILE', '/tmp/GeoIPCountryWhois.csv')
92
+ redefine_const('ARCHIVE_NAME', 'GeoIPCountryCSV.zip')
93
+ end
94
+
95
+ end
@@ -5,6 +5,7 @@ ENV["RAILS_ENV"] = "test"
5
5
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
6
6
  require "rails/test_help"
7
7
  require 'coveralls'
8
+ require "mocha/setup"
8
9
 
9
10
  Coveralls.wear!
10
11
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ip_to_country
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-04-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &15605500 !ruby/object:Gem::Requirement
16
+ requirement: &13549180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,18 +21,7 @@ dependencies:
21
21
  version: 3.2.12
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *15605500
25
- - !ruby/object:Gem::Dependency
26
- name: pg
27
- requirement: &15632440 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *15632440
24
+ version_requirements: *13549180
36
25
  description: Simple tool to find the country of an ip address.
37
26
  email:
38
27
  - vincent.pochet@gmail.com
@@ -42,18 +31,22 @@ extra_rdoc_files: []
42
31
  files:
43
32
  - app/models/ip_to_country/geoip.rb
44
33
  - lib/ip_to_country/engine.rb
34
+ - lib/ip_to_country/loader.rb
45
35
  - lib/ip_to_country/version.rb
46
36
  - lib/ip_to_country.rb
47
37
  - lib/generators/geoip/geoip_generator.rb
48
38
  - lib/generators/geoip/templates/migration.rb
49
- - lib/tasks/ip_to_country_tasks.rake
39
+ - lib/tasks/ip_to_country.rake
50
40
  - MIT-LICENSE
51
41
  - Rakefile
52
42
  - README.md
53
43
  - test/ip_to_country_test.rb
44
+ - test/loader_test.rb
54
45
  - test/geoip_test.rb
55
46
  - test/test_helper.rb
56
47
  - test/fixtures/geoips.yml
48
+ - test/fixtures/ips/test_ips.csv
49
+ - test/fixtures/ips/test_ips.zip
57
50
  - test/dummy/log/test.log
58
51
  - test/dummy/script/rails
59
52
  - test/dummy/public/favicon.ico
@@ -110,9 +103,12 @@ specification_version: 3
110
103
  summary: Simple tool to find the country of an ip address
111
104
  test_files:
112
105
  - test/ip_to_country_test.rb
106
+ - test/loader_test.rb
113
107
  - test/geoip_test.rb
114
108
  - test/test_helper.rb
115
109
  - test/fixtures/geoips.yml
110
+ - test/fixtures/ips/test_ips.csv
111
+ - test/fixtures/ips/test_ips.zip
116
112
  - test/dummy/log/test.log
117
113
  - test/dummy/script/rails
118
114
  - test/dummy/public/favicon.ico
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :ip_to_country do
3
- # # Task goes here
4
- # end