ip2location_ruby 8.1.1 → 8.2.0

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
  SHA256:
3
- metadata.gz: 5d160588d5a49065122250d6dee7accdbe55df7cf59fd6553280021d70f7de57
4
- data.tar.gz: 2d3f13b07b33befcbf33f9219d746bd6e3a5b7f3e7e698f73a1c40b3403351d3
3
+ metadata.gz: d40ddb96c3b68fc1ff4d851a0389f715e09c41c3b185d8936558686fa39ce2a4
4
+ data.tar.gz: 1b0d493cddb9e69b692be6f3a84b4e178d1ad16a1c63641732638b6134cf51e1
5
5
  SHA512:
6
- metadata.gz: 6f4038abb8b7d375e5fa7bcc755caf185618b2b7c14bd905349ab07df4626e0ad13e503ef28bd3f149c8a6ecf03b597ea549d497f8c161dca05bff6a72bdbc3f
7
- data.tar.gz: 313f941c440627468594b39364793c1ef919fe6d3bdf0842338510983b88186d3e21feb6c37a03e6eb18ae4e6c074b25685cc066ff46605773f0ebcc183195d9
6
+ metadata.gz: c21ffd658ec663cc61c726a77a907e56bb69114ac1a016ccea7568ccf0b6faa180a4efade585009dbed2c526880fddef1dce724f1e724f0592ec1b52174ae287
7
+ data.tar.gz: 6337c61e5594a6e48bc2b2541afe9d0f944eeeabd6200091ac6f3b0459d60e31f216ac4ca5aaa51e5bc3c890eb17b1fd28fbdadce4d7b46c6308faa117a621de
@@ -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,50 +10,58 @@ 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'
15
+ ## BIN Database
16
+ Below is the description of the functions available in the **BIN Database** lookup.
17
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')
18
+ | Function Name | Description |
19
+ |---|---|
20
+ | open | Open the IP2Location BIN data for lookup. |
21
+ | close | Close and clean up the file pointer. |
22
+ | close | Close and clean up the file pointer. |
23
+ | get_all | Return the geolocation information in array. |
24
+ | get_country_short | Return the ISO3166-1 country code (2-digits) of the IP address. |
25
+ | get_country_long | Return the ISO3166-1 country name of the IP address. |
26
+ | 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 |
27
+ | get_city | Return the city name of the IP address. |
28
+ | get_latitude | Return the city latitude of the IP address. |
29
+ | get_longitude | Return the city longtitude of the IP address. |
30
+ | get_isp | Return the ISP name of the IP address. |
31
+ | get_domain | Return the domain name of IP address. |
32
+ | get_zipcode | Return the zipcode of the city. |
33
+ | get_timezone | Return the UTC time zone (with DST supported). |
34
+ | get_netspeed | Return the Internet connection type. |
35
+ | get_iddcode | Return the IDD prefix to call the city from another country. |
36
+ | get_areacode | Return the area code of the city. |
37
+ | get_weathercode | Return the nearest weather observation station code. |
38
+ | get_weathername | Return the nearest weather observation station name. |
39
+ | get_mcc | Return the Mobile Country Codes (MCC). |
40
+ | get_mnc | Return the Mobile Network Code (MNC). |
41
+ | get_mobilebrand | Commercial brand associated with the mobile carrier. |
42
+ | get_elevation | Return average height of city above sea level in meters (m). |
43
+ | get_usagetype | Return the ISP's usage type of IP address. |
20
44
 
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
45
 
48
- i2l.close()
49
- ```
46
+ ## Web Service
47
+ Below is the description of the functions available in the **Web Service** lookup.
50
48
 
51
- # Sample BIN Databases
49
+ | Function Name | Description |
50
+ |---|---|
51
+ | Constructor | Expect 2 input parameters:<ol><li>IP2Location API Key.</li><li>Package (WS1 - WS24)</li></ol> |
52
+ | 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> |
53
+ | get_credit | Return remaining credit of the web service account. |
52
54
 
53
- * Download free IP2Location LITE databases at [https://lite.ip2location.com](https://lite.ip2location.com)
54
- * Download IP2Location sample databases at [https://www.ip2location.com/developers](https://www.ip2location.com/developers)
55
+ # Dependencies
56
+ This library requires IP2Location BIN data file to function. You may download the BIN data file at
57
+ * IP2Location LITE BIN Data (Free): https://lite.ip2location.com
58
+ * IP2Location Commercial BIN Data (Comprehensive): https://www.ip2location.com
55
59
 
56
- # IPv4 BIN vs IPv6 BIN
60
+ 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.
61
+
62
+ You can also sign up for [IP2Location Web Service](https://www.ip2location.com/web-service/ip2location) to lookup by IP2Location API.
57
63
 
64
+ # IPv4 BIN vs IPv6 BIN
58
65
  * Use the IPv4 BIN file if you just need to query IPv4 addresses.
59
66
  * Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.
60
67
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 8.1.1
1
+ 8.2.0
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
 
@@ -30,4 +31,11 @@ print record['elevation']
30
31
  print "\n"
31
32
  print 'Usage Type: ' + record['usagetype'] + "\n"
32
33
 
33
- i2l.close()
34
+ i2l.close()
35
+
36
+ # Web Service
37
+ ws = Ip2locationWebService.new('demo', 'WS24')
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.1"
8
+ s.version = "8.2.0"
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"]
@@ -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'
@@ -535,5 +537,43 @@ class Ip2location
535
537
  end
536
538
 
537
539
  private :get_record, :bsearch, :get_from_to, :read32, :readipv6
540
+ end
538
541
 
542
+ class Ip2locationWebService
543
+ attr_accessor :ws_api_key, :ws_package
544
+
545
+ def initialize(api_key, package)
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
+ self.ws_api_key = api_key
553
+ self.ws_package = package
554
+ end
555
+
556
+ def lookup(ip, add_ons, language)
557
+ 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))
558
+ parsed_response = JSON.parse(response)
559
+ if parsed_response.nil?
560
+ return false
561
+ end
562
+ if !parsed_response["response"].nil?
563
+ raise Exception.new "Error: " + parsed_response["response"]
564
+ end
565
+ return parsed_response
566
+ end
567
+
568
+ def get_credit()
569
+ response = Net::HTTP.get(URI("https://api.ip2location.com/v2/?key=" + self.ws_api_key + "&check=true"))
570
+ parsed_response = JSON.parse(response)
571
+ if parsed_response.nil?
572
+ return 0
573
+ end
574
+ if parsed_response["response"].nil?
575
+ return 0
576
+ end
577
+ return parsed_response["response"]
578
+ end
539
579
  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.1
4
+ version: 8.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ip2location
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-24 00:00:00.000000000 Z
11
+ date: 2020-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata