ipligence 0.0.3 → 0.0.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73cbbfbc628ac5f8f87cc5693319cf118e42753c
4
- data.tar.gz: 689e803487cb2c23bd2981bc124726caa961f293
3
+ metadata.gz: b9e6ec61058d4ad2b8da18aa620783724890b7ee
4
+ data.tar.gz: a065074b9ff4dba16f1fc84b816774d904be3a27
5
5
  SHA512:
6
- metadata.gz: 87c536d5c19d587590dcf240edf92772eb9044d17897b344481f788c3c5838f4374f3c13a1d171edbd8eab279c8547fdd582ce3162b80c0a135c972722b765be
7
- data.tar.gz: 4b6b9b1e90d82f4231609afaecf4db837328421bf1af658e2953cac6ec38f09425017848eac075595d600a44b3054ee4e4b4894ef2c12433ea17af8878fa6579
6
+ metadata.gz: 6679a0bf3eb446bc17eeb238555f2e995a19de2b64a6230cdd74365c5b7213a50a2739f4938c085b026af2b9dbb09e90970c9dbcbdfa994951d02307892f96bf
7
+ data.tar.gz: 6b44581fc33ad7fd0315082a19f7978c8665cbcc55fd8e0d303a69fd04cf4f26cfcbb65972dd33a507c821863f1fc3aa789a5c67b3945f33824ec1c6e23a0f14
data/README.md CHANGED
@@ -26,7 +26,14 @@ Or install it yourself as:
26
26
 
27
27
  The gem needs an IPligence database. After you create it you can configure the `Ipligence::Client`:
28
28
 
29
- client = Ipligence::Client.new("adapter", "database", "username", "password")
29
+ client =
30
+ Ipligence::Client.new(
31
+ :adapter => "adapter",
32
+ :host => "host.it.com"
33
+ :database => "database",
34
+ :username => "username",
35
+ :password => "password"
36
+ )
30
37
 
31
38
  Then, you can get a hash with the geodata for a given IP using the client's `data` method:
32
39
 
@@ -36,7 +43,7 @@ For example, querying for `195.130.124.1` returns the following hash:
36
43
 
37
44
  => {:ip_from=>"3280108544", :ip_to=>"3280109567", :country_code=>"GR", :country_name=>"GREECE",
38
45
  :continent_code=>"EU", :continent_name=>"EUROPE", :time_zone=>"GMT+2", :region_code=>"",
39
- :region_name=>"", :owner=>"IONIAN UNIVERSITY", :city_name=>"CORFU", :county_name=>"",
46
+ :region_name=>"", :owner=>"IONIAN UNIVERSITY", :city_name=>"CORFU", :country_name=>"",
40
47
  :post_code=>"", :area_code=>"", :metro_code=>"", :latitude=>"39.62", :longitude=>"19.9197"}
41
48
 
42
49
  ## Contributing
@@ -1,5 +1,6 @@
1
1
  require_relative "ipligence/version"
2
2
  require_relative "ipligence/utils"
3
+ require_relative "ipligence/db_connection"
3
4
  require_relative "ipligence/client"
4
5
 
5
6
  module Ipligence
@@ -2,15 +2,10 @@ require "active_record"
2
2
 
3
3
  class Ipligence::Client
4
4
 
5
- attr_accessor :db
5
+ attr_reader :connection
6
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
7
+ def initialize(opts)
8
+ @connection = Ipligence::DBConnection.establish_connection(opts).connection
14
9
  end
15
10
 
16
11
  def data(ip)
@@ -42,7 +37,7 @@ class Ipligence::Client
42
37
  long_ip = Ipligence::Utils.convert_dotted_to_long(ip).to_s
43
38
  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
39
  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
40
+ connection.exec_query(sql_query).first
46
41
  end
47
42
 
48
43
  end
@@ -0,0 +1,3 @@
1
+ class Ipligence::DBConnection < ActiveRecord::Base
2
+ @abstract_class = true
3
+ end
@@ -1,3 +1,3 @@
1
1
  module Ipligence
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -5,23 +5,16 @@ class ClientTest < MiniTest::Test
5
5
  end
6
6
 
7
7
  def test_initialize
8
- connection_params = {
9
- :adapter => "ADAPTER",
10
- :database => "DATABASE",
11
- :username => "USERNAME",
12
- :password => "PASSWORD"
13
- }
14
-
15
8
  adapter_mock = mock(:connection => "CONNECTION")
16
9
 
17
- ActiveRecord::Base.expects(:establish_connection).with(connection_params).returns(adapter_mock)
18
- client = Ipligence::Client.new("ADAPTER", "DATABASE", "USERNAME", "PASSWORD")
10
+ ActiveRecord::Base.expects(:establish_connection).with("OPTS").returns(adapter_mock)
11
+ client = Ipligence::Client.new("OPTS")
19
12
 
20
- assert_equal("CONNECTION", client.db)
13
+ assert_equal("CONNECTION", client.connection)
21
14
  end
22
15
 
23
16
  def test_data
24
- client = Ipligence::Client.new("sqlite3", "#{File.dirname(__FILE__)}/db/ipligence.sqlite")
17
+ client = Ipligence::Client.new(:adapter => "sqlite3", :database => "#{File.dirname(__FILE__)}/db/ipligence.sqlite")
25
18
 
26
19
  data = client.data("2.84.170.255")
27
20
  assert_equal(39102976, data[:ip_from])
@@ -13,8 +13,8 @@ ActiveRecord::Schema.define :version => 0 do
13
13
  t.string :city_name, null: false
14
14
  t.string :county_name, null: false
15
15
  t.string :post_code, null: false
16
- t.string :area_code, null: false
17
16
  t.string :metro_code, null: false
17
+ t.string :area_code, null: false
18
18
  t.decimal :latitude, null: false
19
19
  t.decimal :longitude, null: false
20
20
  end
@@ -15,7 +15,7 @@ load("#{File.dirname(__FILE__)}/schema.rb")
15
15
 
16
16
  CSV.foreach("#{File.dirname(__FILE__)}/fixtures/ipligence_test.csv") do |row|
17
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)
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, metro_code, area_code, latitude, longitude)
19
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
20
  @db.connection.execute(insert_query)
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipligence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Komianos, Fernando Guillen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-30 00:00:00.000000000 Z
11
+ date: 2014-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -109,6 +109,7 @@ files:
109
109
  - ipligence.gemspec
110
110
  - lib/ipligence.rb
111
111
  - lib/ipligence/client.rb
112
+ - lib/ipligence/db_connection.rb
112
113
  - lib/ipligence/utils.rb
113
114
  - lib/ipligence/version.rb
114
115
  - test/client_test.rb