ip2location_rails 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d0021043a6e79782ab1e993c50bd4881c5cd4ae1694f67fa183fe1efc85abc84
4
+ data.tar.gz: 5c07387aa05f1b86caa919bc49ce2c9a0eb1c8f7dc3ffb74aea3828d88149d30
5
+ SHA512:
6
+ metadata.gz: 11d3a754860a4bdeaafb21961beef16a3a69307be355a88e805c0516b616d945d4811cacd0b1a213a5864167dc90d311c90407467dcf568453f6ebc3b868c230
7
+ data.tar.gz: 521917ddebe83b99a9b66b317fc50f3430e6f574269c5879cc7a2ac1883fc0d706e6cd4754c602eb445428ecb46dcbaa001ee0ccb2cc19cb00604d1527679faf
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ip2location_rails.gemspec
4
+ gemspec
5
+ gem 'ip2location_ruby', ">= 8.7.3"
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2023 - 2024 IP2Location ( support@ip2location.com )
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # IP2Location Ruby on Rails Library
2
+ This is IP2Location Ruby on Rails library that enables the user to find the country, region or state, district, city, latitude and longitude, ZIP/Postal 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, usage type, address type, IAB category and ASN from IP address using IP2Location database. The library reads the geo location information from **IP2Location BIN data** file.
3
+
4
+ Supported IPv4 and IPv6 address.
5
+
6
+ ## INSTALLATION
7
+ 1. Add this lines to your application's Gemfile:
8
+ ```ruby
9
+ gem 'ip2location_ruby'
10
+ gem 'ip2location_rails'
11
+ ```
12
+ 2. Then execute it
13
+ ```bash
14
+ $ bundle install
15
+ ```
16
+ 3. Open the preferred file in the `config/environments` directory. Add the following code to the chosen configuration file after the `Rails.application.configure do` line.
17
+ ```ruby
18
+ config.ip2location_db_path = Rails.root.join('lib', 'assets', 'ip2location_rails', 'IP2LOCATION.BIN').to_s
19
+ ```
20
+
21
+ ## USAGE
22
+ 1. Download IP2Location BIN database
23
+ - IP2Location free LITE database at https://lite.ip2location.com
24
+ - IP2Location commercial database at https://www.ip2location.com
25
+ 2. Create a folder named as `ip2location_rails` in the `lib/assets` directory.
26
+ 3. Unzip and copy the BIN file into `lib/assets/ip2location_rails` folder.
27
+ 4. Rename the BIN file to **IP2LOCATION.BIN**.
28
+ 5. Create a **TestController** using the below command line
29
+ ```bash
30
+ bin/rails generate controller Test index --skip-routes
31
+ ```
32
+ 6. Open the *app/controllers/test_controller.rb* in any text editor.
33
+ 7. Add the below lines into the controller file.
34
+ ```ruby
35
+ require 'ip2location_rails'
36
+
37
+ class TestController < ApplicationController
38
+ def index
39
+ location_service = Ip2locationRails.new('8.8.8.8')
40
+ @country_code = location_service.country_code
41
+ @country_name = location_service.country_name
42
+ @region = location_service.region
43
+ @city = location_service.city
44
+ @latitude = location_service.latitude
45
+ @longitude = location_service.longitude
46
+ @isp = location_service.isp
47
+ @domain = location_service.domain
48
+ @netspeed = location_service.netspeed
49
+ @area_code = location_service.areacode
50
+ @idd_code = location_service.iddcode
51
+ @time_zone = location_service.timezone
52
+ @zip_code = location_service.zipcode
53
+ @weather_station_name = location_service.weatherstationname
54
+ @weather_station_code = location_service.weatherstationcode
55
+ @mcc= location_service.mcc
56
+ @mnc = location_service.mnc
57
+ @mobile_brand = location_service.mobilebrand
58
+ @elevation = location_service.elevation
59
+ @usage_type = location_service.usagetype
60
+ @address_type = location_service.addresstype
61
+ @category = location_service.category
62
+ @district = location_service.district
63
+ @asn = location_service.asn
64
+ @as = location_service.as
65
+ end
66
+ end
67
+ ```
68
+ 8. Open the *app/views/test/index.html.erb* in any text editor and add the below lines into it.
69
+ ```
70
+ <p>Country Code: <%= @country_code %></p>
71
+ <p>Country Name: <%= @country_name %></p>
72
+ <p>Region Name: <%= @region %></p>
73
+ <p>City Name: <%= @city %></p>
74
+ <p>Latitude: <%= @latitude %></p>
75
+ <p>Longitude: <%= @longitude %></p>
76
+ <p>ISP Name: <%= @isp %></p>
77
+ <p>Domain Name: <%= @domain %></p>
78
+ <p>Net Speed: <%= @netspeed %></p>
79
+ <p>Area Code: <%= @area_code %></p>
80
+ <p>IDD Code: <%= @idd_code %></p>
81
+ <p>Time Zone: <%= @time_zone %></p>
82
+ <p>ZIP Code: <%= @zip_code %></p>
83
+ <p>Weather Station Code: <%= @weather_station_name %></p>
84
+ <p>Weather Station Name: <%= @weather_station_code %></p>
85
+ <p>MCC: <%= @mcc %></p>
86
+ <p>MNC: <%= @mnc %></p>
87
+ <p>Mobile Carrier: <%= @mobile_brand %></p>
88
+ <p>Elevation: <%= @elevation %></p>
89
+ <p>Usage Type: <%= @usage_type %></p>
90
+ <p>Address Type: <%= @address_type %></p>
91
+ <p>Category: <%= @category %></p>
92
+ <p>District: <%= @district %></p>
93
+ <p>ASN: <%= @asn %></p>
94
+ <p>AS: <%= @as %></p>
95
+ ```
96
+ 9. Add the following line into the *config/routes.rb* file after the `Rails.application.routes.draw do` line.
97
+ ```ruby
98
+ get "/test", to: "test#index"
99
+ ```
100
+ 10. Restart your development server.
101
+ ```bash
102
+ $ bin/rails server
103
+ ```
104
+ 11. Enter the URL <your domain>/test and run. You should see the information of **8.8.8.8** IP address.
105
+
106
+ ## Dependencies
107
+ This library requires IP2Location BIN data file to function. You may download the BIN data file at
108
+ * IP2Location LITE BIN Data (Free): https://lite.ip2location.com
109
+ * IP2Location Commercial BIN Data (Comprehensive): https://www.ip2location.com
110
+
111
+ ## IPv4 BIN vs IPv6 BIN
112
+ * Use the IPv4 BIN file if you just need to query IPv4 addresses.
113
+ * Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.
114
+
115
+ ## Support
116
+ Email: support@ip2location.com
117
+ URL: [https://www.ip2location.com](https://www.ip2location.com)
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'ip2location_rails'
3
+ s.version = '1.0.0'
4
+ s.required_ruby_version = '>= 2.5.0'
5
+ s.require_paths = ["lib"]
6
+ s.authors = ["ip2location"]
7
+ s.email = ["support@ip2location.com"]
8
+ s.description = "The official IP2Location Ruby on Rails library to geolocate an IP address. You can lookup for country, region, district, city, latitude and longitude, ZIP/Postal 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, usage type, address type, IAB category and ASN from an IP address. Supported both IPv4 and IPv6 lookup."
9
+ s.summary = "IP2Location Ruby on Rails library"
10
+ s.homepage = 'https://www.ip2location.com'
11
+ s.licenses = ["MIT"]
12
+ s.files = [
13
+ "LICENSE.txt",
14
+ "Gemfile",
15
+ "README.md",
16
+ "ip2location_rails.gemspec",
17
+ "lib/ip2location_rails.rb",
18
+ ]
19
+ s.add_runtime_dependency 'ip2location_ruby', '>= 8.7.3'
20
+ end
@@ -0,0 +1,112 @@
1
+ require 'ip2location_ruby'
2
+
3
+ class Ip2locationRails
4
+ def initialize(ip_address)
5
+ @ip_address = ip_address
6
+ @i2l = Ip2location.new.open(Rails.configuration.ip2location_db_path)
7
+ end
8
+
9
+ def location
10
+ @i2l.get_all(@ip_address)
11
+ end
12
+
13
+ def country_code
14
+ location['country_short']
15
+ end
16
+
17
+ def country_name
18
+ location['country_long']
19
+ end
20
+
21
+ def region
22
+ location['region']
23
+ end
24
+
25
+ def city
26
+ location['city']
27
+ end
28
+
29
+ def latitude
30
+ location['latitude']
31
+ end
32
+
33
+ def longitude
34
+ location['longitude']
35
+ end
36
+
37
+ def isp
38
+ location['isp']
39
+ end
40
+
41
+ def domain
42
+ location['domain']
43
+ end
44
+
45
+ def netspeed
46
+ location['netspeed']
47
+ end
48
+
49
+ def areacode
50
+ location['areacode']
51
+ end
52
+
53
+ def iddcode
54
+ location['iddcode']
55
+ end
56
+
57
+ def timezone
58
+ location['timezone']
59
+ end
60
+
61
+ def zipcode
62
+ location['zipcode']
63
+ end
64
+
65
+ def weatherstationname
66
+ location['weatherstationname']
67
+ end
68
+
69
+ def weatherstationcode
70
+ location['weatherstationcode']
71
+ end
72
+
73
+ def mcc
74
+ location['mcc']
75
+ end
76
+
77
+ def mnc
78
+ location['mnc']
79
+ end
80
+
81
+ def mobilebrand
82
+ location['mobilebrand']
83
+ end
84
+
85
+ def elevation
86
+ location['elevation']
87
+ end
88
+
89
+ def usagetype
90
+ location['usagetype']
91
+ end
92
+
93
+ def addresstype
94
+ location['addresstype']
95
+ end
96
+
97
+ def category
98
+ location['category']
99
+ end
100
+
101
+ def district
102
+ location['district']
103
+ end
104
+
105
+ def asn
106
+ location['asn']
107
+ end
108
+
109
+ def as
110
+ location['as']
111
+ end
112
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ip2location_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ip2location
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-11-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ip2location_ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 8.7.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 8.7.3
27
+ description: The official IP2Location Ruby on Rails library to geolocate an IP address.
28
+ You can lookup for country, region, district, city, latitude and longitude, ZIP/Postal
29
+ code, time zone, Internet Service Provider (ISP) or company name, domain name, net
30
+ speed, area code, weather station code, weather station name, mobile country code
31
+ (MCC), mobile network code (MNC) and carrier brand, elevation, usage type, address
32
+ type, IAB category and ASN from an IP address. Supported both IPv4 and IPv6 lookup.
33
+ email:
34
+ - support@ip2location.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - ip2location_rails.gemspec
43
+ - lib/ip2location_rails.rb
44
+ homepage: https://www.ip2location.com
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 2.5.0
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.5.23
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: IP2Location Ruby on Rails library
67
+ test_files: []