ipligence 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff60ae1a98c5c1904c4538753ae37ceef588a248
4
- data.tar.gz: 832a9aa3915cf4e3e1dbfc078364cb82f25a0730
3
+ metadata.gz: 73cbbfbc628ac5f8f87cc5693319cf118e42753c
4
+ data.tar.gz: 689e803487cb2c23bd2981bc124726caa961f293
5
5
  SHA512:
6
- metadata.gz: 8f35b05c6e844762d647e5e48ba940828b7176a87868b97fcd720af94a543e2375531101bfc958fb70a0e0810d7b4917f5e2ae802acf91e7d4ec85ed79e07bd4
7
- data.tar.gz: 65c31c1b15d65271a0867a695e8eb294420667a42d5e521d6b1040ef83a7d769f9c0cb2c194edec9789ba767365514f9b8523683ffe1da0cb3173498b2461041
6
+ metadata.gz: 87c536d5c19d587590dcf240edf92772eb9044d17897b344481f788c3c5838f4374f3c13a1d171edbd8eab279c8547fdd582ce3162b80c0a135c972722b765be
7
+ data.tar.gz: 4b6b9b1e90d82f4231609afaecf4db837328421bf1af658e2953cac6ec38f09425017848eac075595d600a44b3054ee4e4b4894ef2c12433ea17af8878fa6579
data/.gitignore CHANGED
@@ -15,9 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
23
18
  test/db/*.sqlite
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in geodalia.gemspec
3
+ # Specify your gem's dependencies in ipligence.gemspec
4
4
  gemspec
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Sevastianos Komianos
1
+ Copyright (c) 2014 Dalia Research
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Ipligence
2
2
 
3
- TODO: Write a gem description
3
+ A ruby gem to integrate the [IPligence database](http://ipligence.com/)
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'geo_dalia'
9
+ gem "ipligence"
10
10
 
11
11
  And then execute:
12
12
 
@@ -14,16 +14,35 @@ And then execute:
14
14
 
15
15
  Or install it yourself as:
16
16
 
17
- $ gem install geodalia
17
+ $ gem install ipligence
18
+
19
+ ## Set up
20
+
21
+ curl -O http://www.ipligence.com/pickup/<SOME CODE HERE>/ipligence-pro.mysqldump.sql.gz
22
+ gunzip ipligence-pro.mysqldump.sql.gz
23
+ mysql -uusername -ppassword database < ipligence-pro.mysqldump.sql
18
24
 
19
25
  ## Usage
20
26
 
21
- TODO: Write usage instructions here
27
+ The gem needs an IPligence database. After you create it you can configure the `Ipligence::Client`:
28
+
29
+ client = Ipligence::Client.new("adapter", "database", "username", "password")
30
+
31
+ Then, you can get a hash with the geodata for a given IP using the client's `data` method:
32
+
33
+ data = client.data("0.0.0.0")
34
+
35
+ For example, querying for `195.130.124.1` returns the following hash:
36
+
37
+ => {:ip_from=>"3280108544", :ip_to=>"3280109567", :country_code=>"GR", :country_name=>"GREECE",
38
+ :continent_code=>"EU", :continent_name=>"EUROPE", :time_zone=>"GMT+2", :region_code=>"",
39
+ :region_name=>"", :owner=>"IONIAN UNIVERSITY", :city_name=>"CORFU", :county_name=>"",
40
+ :post_code=>"", :area_code=>"", :metro_code=>"", :latitude=>"39.62", :longitude=>"19.9197"}
22
41
 
23
42
  ## Contributing
24
43
 
25
- 1. Fork it ( https://github.com/[my-github-username]/geodalia/fork )
44
+ 1. Fork it (https://github.com/DaliaResearch/Ipligence/fork)
26
45
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
46
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
47
  4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create a new Pull Request
48
+ 5. Issue a new pull request (https://github.com/DaliaResearch/Ipligence/pulls)
data/Rakefile CHANGED
@@ -9,4 +9,3 @@ Rake::TestTask.new do |t|
9
9
  t.test_files = FileList["test/**/*_test.rb"]
10
10
  t.verbose = true
11
11
  end
12
-
data/ipligence.gemspec CHANGED
@@ -1,16 +1,16 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'ipligence/version'
4
+ require "ipligence/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "ipligence"
8
8
  spec.version = Ipligence::VERSION
9
- spec.authors = ["Sevastianos Komianos"]
9
+ spec.authors = ["Sebastian Komianos, Fernando Guillen"]
10
10
  spec.email = ["sebastian.komianos@daliaresearch.com"]
11
- spec.summary = "Ruby Gem to integrate Ipligence DB in Rails apps"
12
- spec.description = "Ruby Gem to integrate Ipligence DB in Rails apps"
13
- spec.homepage = "https://github.com/DaliaResearch/Ipligence"
11
+ spec.summary = "A ruby gem for the IPligence database"
12
+ spec.description = "A gem to integrate the IPligence database in ruby"
13
+ spec.homepage = "http://github.com/DaliaResearch/ipligence"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "rails", "~> 4.0"
21
+ spec.add_dependency "activerecord"
22
22
 
23
- spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "sqlite3"
25
26
  spec.add_development_dependency "mocha"
26
27
  spec.add_development_dependency "minitest"
27
- spec.add_development_dependency "sqlite3"
28
28
  end
data/lib/ipligence.rb CHANGED
@@ -1,11 +1,6 @@
1
- require "active_record"
2
- require "csv"
3
- require "rails"
4
1
  require_relative "ipligence/version"
5
2
  require_relative "ipligence/utils"
6
- require_relative "ipligence/record"
7
- require_relative "ipligence/railtie"
3
+ require_relative "ipligence/client"
8
4
 
9
5
  module Ipligence
10
6
  end
11
-
@@ -0,0 +1,48 @@
1
+ require "active_record"
2
+
3
+ class Ipligence::Client
4
+
5
+ attr_accessor :db
6
+
7
+ def initialize(adapter, database, username = "root", password = "")
8
+ self.db = ActiveRecord::Base.establish_connection(
9
+ :adapter => adapter,
10
+ :database => database,
11
+ :username => username,
12
+ :password => password
13
+ ).connection
14
+ end
15
+
16
+ def data(ip)
17
+ result = query(ip)
18
+
19
+ {
20
+ :ip_from => result["ip_from"],
21
+ :ip_to => result["ip_to"],
22
+ :country_code => result["country_code"],
23
+ :country_name => result["country_name"],
24
+ :continent_code => result["continent_code"],
25
+ :continent_name => result["continent_name"],
26
+ :time_zone => result["time_zone"],
27
+ :region_code => result["region_code"],
28
+ :region_name => result["region_name"],
29
+ :owner => result["owner"],
30
+ :city_name => result["city_name"],
31
+ :county_name => result["county_name"],
32
+ :post_code => result["post_code"],
33
+ :area_code => result["area_code"],
34
+ :metro_code => result["metro_code"],
35
+ :latitude => result["latitude"],
36
+ :longitude => result["longitude"]
37
+ }
38
+ end
39
+
40
+ private
41
+ def query(ip)
42
+ long_ip = Ipligence::Utils.convert_dotted_to_long(ip).to_s
43
+ data_fields = "ip_from, ip_to, country_code, country_name, continent_code, continent_name, time_zone, region_code, region_name, owner, city_name, county_name, post_code, area_code, metro_code, latitude, longitude"
44
+ sql_query = "select #{data_fields} from ipligence2 where ip_from <= '#{long_ip}' and '#{long_ip}' <= ip_to"
45
+ self.db.exec_query(sql_query).first
46
+ end
47
+
48
+ end
@@ -1,45 +1,8 @@
1
1
  module Ipligence::Utils
2
- def self.convert_dotted_to_long(ip)
2
+
3
+ def self.convert_dotted_to_long(ip)
3
4
  dotted_ip_array = ip.split(".").map(&:to_i)
4
5
  (dotted_ip_array[0] * 256 * 256 * 256) + (dotted_ip_array[1] * 256 * 256) + (dotted_ip_array[2] * 256) + (dotted_ip_array[3])
5
6
  end
6
7
 
7
- def self.repopulate_db(file_path)
8
- index = 0
9
- total_lines = File.open(file_path).readlines.size
10
-
11
- Ipligence::Record.destroy_all
12
-
13
- CSV.foreach(file_path) do |row|
14
- Ipligence::Utils.log "Populating line [#{index + 1}/#{total_lines}]: #{row}"
15
- Ipligence::Record.create!(
16
- :ipblock_from => row[0],
17
- :ipblock_to => row[1],
18
- :country_code => row[2].empty? ? nil : row[2],
19
- :country_name => row[3].empty? ? nil : row[3],
20
- :continent_code => row[4].empty? ? nil : row[4],
21
- :continent_name => row[5].empty? ? nil : row[5],
22
- :time_zone => row[6].empty? ? nil : row[6],
23
- :region_code => row[7].empty? ? nil : row[7],
24
- :region_name => row[8].empty? ? nil : row[8],
25
- :owner => row[9].empty? ? nil : row[9],
26
- :city_name => row[10].empty? ? nil : row[10],
27
- :county_name => row[11].empty? ? nil : row[11],
28
- :post_code => row[12].empty? ? nil : row[12],
29
- :area_code => row[13].empty? ? nil : row[13],
30
- :metro_code => row[14].empty? ? nil : row[14],
31
- :latitude => row[15].empty? ? nil : row[15],
32
- :longitude => row[16].empty? ? nil : row[16]
33
- )
34
-
35
- index += 1
36
- end
37
-
38
- Ipligence::Utils.log "Repopulation completed!"
39
- end
40
-
41
- def self.log(message)
42
- Kernel.puts "Ipligence [#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] #{message}"
43
- end
44
-
45
- end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Ipligence
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,46 @@
1
+ require_relative "test_helper"
2
+
3
+ class ClientTest < MiniTest::Test
4
+ def setup
5
+ end
6
+
7
+ def test_initialize
8
+ connection_params = {
9
+ :adapter => "ADAPTER",
10
+ :database => "DATABASE",
11
+ :username => "USERNAME",
12
+ :password => "PASSWORD"
13
+ }
14
+
15
+ adapter_mock = mock(:connection => "CONNECTION")
16
+
17
+ ActiveRecord::Base.expects(:establish_connection).with(connection_params).returns(adapter_mock)
18
+ client = Ipligence::Client.new("ADAPTER", "DATABASE", "USERNAME", "PASSWORD")
19
+
20
+ assert_equal("CONNECTION", client.db)
21
+ end
22
+
23
+ def test_data
24
+ client = Ipligence::Client.new("sqlite3", "#{File.dirname(__FILE__)}/db/ipligence.sqlite")
25
+
26
+ data = client.data("2.84.170.255")
27
+ assert_equal(39102976, data[:ip_from])
28
+ assert_equal(39103231, data[:ip_to])
29
+ assert_equal("GR", data[:country_code])
30
+ assert_equal("GREECE", data[:country_name])
31
+ assert_equal("EU", data[:continent_code])
32
+ assert_equal("EUROPE", data[:continent_name])
33
+ assert_equal("GMT+2", data[:time_zone])
34
+ assert_equal("", data[:region_code])
35
+ assert_equal("", data[:region_name])
36
+ assert_equal("MULTIPROTOCOL SERVICE PROVIDER TO OTHER ISP S AND END USERS", data[:owner])
37
+ assert_equal("VOULA", data[:city_name])
38
+ assert_equal("", data[:county_name])
39
+ assert_equal("", data[:post_code])
40
+ assert_equal("", data[:area_code])
41
+ assert_equal("", data[:metro_code])
42
+ assert_equal(37.85, data[:latitude])
43
+ assert_equal(23.77, data[:longitude])
44
+ end
45
+
46
+ end
@@ -1,4 +1,22 @@
1
- "0000000000","0016777215","","","","","","","","NOT ALLOCATED","","","","","","0","0"
2
- "0016777216","0016777471","AU","AUSTRALIA","OC","OCEANIA","GMT+10","QLD","QUEENSLAND","APNIC DEBOGON PROJECT","BRISBANE","","","","","-27.5","153.02"
3
- "0016777472","0016778239","CN","CHINA","AS","ASIA","GMT+8","BJ","","CHINANET FUJIAN PROVINCE NETWORK","BEIJING","","","","","39.9","116.41"
4
- "0016778240","0016778495","AU","AUSTRALIA","OC","OCEANIA","GMT+10","VIC","VICTORIA","LEVEL 5 530 COLLINS STREET","PRAHRAN","","3181","","","-37.85","145"
1
+ "0039102976","0039103231","GR","GREECE","EU","EUROPE","GMT+2","","","MULTIPROTOCOL SERVICE PROVIDER TO OTHER ISP S AND END USERS","VOULA","","","","","37.85","23.77"
2
+ "0387178496","0387179519","US","UNITED STATES","NA","NORTH AMERICA","EST","NY","NEW YORK","UBIQUITY SERVER SOLUTIONS NEW YORK","NEW YORK","NEW YORK","10011","501","212","40.71","-74.00"
3
+ "0387179520","0387180543","US","UNITED STATES","NA","NORTH AMERICA","PST","CA","CALIFORNIA","UBIQUITY SERVER SOLUTIONS LOS ANGELES","LOS ANGELES","LOS ANGELES","90014","803","213","33.99","-118.37"
4
+ "0387180544","0387181567","US","UNITED STATES","NA","NORTH AMERICA","EST","GA","GEORGIA","UBIQUITY SERVER SOLUTIONS ATLANTA","ATLANTA","FULTON DEKALB","30303","524","404","33.93","-84.27"
5
+ "0387181568","0387182591","US","UNITED STATES","NA","NORTH AMERICA","PST","CA","CALIFORNIA","UBIQUITY SERVER SOLUTIONS LOS ANGELES","LOS ANGELES","LOS ANGELES","90014","803","213","33.99","-118.37"
6
+ "0387182592","0387183615","US","UNITED STATES","NA","NORTH AMERICA","CST","TX","TEXAS","UBIQUITY SERVER SOLUTIONS DALLAS","DALLAS","DALLAS","75207","623","214","32.83","-96.79"
7
+ "0387183616","0387184639","US","UNITED STATES","NA","NORTH AMERICA","CST","IL","ILLINOIS","UBIQUITY SERVER SOLUTIONS CHICAGO","CHICAGO","COOK","60616","602","312","41.90","-87.67"
8
+ "0387184640","0387185663","US","UNITED STATES","NA","NORTH AMERICA","PST","WA","WASHINGTON","UBIQUITY SERVER SOLUTIONS SEATTLE","SEATTLE","KING","98168","819","206","47.50","-122.35"
9
+ "0387185664","0387186687","US","UNITED STATES","NA","NORTH AMERICA","EST","GA","GEORGIA","UBIQUITY SERVER SOLUTIONS ATLANTA","ATLANTA","FULTON DEKALB","30303","524","404","33.93","-84.27"
10
+ "0387186688","0387448831","US","UNITED STATES","NA","NORTH AMERICA","EST","VA","VIRGINIA","AMAZON.COM INC.","ASHBURN","LOUDOUN","20146","511","703","39.04","-77.48"
11
+ "0387448832","0387449343","US","UNITED STATES","NA","NORTH AMERICA","EST","PA","PENNSYLVANIA","COMCAST BUSINESS COMMUNICATIONS LLC","BOYERTOWN","BERKS","19512","504","610","40.34","-75.68"
12
+ "0387449344","0387449599","US","UNITED STATES","NA","NORTH AMERICA","EST","PA","PENNSYLVANIA","COMCAST BUSINESS COMMUNICATIONS LLC","PHILADELPHIA","PHILADELPHIA DELAWARE","19106","504","215","39.95","-75.15"
13
+ "0387449600","0387449855","US","UNITED STATES","NA","NORTH AMERICA","EST","PA","PENNSYLVANIA","COMCAST BUSINESS COMMUNICATIONS LLC","HARLEYSVILLE","MONTGOMERY","19438","504","215","40.27","-75.38"
14
+ "0387449856","0387450111","US","UNITED STATES","NA","NORTH AMERICA","EST","PA","PENNSYLVANIA","COMCAST BUSINESS COMMUNICATIONS LLC","BERWYN","CHESTER","19312","504","610","40.03","-75.44"
15
+ "0387450112","0387450367","US","UNITED STATES","NA","NORTH AMERICA","EST","PA","PENNSYLVANIA","COMCAST BUSINESS COMMUNICATIONS LLC","PHILADELPHIA","PHILADELPHIA DELAWARE","19148","504","215","39.95","-75.15"
16
+ "0387450368","0387450623","US","UNITED STATES","NA","NORTH AMERICA","EST","PA","PENNSYLVANIA","COMCAST BUSINESS COMMUNICATIONS LLC","NEWTOWN SQUARE","DELAWARE","19073","504","610","39.97","-75.43"
17
+ "0387450624","0387451008","US","UNITED STATES","NA","NORTH AMERICA","EST","PA","PENNSYLVANIA","COMCAST BUSINESS COMMUNICATIONS LLC","PHILADELPHIA","PHILADELPHIA DELAWARE","19019","504","610","39.95","-75.15"
18
+ "0387451009","0387451009","US","UNITED STATES","NA","NORTH AMERICA","EST","PA","PENNSYLVANIA","COMCAST BUSINESS COMMUNICATIONS LLC","LANGHORNE","BUCKS","19047","504","215","40.18","-74.91"
19
+ "0387451010","0387451903","US","UNITED STATES","NA","NORTH AMERICA","EST","PA","PENNSYLVANIA","COMCAST BUSINESS COMMUNICATIONS LLC","PHILADELPHIA","PHILADELPHIA DELAWARE","19019","504","610","39.95","-75.15"
20
+ "0387451904","0387452095","US","UNITED STATES","NA","NORTH AMERICA","EST","NJ","NEW JERSEY","COMCAST BUSINESS COMMUNICATIONS LLC","MOUNT LAUREL","BURLINGTON","08054","504","856","39.94","-74.90"
21
+ "0387452096","0387452111","US","UNITED STATES","NA","NORTH AMERICA","EST","PA","PENNSYLVANIA","COMCAST BUSINESS COMMUNICATIONS LLC","CRUM LYNNE","DELAWARE","19022","504","610","39.864","-75.34"
22
+ "0387452112","0387452415","US","UNITED STATES","NA","NORTH AMERICA","EST","NJ","NEW JERSEY","COMCAST BUSINESS COMMUNICATIONS LLC","MOUNT LAUREL","BURLINGTON","08054","504","856","39.94","-74.90"
data/test/schema.rb ADDED
@@ -0,0 +1,21 @@
1
+ ActiveRecord::Schema.define :version => 0 do
2
+ create_table :ipligence2 do |t|
3
+ t.integer :ip_from, default: 0000000000, null: false
4
+ t.integer :ip_to, default: 0000000000, null: false
5
+ t.string :country_code, null: false
6
+ t.string :country_name, null: false
7
+ t.string :continent_code, null: false
8
+ t.string :continent_name, null: false
9
+ t.string :time_zone, null: false
10
+ t.string :region_code, null: false
11
+ t.string :region_name, null: false
12
+ t.string :owner, null: false
13
+ t.string :city_name, null: false
14
+ t.string :county_name, null: false
15
+ t.string :post_code, null: false
16
+ t.string :area_code, null: false
17
+ t.string :metro_code, null: false
18
+ t.decimal :latitude, null: false
19
+ t.decimal :longitude, null: false
20
+ end
21
+ end
data/test/test_helper.rb CHANGED
@@ -1,13 +1,23 @@
1
+ require "active_record"
2
+ require "CSV"
1
3
  require "minitest/autorun"
2
4
  require "mocha/setup"
3
5
  require_relative "../lib/ipligence"
4
6
 
5
7
  FileUtils.rm("#{File.dirname(__FILE__)}/db/ipligence.sqlite", :force => true)
6
8
 
7
- ActiveRecord::Base.establish_connection(
9
+ @db = ActiveRecord::Base.establish_connection(
8
10
  :adapter => "sqlite3",
9
11
  :database => "#{File.dirname(__FILE__)}/db/ipligence.sqlite"
10
12
  )
11
13
 
12
- require_relative "../lib/generators/ipligence/templates/create_ipligence_records_table"
13
- CreateIpligenceRecordsTable.up
14
+ load("#{File.dirname(__FILE__)}/schema.rb")
15
+
16
+ CSV.foreach("#{File.dirname(__FILE__)}/fixtures/ipligence_test.csv") do |row|
17
+ insert_query =
18
+ "INSERT INTO ipligence2 (ip_from, ip_to, country_code, country_name, continent_code, continent_name, time_zone, region_code, region_name, owner, city_name, county_name, post_code, area_code, metro_code, latitude, longitude)
19
+ VALUES (#{row[0]}, #{row[1]}, '#{row[2]}', '#{row[3]}', '#{row[4]}', '#{row[5]}', '#{row[6]}', '#{row[7]}', '#{row[8]}', '#{row[9]}', '#{row[10]}', '#{row[11]}', '#{row[12]}', '#{row[13]}', '#{row[14]}', #{row[15]}, #{row[16]})"
20
+ @db.connection.execute(insert_query)
21
+ end
22
+
23
+ ActiveRecord::Base.remove_connection
data/test/utils_test.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  require_relative "test_helper"
2
2
 
3
- class UtilsTest < MiniTest::Unit::TestCase
4
- def setup
5
- Ipligence::Utils.stubs(:log)
6
- end
3
+ class UtilsTest < MiniTest::Test
7
4
 
8
5
  def test_convert_dotted_to_long
9
6
  assert_equal(3232235521, Ipligence::Utils.convert_dotted_to_long("192.168.0.1"))
@@ -12,56 +9,4 @@ class UtilsTest < MiniTest::Unit::TestCase
12
9
  assert_equal(4294967295, Ipligence::Utils.convert_dotted_to_long("255.255.255.255"))
13
10
  end
14
11
 
15
- def test_repopulate_db
16
- record = Ipligence::Record.create!(:ipblock_from => 3280108544, :ipblock_to => 3280109567)
17
-
18
- Ipligence::Utils.repopulate_db("#{File.dirname(__FILE__)}/fixtures/ipligence_test.csv")
19
-
20
- # Old records should be deleted
21
- assert_equal(false, Ipligence::Record.exists?(record.id))
22
-
23
- assert_equal(4, Ipligence::Record.count)
24
-
25
- ipligence = Ipligence::Record.first
26
-
27
- assert_equal(0, ipligence.ipblock_from)
28
- assert_equal(16777215, ipligence.ipblock_to)
29
- assert_equal(nil, ipligence.country_code)
30
- assert_equal(nil, ipligence.country_name)
31
- assert_equal(nil, ipligence.continent_code)
32
- assert_equal(nil, ipligence.continent_name)
33
- assert_equal(nil, ipligence.time_zone)
34
- assert_equal(nil, ipligence.region_code)
35
- assert_equal(nil, ipligence.region_name)
36
- assert_equal("NOT ALLOCATED", ipligence.owner)
37
- assert_equal(nil, ipligence.city_name)
38
- assert_equal(nil, ipligence.county_name)
39
- assert_equal(nil, ipligence.post_code)
40
- assert_equal(nil, ipligence.area_code)
41
- assert_equal(nil, ipligence.metro_code)
42
- assert_equal("0", ipligence.latitude)
43
- assert_equal("0", ipligence.longitude)
44
-
45
-
46
- ipligence = Ipligence::Record.last
47
-
48
- assert_equal(16778240, ipligence.ipblock_from)
49
- assert_equal(16778495, ipligence.ipblock_to)
50
- assert_equal("AU", ipligence.country_code)
51
- assert_equal("AUSTRALIA", ipligence.country_name)
52
- assert_equal("OC", ipligence.continent_code)
53
- assert_equal("OCEANIA", ipligence.continent_name)
54
- assert_equal("GMT+10", ipligence.time_zone)
55
- assert_equal("VIC", ipligence.region_code)
56
- assert_equal("VICTORIA", ipligence.region_name)
57
- assert_equal("LEVEL 5 530 COLLINS STREET", ipligence.owner)
58
- assert_equal("PRAHRAN", ipligence.city_name)
59
- assert_equal(nil, ipligence.county_name)
60
- assert_equal("3181", ipligence.post_code)
61
- assert_equal(nil, ipligence.area_code)
62
- assert_equal(nil, ipligence.metro_code)
63
- assert_equal("-37.85", ipligence.latitude)
64
- assert_equal("145", ipligence.longitude)
65
- end
66
-
67
12
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipligence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
- - Sevastianos Komianos
7
+ - Sebastian Komianos, Fernando Guillen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-06 00:00:00.000000000 Z
11
+ date: 2014-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: mocha
56
+ name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '>='
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: minitest
70
+ name: mocha
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - '>='
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: sqlite3
84
+ name: minitest
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - '>='
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: Ruby Gem to integrate Ipligence DB in Rails apps
97
+ description: A gem to integrate the IPligence database in ruby
98
98
  email:
99
99
  - sebastian.komianos@daliaresearch.com
100
100
  executables: []
@@ -102,25 +102,22 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - .gitignore
105
- - .ruby-version
106
105
  - Gemfile
107
106
  - LICENSE.txt
108
107
  - README.md
109
108
  - Rakefile
110
109
  - ipligence.gemspec
111
- - lib/generators/ipligence/migration_generator.rb
112
- - lib/generators/ipligence/templates/create_ipligence_records_table.rb
113
110
  - lib/ipligence.rb
114
- - lib/ipligence/railtie.rb
115
- - lib/ipligence/record.rb
111
+ - lib/ipligence/client.rb
116
112
  - lib/ipligence/utils.rb
117
113
  - lib/ipligence/version.rb
118
- - lib/tasks/ipligence.rake
114
+ - test/client_test.rb
115
+ - test/db/ipligence.sqlite
119
116
  - test/fixtures/ipligence_test.csv
120
- - test/record_test.rb
117
+ - test/schema.rb
121
118
  - test/test_helper.rb
122
119
  - test/utils_test.rb
123
- homepage: https://github.com/DaliaResearch/Ipligence
120
+ homepage: http://github.com/DaliaResearch/ipligence
124
121
  licenses:
125
122
  - MIT
126
123
  metadata: {}
@@ -143,9 +140,11 @@ rubyforge_project:
143
140
  rubygems_version: 2.0.3
144
141
  signing_key:
145
142
  specification_version: 4
146
- summary: Ruby Gem to integrate Ipligence DB in Rails apps
143
+ summary: A ruby gem for the IPligence database
147
144
  test_files:
145
+ - test/client_test.rb
146
+ - test/db/ipligence.sqlite
148
147
  - test/fixtures/ipligence_test.csv
149
- - test/record_test.rb
148
+ - test/schema.rb
150
149
  - test/test_helper.rb
151
150
  - test/utils_test.rb
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.0.0-p247
@@ -1,25 +0,0 @@
1
- require "rails/generators"
2
-
3
- class Ipligence::MigrationGenerator < Rails::Generators::Base
4
- include Rails::Generators::Migration
5
-
6
- desc "Generates migration for Ipligence::Record model"
7
-
8
- def self.source_root
9
- File.join(File.dirname(__FILE__), "templates")
10
- end
11
-
12
- def self.next_migration_number(dirname) #:nodoc:
13
- migration_number_attempt = Time.now.utc.strftime("%Y%m%d%H%M%S")
14
-
15
- if ActiveRecord::Base.timestamped_migrations && migration_number_attempt > current_migration_number(dirname).to_s
16
- migration_number_attempt
17
- else
18
- serial_migration_number(dirname)
19
- end
20
- end
21
-
22
- def copy_migration
23
- migration_template "create_ipligence_records_table.rb", "db/migrate/create_ipligence_records_table.rb"
24
- end
25
- end
@@ -1,29 +0,0 @@
1
- class CreateIpligenceRecordsTable < ActiveRecord::Migration
2
- def self.up
3
- create_table :ipligence_records do |t|
4
- t.integer :ipblock_from, :null => false
5
- t.integer :ipblock_to, :null => false
6
- t.string :country_code
7
- t.string :country_name
8
- t.string :continent_code
9
- t.string :continent_name
10
- t.string :time_zone
11
- t.string :region_code
12
- t.string :region_name
13
- t.string :owner
14
- t.string :city_name
15
- t.string :county_name
16
- t.string :post_code
17
- t.string :area_code
18
- t.string :metro_code
19
- t.string :latitude
20
- t.string :longitude
21
-
22
- t.timestamps
23
- end
24
- end
25
-
26
- def self.down
27
- drop_table :ipligence_records
28
- end
29
- end
@@ -1,9 +0,0 @@
1
- module Ipligence
2
- class Railtie < Rails::Railtie
3
- railtie_name :ipligence
4
-
5
- rake_tasks do
6
- load "tasks/ipligence.rake"
7
- end
8
- end
9
- end
@@ -1,11 +0,0 @@
1
- class Ipligence::Record < ::ActiveRecord::Base
2
- self.table_name = "ipligence_records"
3
-
4
- validates :ipblock_from, :presence => true
5
- validates :ipblock_to, :presence => true
6
-
7
- def self.fetch(ip)
8
- long_ip = Ipligence::Utils.convert_dotted_to_long(ip).to_s
9
- Ipligence::Record.where("(ipblock_from <= :ip) and (:ip <= ipblock_to)", { :ip => long_ip } ).first
10
- end
11
- end
@@ -1,8 +0,0 @@
1
- require "ipligence"
2
-
3
- namespace :ipligence do
4
- desc "Repopulate Ipligence Records Table"
5
- task :repopulate_db, [:path] => :environment do |t, args|
6
- Ipligence::Utils.repopulate_db(args.path)
7
- end
8
- end
data/test/record_test.rb DELETED
@@ -1,26 +0,0 @@
1
- require_relative "test_helper"
2
-
3
- class RecordsTest < MiniTest::Unit::TestCase
4
- def setup
5
- Ipligence::Record.destroy_all
6
-
7
- @record_1 =
8
- Ipligence::Record.create!(
9
- :ipblock_from => 3280108544,
10
- :ipblock_to => 3280109567
11
- )
12
-
13
- @record_2 =
14
- Ipligence::Record.create!(
15
- :ipblock_from => 3232235521,
16
- :ipblock_to => 3232235523
17
- )
18
- end
19
-
20
- def test_fetch
21
- assert_equal(@record_1.id, Ipligence::Record.fetch("195.130.124.0").id)
22
- assert_equal(@record_2.id, Ipligence::Record.fetch("192.168.0.1").id)
23
- assert_equal(nil, Ipligence::Record.fetch("0.0.0.0"))
24
- end
25
-
26
- end