ip2location_ruby 8.1.0 → 8.2.3

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
  SHA256:
3
- metadata.gz: 613585ff34abe6d207beb9de5a02a2b5291c6fdb9f6b2c392bc450faa92c393b
4
- data.tar.gz: cda9e736447f28ca68af0617cb4c12b6983347630aa8b2b9070fcc4aaa17161b
3
+ metadata.gz: 118e20ce9246a282a4762523c68870f645bde1532e79950e812e935eecc4252e
4
+ data.tar.gz: 23da14c93843dc1952371b5f250015d59fdf27323fcc0232882f65a036509a86
5
5
  SHA512:
6
- metadata.gz: 041d86f010371a8640341a61e76d442f2511176f3369cf27f200e042e284ee62c7561feebb646e78cffa4ec84ca5a2626cff3f8b0722dec274f99780b4d8b01a
7
- data.tar.gz: 333b9c07798a16ef3af4a60d07329a828087d132a0f81a2ccffc89b9596c0f0e4718a113612c539a1f039ccfd78e681da0deb7661a6ed44b19bfd08ad3f9a352
6
+ metadata.gz: 5d1da0f2aed10f79b0268e38368abaaa66b8c2e5f24a862fb46fd6c5c58047f6e5a15941561ba527020fcd312aa62f1c8e918fc8273ffa25ba6f4a3e6847a834
7
+ data.tar.gz: f1481d6b6bfd5143612c6772a4c9be2d2f0216e74293afa80b1fcba422755016a27167c99640880e1fda45577e3cee7b69b3398a7f7fe89b68f7394e418614f9
data/Gemfile CHANGED
@@ -7,10 +7,8 @@ gem 'bindata'
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
 
9
9
  group :development do
10
- gem 'awesome_print'
11
10
  gem "rspec", "~> 2.8.0"
12
11
  gem "rdoc", "~> 3.12"
13
12
  gem "bundler", ">= 1.2.0"
14
13
  gem "jeweler", "~> 1.8.4"
15
- gem "simplecov", ">= 0"
16
14
  end
@@ -1,74 +1,66 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- addressable (2.3.5)
5
- awesome_print (1.2.0)
6
- bindata (2.1.0)
7
- builder (3.2.2)
8
- diff-lcs (1.1.3)
9
- docile (1.1.1)
10
- faraday (0.8.8)
11
- multipart-post (~> 1.2.0)
12
- git (1.2.6)
13
- github_api (0.10.1)
14
- addressable
15
- faraday (~> 0.8.1)
16
- hashie (>= 1.2)
17
- multi_json (~> 1.4)
18
- nokogiri (~> 1.5.2)
19
- oauth2
20
- hashie (2.0.5)
21
- highline (1.6.20)
22
- httpauth (0.2.0)
23
- jeweler (1.8.8)
24
- builder
25
- bundler (~> 1.0)
26
- git (>= 1.2.5)
27
- github_api (= 0.10.1)
28
- highline (>= 1.6.15)
29
- nokogiri (>= 1.8.2)
30
- rake
31
- rdoc
32
- json (1.8.1)
33
- jwt (0.1.8)
34
- multi_json (>= 1.5)
35
- multi_json (1.8.2)
36
- multi_xml (0.5.5)
37
- multipart-post (1.2.0)
38
- nokogiri (>= 1.8.2)
39
- oauth2 (0.9.2)
40
- faraday (~> 0.8)
41
- httpauth (~> 0.2)
42
- jwt (~> 0.1.4)
43
- multi_json (~> 1.0)
44
- multi_xml (~> 0.5)
45
- rack (~> 1.2)
46
- rack (>= 1.6.11)
47
- rake (10.1.1)
48
- rdoc (3.12.2)
49
- json (~> 1.4)
50
- rspec (2.8.0)
51
- rspec-core (~> 2.8.0)
52
- rspec-expectations (~> 2.8.0)
53
- rspec-mocks (~> 2.8.0)
54
- rspec-core (2.8.0)
55
- rspec-expectations (2.8.0)
56
- diff-lcs (~> 1.1.2)
57
- rspec-mocks (2.8.0)
58
- simplecov (0.8.2)
59
- docile (~> 1.1.0)
60
- multi_json
61
- simplecov-html (~> 0.8.0)
62
- simplecov-html (0.8.0)
63
-
64
- PLATFORMS
65
- ruby
66
-
67
- DEPENDENCIES
68
- awesome_print
69
- bindata
70
- bundler (>= 1.2.0)
71
- jeweler (~> 1.8.4)
72
- rdoc (~> 3.12)
73
- rspec (~> 2.8.0)
74
- simplecov
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ bindata (2.1.0)
6
+ builder (3.2.2)
7
+ diff-lcs (1.1.3)
8
+ docile (1.1.1)
9
+ faraday (0.8.8)
10
+ multipart-post (~> 1.2.0)
11
+ git (1.2.6)
12
+ github_api (0.10.1)
13
+ addressable
14
+ faraday (~> 0.8.1)
15
+ hashie (>= 1.2)
16
+ multi_json (~> 1.4)
17
+ nokogiri (~> 1.5.2)
18
+ oauth2
19
+ hashie (2.0.5)
20
+ highline (1.6.20)
21
+ httpauth (0.2.0)
22
+ jeweler (1.8.8)
23
+ builder
24
+ bundler (~> 1.0)
25
+ git (>= 1.2.5)
26
+ github_api (= 0.10.1)
27
+ highline (>= 1.6.15)
28
+ nokogiri (>= 1.8.2)
29
+ rake
30
+ rdoc
31
+ json (>= 2.3.0)
32
+ jwt (0.1.8)
33
+ multi_json (>= 1.5)
34
+ multi_json (1.8.2)
35
+ multi_xml (0.5.5)
36
+ multipart-post (1.2.0)
37
+ nokogiri (>= 1.8.2)
38
+ oauth2 (0.9.2)
39
+ faraday (~> 0.8)
40
+ httpauth (~> 0.2)
41
+ jwt (~> 0.1.4)
42
+ multi_json (~> 1.0)
43
+ multi_xml (~> 0.5)
44
+ rack (~> 1.2)
45
+ rack (>= 1.6.11)
46
+ rake (>= 12.3.3)
47
+ rdoc (3.12.2)
48
+ json (~> 1.4)
49
+ rspec (2.8.0)
50
+ rspec-core (~> 2.8.0)
51
+ rspec-expectations (~> 2.8.0)
52
+ rspec-mocks (~> 2.8.0)
53
+ rspec-core (2.8.0)
54
+ rspec-expectations (2.8.0)
55
+ diff-lcs (~> 1.1.2)
56
+ rspec-mocks (2.8.0)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ bindata
63
+ bundler (>= 1.2.0)
64
+ jeweler (~> 1.8.4)
65
+ rdoc (~> 3.12)
66
+ rspec (~> 2.8.0)
@@ -1,4 +1,4 @@
1
- Copyright (c) 2019 IP2Location ( support@ip2location.com )
1
+ Copyright (c) 2020 IP2Location ( support@ip2location.com )
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -2,8 +2,7 @@
2
2
  [![Total Downloads](https://img.shields.io/gem/dt/ip2location_ruby.svg)](https://rubygems.org/gems/ip2location_ruby)
3
3
 
4
4
  # IP2Location Ruby Library
5
- This is IP2Location Ruby library that enables the user to find the country, region or state, city, latitude and longitude, US ZIP code, time zone, Internet Service Provider (ISP) or company name, domain name, net speed, area code, weather station code, weather station name, mobile country code (MCC), mobile network code (MNC) and carrier brand, elevation, and usage type by IP address or hostname originates from. The library reads the geo location information
6
- from **IP2Location BIN data** file.
5
+ This is IP2Location Ruby library that enables the user to find the country, region or state, city, latitude and longitude, US ZIP code, time zone, Internet Service Provider (ISP) or company name, domain name, net speed, area code, weather station code, weather station name, mobile country code (MCC), mobile network code (MNC) and carrier brand, elevation, and usage type by IP address or hostname originates from. The library reads the geo location information from **IP2Location BIN data** file or web service.
7
6
 
8
7
  Supported IPv4 and IPv6 address.
9
8
 
@@ -11,48 +10,57 @@ For more details, please visit:
11
10
  [https://www.ip2location.com/developers/ruby](https://www.ip2location.com/developers/ruby)
12
11
 
13
12
  # Usage
13
+ You can check the **example.rb** file to learn more about usage.
14
14
 
15
- ```
16
- require 'ip2location_ruby'
17
-
18
- i2l = Ip2location.new.open("./data/IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE.BIN")
19
- record = i2l.get_all('8.8.8.8')
20
-
21
- print 'Country Code: ' + record['country_short'] + "\n"
22
- print 'Country Name: ' + record['country_long'] + "\n"
23
- print 'Region Name: ' + record['region'] + "\n"
24
- print 'City Name: ' + record['city'] + "\n"
25
- print 'Latitude: '
26
- print record['latitude']
27
- print "\n"
28
- print 'Longitude: '
29
- print record['longitude']
30
- print "\n"
31
- print 'ISP: ' + record['isp'] + "\n"
32
- print 'Domain: ' + record['domain'] + "\n"
33
- print 'Net Speed: ' + record['netspeed'] + "\n"
34
- print 'Area Code: ' + record['areacode'] + "\n"
35
- print 'IDD Code: ' + record['iddcode'] + "\n"
36
- print 'Time Zone: ' + record['timezone'] + "\n"
37
- print 'ZIP Code: ' + record['zipcode'] + "\n"
38
- print 'Weather Station Code: ' + record['weatherstationname'] + "\n"
39
- print 'Weather Station Name: ' + record['weatherstationcode'] + "\n"
40
- print 'MCC: ' + record['mcc'] + "\n"
41
- print 'MNC: ' + record['mnc'] + "\n"
42
- print 'Mobile Name: ' + record['mobilebrand'] + "\n"
43
- print 'Elevation: '
44
- print record['elevation']
45
- print "\n"
46
- print 'Usage Type: ' + record['usagetype'] + "\n"
47
- ```
48
-
49
- # Sample BIN Databases
50
-
51
- * Download free IP2Location LITE databases at [https://lite.ip2location.com](https://lite.ip2location.com)
52
- * Download IP2Location sample databases at [https://www.ip2location.com/developers](https://www.ip2location.com/developers)
15
+ ## BIN Database
16
+ Below is the description of the functions available in the **BIN Database** lookup.
53
17
 
54
- # IPv4 BIN vs IPv6 BIN
18
+ | Function Name | Description |
19
+ |---|---|
20
+ | open | Open the IP2Location BIN data for lookup. |
21
+ | close | Close and clean up the file pointer. |
22
+ | get_all | Return the geolocation information in array. |
23
+ | get_country_short | Return the ISO3166-1 country code (2-digits) of the IP address. |
24
+ | get_country_long | Return the ISO3166-1 country name of the IP address. |
25
+ | get_region | Return the ISO3166-2 region name of the IP address. Please visit [ISO3166-2 Subdivision Code](https://www.ip2location.com/free/iso3166-2) for the information of ISO3166-2 supported |
26
+ | get_city | Return the city name of the IP address. |
27
+ | get_latitude | Return the city latitude of the IP address. |
28
+ | get_longitude | Return the city longtitude of the IP address. |
29
+ | get_isp | Return the ISP name of the IP address. |
30
+ | get_domain | Return the domain name of IP address. |
31
+ | get_zipcode | Return the zipcode of the city. |
32
+ | get_timezone | Return the UTC time zone (with DST supported). |
33
+ | get_netspeed | Return the Internet connection type. |
34
+ | get_iddcode | Return the IDD prefix to call the city from another country. |
35
+ | get_areacode | Return the area code of the city. |
36
+ | get_weathercode | Return the nearest weather observation station code. |
37
+ | get_weathername | Return the nearest weather observation station name. |
38
+ | get_mcc | Return the Mobile Country Codes (MCC). |
39
+ | get_mnc | Return the Mobile Network Code (MNC). |
40
+ | get_mobilebrand | Commercial brand associated with the mobile carrier. |
41
+ | get_elevation | Return average height of city above sea level in meters (m). |
42
+ | get_usagetype | Return the ISP's usage type of IP address. |
43
+
44
+
45
+ ## Web Service
46
+ Below is the description of the functions available in the **Web Service** lookup.
47
+
48
+ | Function Name | Description |
49
+ |---|---|
50
+ | Constructor | Expect 3 input parameters:<ol><li>IP2Location API Key.</li><li>Package (WS1 - WS24)</li></li><li>Use HTTPS or HTTP</li></ol> |
51
+ | lookup | Return the IP information in array.<ul><li>country_code</li><li>country_name</li><li>region_name</li><li>city_name</li><li>latitude</li><li>longitude</li><li>zip_code</li><li>time_zone</li><li>isp</li><li>domain</li><li>net_speed</li><li>idd_code</li><li>area_code</li><li>weather_station_code</li><li>weather_station_name</li><li>mcc</li><li>mnc</li><li>mobile_brand</li><li>elevation</li><li>usage_type</li><li>continent<ul><li>name</li><li>code</li><li>hemisphere</li><li>translations</li></ul></li><li>country<ul><li>name</li><li>alpha3_code</li><li>numeric_code</li><li>demonym</li><li>flag</li><li>capital</li><li>total_area</li><li>population</li><li>currency<ul><li>code</li><li>name</li><li>symbol</li></ul></li><li>language<ul><li>code</li><li>name</li></ul></li><li>idd_code</li><li>tld</li><li>translations</li></ul></li><li>region<ul><li>name</li><li>code</li><li>translations</li></ul></li><li>city<ul><li>name</li><li>translations</li></ul></li><li>geotargeting<ul><li>metro</li></ul></li><li>country_groupings</li><li>time_zone_info<ul><li>olson</li><li>current_time</li><li>gmt_offset</li><li>is_dst</li><li>sunrise</li><li>sunset</li></ul></li><ul> |
52
+ | get_credit | Return remaining credit of the web service account. |
55
53
 
54
+ # Dependencies
55
+ This library requires IP2Location BIN data file to function. You may download the BIN data file at
56
+ * IP2Location LITE BIN Data (Free): https://lite.ip2location.com
57
+ * IP2Location Commercial BIN Data (Comprehensive): https://www.ip2location.com
58
+
59
+ An outdated BIN database was provided in the library for your testing. You are recommended to visit the above links to download the latest BIN database.
60
+
61
+ You can also sign up for [IP2Location Web Service](https://www.ip2location.com/web-service/ip2location) to lookup by IP2Location API.
62
+
63
+ # IPv4 BIN vs IPv6 BIN
56
64
  * Use the IPv4 BIN file if you just need to query IPv4 addresses.
57
65
  * Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.
58
66
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 8.1.0
1
+ 8.2.3
data/example.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'ip2location_ruby'
2
2
 
3
+ # BIN Database
3
4
  i2l = Ip2location.new.open("./data/IP2LOCATION-LITE-DB1.IPV6.BIN")
4
5
  record = i2l.get_all('8.8.8.8')
5
6
 
@@ -28,4 +29,13 @@ print 'Mobile Name: ' + record['mobilebrand'] + "\n"
28
29
  print 'Elevation: '
29
30
  print record['elevation']
30
31
  print "\n"
31
- print 'Usage Type: ' + record['usagetype'] + "\n"
32
+ print 'Usage Type: ' + record['usagetype'] + "\n"
33
+
34
+ i2l.close()
35
+
36
+ # Web Service
37
+ ws = Ip2locationWebService.new('demo', 'WS24', true)
38
+ record = ws.lookup('8.8.8.8', 'continent,country,region,city,geotargeting,country_groupings,time_zone_info', 'en')
39
+ print record
40
+ print "\n"
41
+ print ws.get_credit()
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ip2location_ruby"
8
- s.version = "8.1.0"
8
+ s.version = "8.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.require_paths = ["lib"]
@@ -34,10 +34,9 @@ Gem::Specification.new do |s|
34
34
  "lib/ip2location_ruby/i2l_string_data.rb",
35
35
  "lib/ip2location_ruby/ip2location_config.rb",
36
36
  "lib/ip2location_ruby/ip2location_record.rb",
37
- "spec/assets/DB24.DEMO4.BIN",
38
- "spec/assets/DB24.DEMO6.BIN",
39
- "spec/assets/IP-COUNTRY-SAMPLE.BIN",
40
- "spec/ip2location_ruby_spec.rb",
37
+ "spec/assets/IP2LOCATION-LITE-DB1.IPV6.BIN",
38
+ "spec/ip2location_ruby_database_spec.rb",
39
+ "spec/ip2location_ruby_webservice_spec.rb",
41
40
  "spec/spec_helper.rb",
42
41
  "rb/data/IP2LOCATION-LITE-DB1.IPV6.BIN"
43
42
  ]
@@ -59,29 +58,23 @@ Gem::Specification.new do |s|
59
58
 
60
59
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
60
  s.add_runtime_dependency(%q<bindata>, [">= 0"])
62
- s.add_development_dependency(%q<awesome_print>, [">= 0"])
63
61
  s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
64
62
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
65
63
  s.add_development_dependency(%q<bundler>, [">= 1.2.0"])
66
64
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
67
- s.add_development_dependency(%q<simplecov>, [">= 0"])
68
65
  else
69
66
  s.add_dependency(%q<bindata>, [">= 0"])
70
- s.add_dependency(%q<awesome_print>, [">= 0"])
71
67
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
72
68
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
73
69
  s.add_dependency(%q<bundler>, [">= 1.2.0"])
74
70
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
75
- s.add_dependency(%q<simplecov>, [">= 0"])
76
71
  end
77
72
  else
78
73
  s.add_dependency(%q<bindata>, [">= 0"])
79
- s.add_dependency(%q<awesome_print>, [">= 0"])
80
74
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
81
75
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
82
76
  s.add_dependency(%q<bundler>, [">= 1.2.0"])
83
77
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
84
- s.add_dependency(%q<simplecov>, [">= 0"])
85
78
  end
86
79
  end
87
80
 
@@ -1,6 +1,8 @@
1
1
  # encoding: utf-8
2
2
  require 'bindata'
3
3
  require 'ipaddr'
4
+ require 'net/http'
5
+ require 'json'
4
6
  require 'ip2location_ruby/ip2location_config'
5
7
  require 'ip2location_ruby/database_config'
6
8
  require 'ip2location_ruby/i2l_float_data'
@@ -31,6 +33,10 @@ class Ip2location
31
33
  self
32
34
  end
33
35
 
36
+ def close()
37
+ self.file.close
38
+ end
39
+
34
40
  def get_record(ip)
35
41
  ipno = IPAddr.new(ip, Socket::AF_UNSPEC)
36
42
  self.ip_version, ipnum = validateip(ipno)
@@ -402,7 +408,7 @@ class Ip2location
402
408
  if valid
403
409
  rec = get_record(ip)
404
410
  if !(rec.nil?)
405
- mnc = (defined?(mnc) && rec.mnc != '') ? rec.mnc : FIELD_NOT_SUPPORTED
411
+ mnc = (defined?(rec.mnc) && rec.mnc != '') ? rec.mnc : FIELD_NOT_SUPPORTED
406
412
  else
407
413
  mnc = INVALID_IP_ADDRESS
408
414
  end
@@ -531,5 +537,55 @@ class Ip2location
531
537
  end
532
538
 
533
539
  private :get_record, :bsearch, :get_from_to, :read32, :readipv6
540
+ end
541
+
542
+ class Ip2locationWebService
543
+ attr_accessor :ws_api_key, :ws_package, :ws_use_ssl
544
+
545
+ def initialize(api_key, package, use_ssl)
546
+ if !api_key.match(/^[0-9A-Z]{10}$/) && api_key != 'demo'
547
+ raise Exception.new "Please provide a valid IP2Location web service API key."
548
+ end
549
+ if !package.match(/^WS[0-9]+$/)
550
+ package = 'WS1'
551
+ end
552
+ if use_ssl == ''
553
+ use_ssl = true
554
+ end
555
+ self.ws_api_key = api_key
556
+ self.ws_package = package
557
+ self.ws_use_ssl = use_ssl
558
+ end
559
+
560
+ def lookup(ip, add_ons, language)
561
+ if self.ws_use_ssl
562
+ response = Net::HTTP.get(URI("https://api.ip2location.com/v2/?key=" + self.ws_api_key + "&ip=" + ip + "&package=" + self.ws_package + "&format=json&addon=" + add_ons + "&lang=" + language))
563
+ else
564
+ response = Net::HTTP.get(URI("http://api.ip2location.com/v2/?key=" + self.ws_api_key + "&ip=" + ip + "&package=" + self.ws_package + "&format=json&addon=" + add_ons + "&lang=" + language))
565
+ end
566
+ parsed_response = JSON.parse(response)
567
+ if parsed_response.nil?
568
+ return false
569
+ end
570
+ if !parsed_response["response"].nil?
571
+ raise Exception.new "Error: " + parsed_response["response"]
572
+ end
573
+ return parsed_response
574
+ end
534
575
 
576
+ def get_credit()
577
+ if self.ws_use_ssl
578
+ response = Net::HTTP.get(URI("https://api.ip2location.com/v2/?key=" + self.ws_api_key + "&check=true"))
579
+ else
580
+ response = Net::HTTP.get(URI("http://api.ip2location.com/v2/?key=" + self.ws_api_key + "&check=true"))
581
+ end
582
+ parsed_response = JSON.parse(response)
583
+ if parsed_response.nil?
584
+ return 0
585
+ end
586
+ if parsed_response["response"].nil?
587
+ return 0
588
+ end
589
+ return parsed_response["response"]
590
+ end
535
591
  end
@@ -0,0 +1,147 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Ip2location" do
4
+ it "work correctly with ipv4" do
5
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
6
+ record = i2l.get_all('8.8.8.8')
7
+ expect(record['country_short']).to eq 'US'
8
+ end
9
+
10
+ it "work correctly with get_country_short" do
11
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
12
+ record = i2l.get_country_short('8.8.8.8')
13
+ expect(record).to eq 'US'
14
+ end
15
+
16
+ it "work correctly with get_country_long" do
17
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
18
+ record = i2l.get_country_long('8.8.8.8')
19
+ expect(record).to eq 'United States of America'
20
+ end
21
+
22
+ it "work correctly with get_region" do
23
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
24
+ record = i2l.get_region('8.8.8.8')
25
+ expect(record).to eq 'NOT SUPPORTED'
26
+ end
27
+
28
+ it "work correctly with get_city" do
29
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
30
+ record = i2l.get_city('8.8.8.8')
31
+ expect(record).to eq 'NOT SUPPORTED'
32
+ end
33
+
34
+ it "work correctly with get_latitude" do
35
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
36
+ record = i2l.get_latitude('8.8.8.8')
37
+ expect(record).to eq 'NOT SUPPORTED'
38
+ end
39
+
40
+ it "work correctly with get_longitude" do
41
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
42
+ record = i2l.get_longitude('8.8.8.8')
43
+ expect(record).to eq 'NOT SUPPORTED'
44
+ end
45
+
46
+ it "work correctly with get_isp" do
47
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
48
+ record = i2l.get_isp('8.8.8.8')
49
+ expect(record).to eq 'NOT SUPPORTED'
50
+ end
51
+
52
+ it "work correctly with get_domain" do
53
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
54
+ record = i2l.get_domain('8.8.8.8')
55
+ expect(record).to eq 'NOT SUPPORTED'
56
+ end
57
+
58
+ it "work correctly with get_zipcode" do
59
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
60
+ record = i2l.get_zipcode('8.8.8.8')
61
+ expect(record).to eq 'NOT SUPPORTED'
62
+ end
63
+
64
+ it "work correctly with get_timezone" do
65
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
66
+ record = i2l.get_timezone('8.8.8.8')
67
+ expect(record).to eq 'NOT SUPPORTED'
68
+ end
69
+
70
+ it "work correctly with get_netspeed" do
71
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
72
+ record = i2l.get_netspeed('8.8.8.8')
73
+ expect(record).to eq 'NOT SUPPORTED'
74
+ end
75
+
76
+ it "work correctly with get_iddcode" do
77
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
78
+ record = i2l.get_iddcode('8.8.8.8')
79
+ expect(record).to eq 'NOT SUPPORTED'
80
+ end
81
+
82
+ it "work correctly with get_areacode" do
83
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
84
+ record = i2l.get_areacode('8.8.8.8')
85
+ expect(record).to eq 'NOT SUPPORTED'
86
+ end
87
+
88
+ it "work correctly with get_weatherstationcode" do
89
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
90
+ record = i2l.get_weatherstationcode('8.8.8.8')
91
+ expect(record).to eq 'NOT SUPPORTED'
92
+ end
93
+
94
+ it "work correctly with get_weatherstationname" do
95
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
96
+ record = i2l.get_weatherstationname('8.8.8.8')
97
+ expect(record).to eq 'NOT SUPPORTED'
98
+ end
99
+
100
+ it "work correctly with get_mcc" do
101
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
102
+ record = i2l.get_mcc('8.8.8.8')
103
+ expect(record).to eq 'NOT SUPPORTED'
104
+ end
105
+
106
+ it "work correctly with get_mnc" do
107
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
108
+ record = i2l.get_mnc('8.8.8.8')
109
+ expect(record).to eq 'NOT SUPPORTED'
110
+ end
111
+
112
+ it "work correctly with get_mobilebrand" do
113
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
114
+ record = i2l.get_mobilebrand('8.8.8.8')
115
+ expect(record).to eq 'NOT SUPPORTED'
116
+ end
117
+
118
+ it "work correctly with get_elevation" do
119
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
120
+ record = i2l.get_elevation('8.8.8.8')
121
+ expect(record).to eq 'NOT SUPPORTED'
122
+ end
123
+
124
+ it "work correctly with get_usagetype" do
125
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
126
+ record = i2l.get_usagetype('8.8.8.8')
127
+ expect(record).to eq 'NOT SUPPORTED'
128
+ end
129
+
130
+ it "work correctly with ipv6" do
131
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
132
+ record = i2l.get_all('2001:4860:4860::8888')
133
+ expect(record['country_short']).to eq 'US'
134
+ end
135
+
136
+ it "work correctly with ipv6 get_country_long" do
137
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
138
+ record = i2l.get_country_long('2001:4860:4860::8888')
139
+ expect(record).to eq 'United States of America'
140
+ end
141
+
142
+ it "work correctly with ipv6 get_region" do
143
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
144
+ record = i2l.get_region('2001:4860:4860::8888')
145
+ expect(record).to eq 'NOT SUPPORTED'
146
+ end
147
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Ip2location" do
4
+ it "work correctly with web service lookup" do
5
+ ws = Ip2locationWebService.new('demo', 'WS24', true)
6
+ record = ws.lookup('8.8.8.8', '', 'en')
7
+ expect(record['country_code']).to eq 'US'
8
+ end
9
+
10
+ it "work correctly with web service get_credit" do
11
+ ws = Ip2locationWebService.new('demo', 'WS24', true)
12
+ record = ws.get_credit()
13
+ expect(record).to_not eq 0
14
+ end
15
+ end
@@ -9,5 +9,4 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
9
 
10
10
  RSpec.configure do |config|
11
11
 
12
- end
13
- require 'awesome_print'
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ip2location_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.0
4
+ version: 8.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ip2location
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-05 00:00:00.000000000 Z
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: awesome_print
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,20 +80,6 @@ dependencies:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
82
  version: 1.8.4
97
- - !ruby/object:Gem::Dependency
98
- name: simplecov
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
83
  description: The official IP2Location Ruby library to geolocate an IP address. You
112
84
  can lookup for country, region, city, latitude, longitude, zip code, time zone,
113
85
  ISP, domain, area code, usage type, mobile data, weather data and elevation from
@@ -137,10 +109,9 @@ files:
137
109
  - lib/ip2location_ruby/ip2location_config.rb
138
110
  - lib/ip2location_ruby/ip2location_record.rb
139
111
  - rb/data/IP2LOCATION-LITE-DB1.IPV6.BIN
140
- - spec/assets/DB24.DEMO4.BIN
141
- - spec/assets/DB24.DEMO6.BIN
142
- - spec/assets/IP-COUNTRY-SAMPLE.BIN
143
- - spec/ip2location_ruby_spec.rb
112
+ - spec/assets/IP2LOCATION-LITE-DB1.IPV6.BIN
113
+ - spec/ip2location_ruby_database_spec.rb
114
+ - spec/ip2location_ruby_webservice_spec.rb
144
115
  - spec/spec_helper.rb
145
116
  homepage: https://github.com/ip2location/ip2location-ruby
146
117
  licenses:
@@ -165,7 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
136
  - !ruby/object:Gem::Version
166
137
  version: '0'
167
138
  requirements: []
168
- rubygems_version: 3.0.3
139
+ rubyforge_project:
140
+ rubygems_version: 2.7.6.2
169
141
  signing_key:
170
142
  specification_version: 4
171
143
  summary: the ip2location ruby library
Binary file
Binary file
@@ -1,53 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "Ip2location" do
4
- it "work correctly with ipv4" do
5
- i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP-COUNTRY-SAMPLE.bin")
6
- record = i2l.get_all('13.5.10.6')
7
- record.should_not be_nil
8
- record.country_short.should == 'US'
9
- end
10
-
11
- it "work correctly with ipv4 with new library" do
12
- i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/DB24.DEMO4.bin")
13
- record = i2l.get_all('13.5.10.6')
14
- record.should_not be_nil
15
- record.country_short.should == 'KR'
16
- end
17
-
18
- it "work correctly with ipv6 with new library" do
19
- i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/DB24.DEMO6.bin")
20
- record = i2l.get_all('2a01:04f8:0d16:26c2::')
21
- record.should_not be_nil
22
- record.country_short.should == 'DE'
23
- end
24
-
25
- # it "profile ipv6 in IPV6.BIN" do
26
- # i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE.BIN")
27
- # File.new(File.dirname(__FILE__) + "/assets/ipv6_ip.txt").readlines.each do |line|
28
- # record = i2l.get_all(line.split(' ').first)
29
- # end
30
- # end
31
-
32
- # it "profile ipv4 in IPV6.BIN" do
33
- # i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE.BIN")
34
- # File.new(File.dirname(__FILE__) + "/assets/ipv4_ip.txt").readlines.each do |line|
35
- # record = i2l.get_all(line.split(' ').first)
36
- # end
37
- # end
38
-
39
- # it "profile ipv4 in IPV4.BIN" do
40
- # i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE.BIN")
41
- # File.new(File.dirname(__FILE__) + "/assets/ipv4_ip.txt").readlines.each do |line|
42
- # record = i2l.get_all(line.split(' ').first)
43
- # end
44
- # end
45
-
46
- # this need spec/assets/IP2LOCATION-LITE-DB5.bin file which too big to include in this test.
47
-
48
- # it "should get float value of attitude" do
49
- # i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB5.bin")
50
- # record = i2l.get_all('192.110.164.88')
51
- # record['latitude'].should eq(33.44837951660156)
52
- # end
53
- end