ip2location_io_ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0b6cc3db17af0def0fd75c9bf704ef6f9570e1dcac6283c40c9237b48f0a41fe
4
+ data.tar.gz: 4dbd3e55362da1e7c4f6b1ff680504dcd552153b2eae2ceb4f0440463f27cb6a
5
+ SHA512:
6
+ metadata.gz: b7043339f314edb74ff7cad060a9e54d1f9358abf05ecb5130cad0e51fba2f63e9b879159f261314c6960a20f69aadad11c9409d88e824aa081152c51c6d6d28
7
+ data.tar.gz: b8066a4655d818a3b70b5bc521939ef195dc1ee707ec5007d5485141938471b72daf0b63a96d579cbfe7d54469fc63503d2513338620737ed3afd0762888b2db
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ip2location_io_ruby.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ip2location_io_ruby (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ x64-mingw32
12
+
13
+ DEPENDENCIES
14
+ ip2location_io_ruby!
15
+
16
+ BUNDLED WITH
17
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 IP2Location.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,367 @@
1
+ IP2Location.io Ruby SDK
2
+ ========================
3
+ This Ruby module enables user to query for an enriched data set, such as country, region, district, city, latitude & longitude, ZIP code, time zone, ASN, ISP, domain, net speed, IDD code, area code, weather station data, MNC, MCC, mobile brand, elevation, usage type, address type, advertisement category and proxy data with an IP address. It supports both IPv4 and IPv6 address lookup.
4
+
5
+ In addition, this module provides WHOIS lookup api that helps users to obtain domain information, WHOIS record, by using a domain name. The WHOIS API returns a comprehensive WHOIS data such as creation date, updated date, expiration date, domain age, the contact information of the registrant, mailing address, phone number, email address, nameservers the domain is using and much more.
6
+
7
+ This module requires API key to function. You may sign up for a free API key at https://www.ip2location.io/pricing.
8
+
9
+
10
+ Usage Example
11
+ ============
12
+ ### Lookup IP Address Geolocation Data
13
+ ```ruby
14
+ require 'ip2location_io_ruby'
15
+
16
+ # Configures IP2Location.io API key
17
+ IP2LocationIORuby::Configuration.api_key = 'YOUR_API_KEY'
18
+
19
+ # Lookup ip address geolocation data
20
+ IP2LocationIORuby::Api::IPGeolocation.lookup('8.8.8.8', 'en'); # The language parameter is only available for Plus and Security plan only.
21
+ ```
22
+
23
+ ### Lookup Domain Information
24
+ ```ruby
25
+ require 'ip2location_io_ruby'
26
+
27
+ # Configures IP2Location.io API key
28
+ IP2LocationIORuby::Configuration.api_key = 'YOUR_API_KEY'
29
+
30
+ # Lookup domain information
31
+ IP2LocationIORuby::Api::DomainWhois.lookup('example.com');
32
+ ```
33
+
34
+ ### Convert Normal Text to Punycode
35
+ ```ruby
36
+ require 'ip2location_io_ruby'
37
+
38
+ # Configures IP2Location.io API key
39
+ IP2LocationIORuby::Configuration.api_key = 'YOUR_API_KEY'
40
+
41
+ # Convert normal text to punycode
42
+ IP2LocationIORuby::Api::DomainWhois.get_punycode('täst.de');
43
+ ```
44
+
45
+ ### Convert Punycode to Normal Text
46
+ ```ruby
47
+ require 'ip2location_io_ruby'
48
+
49
+ # Configures IP2Location.io API key
50
+ IP2LocationIORuby::Configuration.api_key = 'YOUR_API_KEY'
51
+
52
+ # Convert punycode to normal text
53
+ IP2LocationIORuby::Api::DomainWhois.get_normal_text('xn--tst-qla.de');
54
+ ```
55
+
56
+ ### Get Domain Name
57
+ ```ruby
58
+ require 'ip2location_io_ruby'
59
+
60
+ # Configures IP2Location.io API key
61
+ IP2LocationIORuby::Configuration.api_key = 'YOUR_API_KEY'
62
+
63
+ # Get domain name from URL
64
+ IP2LocationIORuby::Api::DomainWhois.get_domain_name('https://www.example.com/exe');
65
+ ```
66
+
67
+ ### Get Domain Extension
68
+ ```ruby
69
+ require 'ip2location_io_ruby'
70
+
71
+ # Configures IP2Location.io API key
72
+ IP2LocationIORuby::Configuration.api_key = 'YOUR_API_KEY'
73
+
74
+ # Get domain extension (gTLD or ccTLD) from URL or domain name
75
+ IP2LocationIORuby::Api::DomainWhois.get_domain_extension('example.com');
76
+ ```
77
+
78
+
79
+ Response Parameter
80
+ ============
81
+ ### IP Geolocation Lookup function
82
+ | Parameter | Type | Description |
83
+ |---|---|---|
84
+ |ip|string|IP address.|
85
+ |country_code|string|Two-character country code based on ISO 3166.|
86
+ |country_name|string|Country name based on ISO 3166.|
87
+ |region_name|string|Region or state name.|
88
+ |city_name|string|City name.|
89
+ |latitude|double|City latitude. Defaults to capital city latitude if city is unknown.|
90
+ |longitude|double|City longitude. Defaults to capital city longitude if city is unknown.|
91
+ |zip_code|string|ZIP/Postal code.|
92
+ |time_zone|string|UTC time zone (with DST supported).|
93
+ |asn|string|Autonomous system number (ASN).|
94
+ |as|string|Autonomous system (AS) name.|
95
+ |isp|string|Internet Service Provider or company's name.|
96
+ |domain|string|Internet domain name associated with IP address range.|
97
+ |net_speed|string|Internet connection type. DIAL = dial-up, DSL = broadband/cable/fiber/mobile, COMP = company/T1|
98
+ |idd_code|string|The IDD prefix to call the city from another country.|
99
+ |area_code|string|A varying length number assigned to geographic areas for calls between cities.|
100
+ |weather_station_code|string|The special code to identify the nearest weather observation station.|
101
+ |weather_station_name|string|The name of the nearest weather observation station.|
102
+ |mcc|string|Mobile Country Codes (MCC) as defined in ITU E.212 for use in identifying mobile stations in wireless telephone networks, particularly GSM and UMTS networks.|
103
+ |mnc|string|Mobile Network Code (MNC) is used in combination with a Mobile Country Code (MCC) to uniquely identify a mobile phone operator or carrier.|
104
+ |mobile_brand|string|Commercial brand associated with the mobile carrier.|
105
+ |elevation|integer|Average height of city above sea level in meters (m).|
106
+ |usage_type|string|Usage type classification of ISP or company.|
107
+ |address_type|string|IP address types as defined in Internet Protocol version 4 (IPv4) and Internet Protocol version 6 (IPv6).|
108
+ |continent.name|string|Continent name.|
109
+ |continent.code|string|Two-character continent code.|
110
+ |continent.hemisphere|array|The hemisphere of where the country located. The data in array format with first item indicates (north/south) hemisphere and second item indicates (east/west) hemisphere information.|
111
+ |continent.translation|object|Translation data based on the given lang code.|
112
+ |country.name|string|Country name based on ISO 3166.|
113
+ |country.alpha3_code|string|Three-character country code based on ISO 3166.|
114
+ |country.numeric_code|string|Three-character country numeric code based on ISO 3166.|
115
+ |country.demonym|string|Native of the country.|
116
+ |country.flag|string|URL of the country flag image.|
117
+ |country.capital|string|Capital of the country.|
118
+ |country.total_area|integer|Total area in km2.|
119
+ |country.population|integer|Population of the country.|
120
+ |country.currency|object|Currency of the country.|
121
+ |country.language|object|Language of the country.|
122
+ |country.tld|string|Country-Code Top-Level Domain.|
123
+ |country.translation|object|Translation data based on the given lang code.|
124
+ |region.name|string|Region or state name.|
125
+ |region.code|string|ISO3166-2 code.|
126
+ |region.translation|object|Translation data based on the given lang code.|
127
+ |city.name|string| City name.|
128
+ |city.translation|object|Translation data based on the given lang code.|
129
+ |time_zone_info.olson|string|Time zone in Olson format.|
130
+ |time_zone_info.current_time|string|Current time in ISO 8601 format.|
131
+ |time_zone_info.gmt_offset|integer|GMT offset value in seconds.|
132
+ |time_zone_info.is_dst|boolean|Indicate if the time zone value is in DST.|
133
+ |time_zone_info.sunrise|string|Time of sunrise. (hh:mm format in local time, i.e, 07:47)|
134
+ |time_zone_info.sunset|string|Time of sunset. (hh:mm format in local time, i.e 19:50)|
135
+ |geotargeting.metro|string|Metro code based on zip/postal code.|
136
+ |ads_category|string|The domain category code based on IAB Tech Lab Content Taxonomy.|
137
+ |ads_category_name|string|The domain category based on IAB Tech Lab Content Taxonomy. These categories are comprised of Tier-1 and Tier-2 (if available) level categories widely used in services like advertising, Internet security and filtering appliances.|
138
+ |is_proxy|boolean|Whether is a proxy or not.|
139
+ |proxy.last_seen|integer|Proxy last seen in days.|
140
+ |proxy.proxy_type|string|Type of proxy.|
141
+ |proxy.threat|string|Security threat reported.|
142
+ |proxy.provider|string|Name of VPN provider if available.|
143
+
144
+ ```json
145
+ {
146
+ "ip":"8.8.8.8",
147
+ "country_code":"US",
148
+ "country_name":"United States of America",
149
+ "region_name":"California",
150
+ "city_name":"Mountain View",
151
+ "latitude":37.405992,
152
+ "longitude":-122.078515,
153
+ "zip_code":"94043",
154
+ "time_zone":"-07:00",
155
+ "asn":"15169",
156
+ "as":"Google LLC",
157
+ "isp":"Google LLC",
158
+ "domain":"google.com",
159
+ "net_speed":"T1",
160
+ "idd_code":"1",
161
+ "area_code":"650",
162
+ "weather_station_code":"USCA0746",
163
+ "weather_station_name":"Mountain View",
164
+ "mcc":"-",
165
+ "mnc":"-",
166
+ "mobile_brand":"-",
167
+ "elevation":32,
168
+ "usage_type":"DCH",
169
+ "address_type":"Anycast",
170
+ "continent":{
171
+ "name":"North America",
172
+ "code":"NA",
173
+ "hemisphere":["north","west"],
174
+ "translation":{
175
+ "lang":"ko",
176
+ "value":"북아메리카"
177
+ }
178
+ },
179
+ "country":{
180
+ "name":"United States of America",
181
+ "alpha3_code":"USA",
182
+ "numeric_code":840,
183
+ "demonym":"Americans",
184
+ "flag":"https://cdn.ip2location.io/assets/img/flags/us.png",
185
+ "capital":"Washington, D.C.",
186
+ "total_area":9826675,
187
+ "population":331002651,
188
+ "currency":{
189
+ "code":"USD",
190
+ "name":"United States Dollar",
191
+ "symbol":"$"
192
+ },
193
+ "language":{
194
+ "code":"EN",
195
+ "name":"English"
196
+ },
197
+ "tld":"us",
198
+ "translation":{
199
+ "lang":"ko",
200
+ "value":"미국"
201
+ }
202
+ },
203
+ "region":{
204
+ "name":"California",
205
+ "code":"US-CA",
206
+ "translation":{
207
+ "lang":"ko",
208
+ "value":"캘리포니아주"
209
+ }
210
+ },
211
+ "city":{
212
+ "name":"Mountain View",
213
+ "translation":{
214
+ "lang":null,
215
+ "value":null
216
+ }
217
+ },
218
+ "time_zone_info":{
219
+ "olson":"America/Los_Angeles",
220
+ "current_time":"2022-04-18T23:41:57-07:00",
221
+ "gmt_offset":-25200,
222
+ "is_dst":true,
223
+ "sunrise":"06:27",
224
+ "sunset":"19:47"
225
+ },
226
+ "geotargeting":{
227
+ "metro":"807"
228
+ },
229
+ "ads_category":"IAB19",
230
+ "ads_category_name":"Technology & Computing",
231
+ "is_proxy":false,
232
+ "proxy":{
233
+ "last_seen":18,
234
+ "proxy_type":"DCH",
235
+ "threat":"-",
236
+ "provider":"-"
237
+ }
238
+ }
239
+ ```
240
+
241
+ ### Domain WHOIS Lookup function
242
+ | Parameter | Type | Description |
243
+ |---|---|---|
244
+ |domain|string|Domain name.|
245
+ |domain_id|string|Domain name ID.|
246
+ |status|string|Domain name status.|
247
+ |create_date|string|Domain name creation date.|
248
+ |update_date|string|Domain name updated date.|
249
+ |expire_date|string|Domain name expiration date.|
250
+ |domain_age|integer|Domain name age in day(s).|
251
+ |whois_server|string|WHOIS server name.|
252
+ |registrar.iana_id|string|Registrar IANA ID.|
253
+ |registrar.name|string|Registrar name.|
254
+ |registrar.url|string|Registrar URL.|
255
+ |registrant.name|string|Registrant name.|
256
+ |registrant.organization|string|Registrant organization.|
257
+ |registrant.street_address|string|Registrant street address.|
258
+ |registrant.city|string|Registrant city.|
259
+ |registrant.region|string|Registrant region.|
260
+ |registrant.zip_code|string|Registrant ZIP Code.|
261
+ |registrant.country|string|Registrant country.|
262
+ |registrant.phone|string|Registrant phone number.|
263
+ |registrant.fax|string|Registrant fax number.|
264
+ |registrant.email|string|Registrant email address.|
265
+ |admin.name|string|Admin name.|
266
+ |admin.organization|string|Admin organization.|
267
+ |admin.street_address|string|Admin street address.|
268
+ |admin.city|string|Admin city.|
269
+ |admin.region|string|Admin region.|
270
+ |admin.zip_code|string|Admin ZIP Code.|
271
+ |admin.country|string|Admin country.|
272
+ |admin.phone|string|Admin phone number.|
273
+ |admin.fax|string|Admin fax number.|
274
+ |admin.email|string|Admin email address.|
275
+ |tech.name|string|Tech name.|
276
+ |tech.organization|string|Tech organization.|
277
+ |tech.street_address|string|Tech street address.|
278
+ |tech.city|string|Tech city.|
279
+ |tech.region|string|Tech region.|
280
+ |tech.zip_code|string|Tech ZIP Code.|
281
+ |tech.country|string|Tech country.|
282
+ |tech.phone|string|Tech phone number.|
283
+ |tech.fax|string|Tech fax number.|
284
+ |tech.email|string|Tech email address.|
285
+ |billing.name|string|Billing name.|
286
+ |billing.organization|string|Billing organization.|
287
+ |billing.street_address|string|Billing street address.|
288
+ |billing.city|string|Billing city.|
289
+ |billing.region|string|Billing region.|
290
+ |billing.zip_code|string|Billing ZIP Code.|
291
+ |billing.country|string|Billing country.|
292
+ |billing.phone|string|Billing phone number.|
293
+ |billing.fax|string|Billing fax number.|
294
+ |billing.email|string|Billing email address.|
295
+ |name_servers|array|Name servers|
296
+
297
+ ```json
298
+ {
299
+ "domain": "locaproxy.com",
300
+ "domain_id": "1710914405_DOMAIN_COM-VRSN",
301
+ "status": "clientTransferProhibited https://icann.org/epp#clientTransferProhibited",
302
+ "create_date": "2012-04-03T02:34:32Z",
303
+ "update_date": "2021-12-03T02:54:57Z",
304
+ "expire_date": "2024-04-03T02:34:32Z",
305
+ "domain_age": 3863,
306
+ "whois_server": "whois.godaddy.com",
307
+ "registrar": {
308
+ "iana_id": "146",
309
+ "name": "GoDaddy.com, LLC",
310
+ "url": "https://www.godaddy.com"
311
+ },
312
+ "registrant": {
313
+ "name": "Registration Private",
314
+ "organization": "Domains By Proxy, LLC",
315
+ "street_address": "DomainsByProxy.com",
316
+ "city": "Tempe",
317
+ "region": "Arizona",
318
+ "zip_code": "85284",
319
+ "country": "US",
320
+ "phone": "+1.4806242599",
321
+ "fax": "+1.4806242598",
322
+ "email": "Select Contact Domain Holder link at https://www.godaddy.com/whois/results.aspx?domain=LOCAPROXY.COM"
323
+ },
324
+ "admin": {
325
+ "name": "Registration Private",
326
+ "organization": "Domains By Proxy, LLC",
327
+ "street_address": "DomainsByProxy.com",
328
+ "city": "Tempe",
329
+ "region": "Arizona",
330
+ "zip_code": "85284",
331
+ "country": "US",
332
+ "phone": "+1.4806242599",
333
+ "fax": "+1.4806242598",
334
+ "email": "Select Contact Domain Holder link at https://www.godaddy.com/whois/results.aspx?domain=LOCAPROXY.COM"
335
+ },
336
+ "tech": {
337
+ "name": "Registration Private",
338
+ "organization": "Domains By Proxy, LLC",
339
+ "street_address": "DomainsByProxy.com",
340
+ "city": "Tempe",
341
+ "region": "Arizona",
342
+ "zip_code": "85284",
343
+ "country": "US",
344
+ "phone": "+1.4806242599",
345
+ "fax": "+1.4806242598",
346
+ "email": "Select Contact Domain Holder link at https://www.godaddy.com/whois/results.aspx?domain=LOCAPROXY.COM"
347
+ },
348
+ "billing": {
349
+ "name": "",
350
+ "organization": "",
351
+ "street_address": "",
352
+ "city": "",
353
+ "region": "",
354
+ "zip_code": "",
355
+ "country": "",
356
+ "phone": "",
357
+ "fax": "",
358
+ "email": ""
359
+ },
360
+ "nameservers": "vera.ns.cloudflare.com, walt.ns.cloudflare.com"
361
+ }
362
+ ```
363
+
364
+
365
+ LICENCE
366
+ =====================
367
+ See the LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/example.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'ip2location_io_ruby'
2
+
3
+ IP2LocationIORuby::Configuration.api_key = 'YOUR_API_KEY'
4
+
5
+ begin
6
+ result = IP2LocationIORuby::Api::IPGeolocation.lookup('8.8.8.8')
7
+ rescue Exception => e
8
+ puts e.message
9
+ else
10
+ puts result.body
11
+ end
12
+
13
+ begin
14
+ result = IP2LocationIORuby::Api::DomainWhois.lookup('example.com')
15
+ rescue Exception => e
16
+ puts e.message
17
+ else
18
+ puts result.body
19
+ end
20
+ puts IP2LocationIORuby::Api::DomainWhois.get_punycode('täst.de')
21
+ puts IP2LocationIORuby::Api::DomainWhois.get_normal_text('xn--tst-qla.de')
22
+ puts IP2LocationIORuby::Api::DomainWhois.get_domain_name('https://www.example.com/exe')
23
+ puts IP2LocationIORuby::Api::DomainWhois.get_domain_extension('example.com')
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "ip2location_io_ruby/version"
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "ip2location_io_ruby"
9
+ s.version = IP2LocationIORuby::VERSION
10
+ s.authors = ["IP2Location"]
11
+ s.email = ["support@ip2location.com"]
12
+ s.summary = "IP2Location IO Ruby SDK"
13
+ s.description = "IP2Location.IO Ruby SDK allows user to query for an enriched data set based on IP address and provides WHOIS lookup api that helps users to obtain domain information."
14
+ s.homepage = "https://github.com/ip2location/ip2location-io-ruby"
15
+ s.licenses = ["MIT"]
16
+ s.require_paths = ["lib"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "example.rb",
28
+ "ip2location_io_ruby.gemspec",
29
+ "lib/ip2location_io_ruby.rb",
30
+ "lib/ip2location_io_ruby/api.rb",
31
+ "lib/ip2location_io_ruby/api/domainwhois.rb",
32
+ "lib/ip2location_io_ruby/api/ipgeolocation.rb",
33
+ "lib/ip2location_io_ruby/configuration.rb",
34
+ "lib/ip2location_io_ruby/version.rb",
35
+ "spec/spec_helper.rb",
36
+ "spec/ip2location_io_ruby_domainwhois_spec.rb",
37
+ "spec/ip2location_io_ruby_ipgeolocation_spec.rb"
38
+ ]
39
+ end
@@ -0,0 +1,74 @@
1
+ require 'uri'
2
+ require 'json'
3
+ require 'simpleidn'
4
+ require 'net/http'
5
+ require "ip2location_io_ruby/configuration"
6
+ require "ip2location_io_ruby/version"
7
+
8
+ module IP2LocationIORuby
9
+ module Api
10
+ class DomainWhois
11
+
12
+ # Lookup domain WHOIS information.
13
+ def self.lookup(domain)
14
+ uri = URI.parse("https://api.ip2whois.com/v2?key=" + IP2LocationIORuby::Configuration.api_key + "&format=json&domain=" + domain + "&source=sdk-ruby-iplio&source_version=" + IP2LocationIORuby::VERSION)
15
+ http = Net::HTTP.new(uri.host, uri.port)
16
+ http.use_ssl = true
17
+ request = Net::HTTP::Get.new(uri.request_uri)
18
+
19
+ response = http.request(request)
20
+
21
+ if response == nil
22
+ raise Exception.new "DomainWhois lookup error."
23
+ elsif JSON[response.body]['error']
24
+ raise Exception.new JSON[response.body]['error']['error_message']
25
+ else
26
+ return response
27
+ end
28
+ end
29
+
30
+ # Get Punycode.
31
+ def self.get_punycode(domain)
32
+ return SimpleIDN.to_ascii(domain)
33
+ end
34
+
35
+ # Get Normal text.
36
+ def self.get_normal_text(domain)
37
+ return SimpleIDN.to_unicode(domain)
38
+ end
39
+
40
+ # Get domain name from a URL.
41
+ def self.get_domain_name(url)
42
+ tlds = [".aaa",".aarp",".abarth",".abbott",".abbvie",".abc",".able",".abogado",".abudhabi",".academy",".accountant",".accountants",".aco",".actor",".adac",".ads",".adult",".aeg",".aero",".aetna",".afamilycompany",".afl",".agakhan",".agency",".aig",".airbus",".airforce",".airtel",".akdn",".alfaromeo",".alibaba",".alipay",".allfinanz",".allstate",".ally",".alsace",".americanexpress",".americanfamily",".amex",".amfam",".amica",".amsterdam",".analytics",".android",".anquan",".anz",".apartments",".app",".apple",".aquarelle",".arab",".aramco",".archi",".army",".art",".arte",".asda",".asia",".associates",".athleta",".attorney",".auction",".audi",".audible",".audio",".auspost",".author",".auto",".autos",".avianca",".aws",".axa",".azure",".baby",".baidu",".band",".bank",".bar",".barcelona",".barclaycard",".barclays",".barefoot",".bargains",".bauhaus",".bayern",".bbc",".bbt",".bbva",".bcg",".bcn",".beats",".beauty",".beer",".bentley",".berlin",".best",".bestbuy",".bet",".bible",".bid",".bike",".bingo",".bio",".biz",".black",".blackfriday",".blockbuster",".blog",".blue",".bms",".bmw",".bnpparibas",".boats",".boehringer",".bofa",".bom",".bond",".boo",".book",".bosch",".bostik",".bot",".boutique",".bradesco",".bridgestone",".broadway",".broker",".brother",".brussels",".bugatti",".build",".builders",".business",".buy",".buzz",".bzh",".cab",".cafe",".cal",".call",".cam",".camera",".camp",".cancerresearch",".canon",".capetown",".capital",".capitalone",".car",".cards",".care",".career",".careers",".cars",".casa",".cash",".casino",".cat",".catering",".cba",".cbs",".ceb",".center",".ceo",".cern",".cfa",".cfd",".chanel",".channel",".chat",".cheap",".chintai",".christmas",".chrome",".chrysler",".church",".cipriani",".city",".cityeats",".claims",".cleaning",".click",".clinic",".clinique",".clothing",".cloud",".club",".clubmed",".coach",".codes",".coffee",".college",".cologne",".com",".comcast",".commbank",".community",".company",".compare",".computer",".comsec",".condos",".construction",".consulting",".contact",".contractors",".cooking",".cookingchannel",".cool",".coop",".corsica",".country",".coupon",".coupons",".credit",".creditcard",".creditunion",".cricket",".cruises",".csc",".cuisinella",".cymru",".cyou",".dabur",".dad",".dance",".date",".dating",".datsun",".day",".dclk",".dds",".deal",".deals",".degree",".delivery",".dell",".deloitte",".delta",".democrat",".dental",".dentist",".desi",".design",".dev",".dhl",".diamonds",".diet",".digital",".direct",".directory",".discount",".dish",".diy",".dk",".dnp",".docs",".doctor",".dodge",".dog",".domains",".dot",".download",".drive",".dtv",".dubai",".duck",".dunlop",".durban",".dvag",".earth",".eat",".eco",".edeka",".edu",".education",".email",".emerck",".energy",".engineer",".engineering",".enterprises",".epson",".equipment",".ericsson",".erni",".esq",".estate",".esurance",".eurovision",".eus",".events",".everbank",".exchange",".expert",".exposed",".express",".extraspace",".fage",".fail",".fairwinds",".faith",".family",".fan",".fans",".farm",".farmers",".fashion",".fast",".fedex",".feedback",".ferrari",".ferrero",".fiat",".fidelity",".film",".final",".finance",".financial",".fire",".firestone",".firmdale",".fish",".fishing",".fit",".fitness",".flickr",".flights",".flir",".florist",".flowers",".fly",".foo",".foodnetwork",".football",".ford",".forex",".forsale",".forum",".foundation",".fox",".free",".fresenius",".frl",".frogans",".frontdoor",".frontier",".ftr",".fujitsu",".fujixerox",".fun",".fund",".furniture",".futbol",".fyi",".gal",".gallery",".gallo",".gallup",".game",".games",".gap",".garden",".gbiz",".gdn",".gea",".gent",".genting",".george",".ggee",".gift",".gifts",".gives",".giving",".glade",".glass",".gle",".global",".globo",".gmail",".gmbh",".gmo",".gmx",".godaddy",".gold",".goldpoint",".golf",".goo",".goodyear",".goog",".google",".gop",".got",".grainger",".graphics",".gratis",".green",".gripe",".group",".guge",".guide",".guitars",".guru",".hamburg",".hangout",".haus",".hbo",".hdfc",".hdfcbank",".health",".healthcare",".help",".helsinki",".here",".hermes",".hgtv",".hiphop",".hisamitsu",".hitachi",".hiv",".hkt",".hockey",".holdings",".holiday",".homedepot",".homegoods",".homes",".homesense",".honda",".horse",".hospital",".host",".hosting",".hot",".hoteles",".house",".how",".hsbc",".hughes",".hyundai",".ibm",".icbc",".ice",".icu",".ieee",".ifm",".ikano",".imamat",".imdb",".immo",".immobilien",".industries",".infiniti",".info",".ing",".ink",".institute",".insurance",".insure",".int",".international",".intuit",".investments",".irish",".iselect",".ismaili",".ist",".istanbul",".it",".itau",".itv",".jaguar",".java",".jcb",".jcp",".jeep",".jetzt",".jewelry",".jll",".jmp",".jnj",".jobs",".joburg",".jot",".joy",".jpmorgan",".jprs",".juegos",".juniper",".kaufen",".kddi",".kerryhotels",".kerrylogistics",".kerryproperties",".kfh",".kia",".kim",".kinder",".kindle",".kitchen",".kiwi",".koeln",".komatsu",".kosher",".kpmg",".kpn",".kred",".kuokgroup",".kyoto",".lacaixa",".ladbrokes",".lamborghini",".lamer",".lancaster",".lancia",".lancome",".land",".landrover",".lasalle",".lat",".latino",".latrobe",".law",".lawyer",".lds",".lease",".leclerc",".lefrak",".legal",".lego",".lexus",".lgbt",".liaison",".lidl",".life",".lifeinsurance",".lifestyle",".lighting",".like",".lilly",".limited",".limo",".lincoln",".linde",".link",".lipsy",".live",".lixil",".loan",".loans",".locker",".locus",".loft",".logs",".lol",".london",".lotte",".lotto",".love",".lpl",".lplfinancial",".ltd",".ltda",".lundbeck",".luxe",".luxury",".macys",".madrid",".maison",".makeup",".man",".management",".mango",".market",".marketing",".markets",".marriott",".maserati",".mba",".mckinsey",".med",".media",".meet",".meme",".memorial",".men",".menu",".metlife",".miami",".mini",".mit",".mitsubishi",".mlb",".mls",".mma",".mobi",".moda",".moe",".moi",".mom",".monash",".money",".mopar",".mormon",".mortgage",".moscow",".motorcycles",".mov",".movie",".movistar",".mtn",".mtr",".museum",".mutual",".nab",".nadex",".nagoya",".name",".nationwide",".natura",".navy",".nba",".nec",".net",".netbank",".netflix",".network",".neustar",".new",".news",".next",".nextdirect",".nexus",".nfl",".ngo",".nhk",".nico",".nike",".nikon",".ninja",".nissan",".nissay",".nokia",".northwesternmutual",".norton",".now",".nowruz",".nowtv",".nra",".nrw",".ntt",".nyc",".obi",".off",".okinawa",".olayan",".olayangroup",".oldnavy",".ollo",".omega",".one",".ong",".onl",".online",".onyourside",".ooo",".oracle",".orange",".org",".organic",".origins",".osaka",".otsuka",".ott",".ovh",".page",".panasonic",".paris",".pars",".partners",".parts",".party",".passagens",".pay",".pccw",".pet",".pfizer",".philips",".photo",".photography",".photos",".physio",".pics",".pictures",".pid",".pin",".ping",".pink",".pioneer",".pizza",".pl",".place",".play",".playstation",".plumbing",".plus",".pnc",".pohl",".poker",".politie",".porn",".post",".pramerica",".praxi",".press",".prime",".pro",".prod",".productions",".prof",".progressive",".promo",".properties",".property",".protection",".pru",".prudential",".pub",".pwc",".qpon",".quebec",".quest",".qvc",".racing",".radio",".raid",".read",".realestate",".realtor",".realty",".recipes",".red",".redstone",".redumbrella",".rehab",".reise",".reisen",".reit",".rent",".rentals",".repair",".report",".republican",".rest",".restaurant",".review",".reviews",".rexroth",".rich",".richardli",".ricoh",".rightathome",".rio",".rip",".rocher",".rocks",".rodeo",".room",".rsvp",".ruhr",".run",".rwe",".ryukyu",".saarland",".safe",".sakura",".sale",".salon",".samsclub",".samsung",".sandvik",".sandvikcoromant",".sanofi",".sap",".sarl",".sas",".save",".sbi",".sbs",".sca",".scb",".schaeffler",".schmidt",".scholarships",".school",".schule",".schwarz",".science",".scjohnson",".scor",".scot",".seat",".secure",".security",".seek",".select",".services",".ses",".seven",".sew",".sex",".sexy",".sfr",".sh",".shangrila",".sharp",".shell",".shia",".shiksha",".shoes",".shop",".shopping",".shouji",".show",".showtime",".shriram",".silk",".sina",".singles",".site",".ski",".skin",".sky",".skype",".sling",".smart",".smile",".sncf",".soccer",".social",".softbank",".software",".solar",".solutions",".song",".sony",".soy",".space",".spot",".spreadbetting",".srl",".srt",".stada",".staples",".star",".starhub",".statebank",".statefarm",".stc",".stcgroup",".stockholm",".storage",".store",".stream",".studio",".study",".style",".sucks",".supplies",".supply",".support",".surf",".surgery",".suzuki",".swatch",".swiftcover",".swiss",".sydney",".symantec",".systems",".tab",".taipei",".talk",".taobao",".target",".tatamotors",".tatar",".tattoo",".tax",".taxi",".tci",".tdk",".team",".tech",".technology",".tel",".telefonica",".temasek",".tennis",".teva",".thd",".theater",".theatre",".tiaa",".tickets",".tienda",".tiffany",".tips",".tires",".tirol",".tjmaxx",".tjx",".tkmaxx",".tmall",".today",".tokyo",".tools",".top",".toray",".toshiba",".total",".tours",".town",".toyota",".toys",".trade",".trading",".training",".travel",".travelchannel",".travelers",".travelersinsurance",".trust",".trv",".tube",".tui",".tunes",".tushu",".tvs",".ubank",".ubs",".uconnect",".university",".uno",".uol",".ups",".us",".vacations",".vana",".vanguard",".vegas",".ventures",".verisign",".versicherung",".vet",".viajes",".video",".vig",".viking",".villas",".vin",".vip",".virgin",".visa",".vision",".vistaprint",".viva",".vivo",".vlaanderen",".vodka",".volkswagen",".volvo",".vote",".voting",".voto",".voyage",".vuelos",".wales",".walmart",".walter",".wang",".wanggou",".warman",".watch",".watches",".weather",".weatherchannel",".webcam",".weber",".website",".wed",".wedding",".weibo",".whoswho",".wien",".wiki",".williamhill",".win",".wine",".winners",".wme",".wolterskluwer",".woodside",".work",".works",".world",".wow",".wtc",".wtf",".xerox",".xfinity",".xihuan",".xin",".xxx",".xyz",".yachts",".yamaxun",".yodobashi",".yoga",".yokohama",".you",".youtube",".yun",".zappos",".zara",".zero",".zip",".zone",".zuerich",".xn--1qqw23a",".xn--30rr7y",".xn--3bst00m",".xn--3ds443g",".xn--3pxu8k",".xn--55qw42g",".xn--55qx5d",".xn--5tzm5g",".xn--6frz82g",".xn--9et52u",".xn--9krt00a",".xn--czrs0t",".xn--czru2d",".xn--efvy88h",".xn--estv75g",".xn--fct429k",".xn--fiq64b",".xn--fjq720a",".xn--flw351e",".xn--g2xx48c",".xn--hxt814e",".xn--io0a7i",".xn--jvr189m",".xn--kput3i",".xn--mxtq1m",".xn--nqv7f",".xn--nyqy26a",".xn--pbt977c",".xn--pssy2u",".xn--rhqv96g",".xn--rovu88b",".xn--unup4y",".xn--vhquv",".xn--vuq861b",".xn--w4rs40l",".xn--xhq521b",".xn--zfr164b",".xn--6qq986b3xl",".xn--b4w605ferd",".xn--fiq228c5hs",".xn--jlq61u9w7b",".xn--kcrx77d1x4a",".xn--3oq18vl8pn36a",".xn--5su34j936bgsg",".xn--fzys8d69uvgm",".xn--nqv7fs00ema",".xn--w4r85el8fhu5dnra",".xn--11b4c3d",".xn--c2br7g",".xn--42c2d9a",".xn--i1b6b1a6a2e",".xn--4gbrim",".xn--fhbei",".xn--mgba3a3ejt",".xn--mgba7c0bbn0a",".xn--mgbaakc7dvf",".xn--mgbab2bd",".xn--mgbt3dhd",".xn--ngbc5azd",".xn--ngbe9e0a",".xn--ngbrx",".xn--node",".xn--y9a3aq",".xn--80adxhks",".xn--80asehdb",".xn--80aswg",".xn--d1acj3b",".xn--d1alf",".xn--j1aef",".xn--9dbq2a",".xn--c1avg",".xn--p1acf",".xn--vermgensberater-ctb",".xn--vermgensberatung-pwb",".xn--bck1b9a5dre4c",".xn--cck2b3b",".xn--eckvdtc9d",".xn--gckr3f0f",".xn--q9jyb4c",".xn--qcka1pmc",".xn--tckwe",".xn--mk1bu44c",".xn--cg4bki",".a.se",".ab.ca",".ac",".ac.cn",".ac.cr",".ac.id",".ac.il",".ac.in",".ac.jp",".ac.mu",".ac.mw",".ac.rs",".ac.rw",".ac.tz",".ac.ug",".ac.uk",".ac.za",".ac.zm",".act.edu.au",".act.gov.au",".ad",".ad.jp",".adm.br",".adv.br",".ae",".af",".ag",".agr.br",".ai",".aichi.jp",".akita.jp",".al",".am",".am.br",".ao",".aomori.jp",".aq",".ar",".arq.br",".art.br",".as",".asso.fr",".at",".ath.cx",".au",".aw",".ax",".az",".ba",".bb",".bc.ca",".bd",".be",".bf",".bg",".bg.ac.rs",".bg.it",".bh",".bi",".bio.br",".biz.id",".biz.pl",".biz.pr",".biz.tr",".biz.ua",".bj",".bl",".blog.br",".bm",".bn",".bo",".bo.it",".bq",".br",".br.it",".brantford.on.ca",".bs",".bt",".bv",".bw",".by",".bydgoszcz.pl",".bz",".ca",".cc",".cd",".cf",".ch",".chiba.jp",".ci",".ck",".cl",".cm",".cn",".cnt.br",".co",".co.bw",".co.ci",".co.cm",".co.cr",".co.gy",".co.hu",".co.id",".co.il",".co.im",".co.in",".co.jp",".co.ke",".co.kr",".co.ma",".co.mu",".co.mw",".co.mz",".co.nl",".co.rs",".co.rw",".co.th",".co.tz",".co.ua",".co.ug",".co.uk",".co.za",".co.zm",".co.zw",".com.af",".com.ag",".com.ai",".com.ar",".com.au",".com.bo",".com.br",".com.cm",".com.cn",".com.co",".com.do",".com.dz",".com.ee",".com.fr",".com.ge",".com.gi",".com.gy",".com.hk",".com.hn",".com.hr",".com.ht",".com.im",".com.kg",".com.ky",".com.kz",".com.lc",".com.ly",".com.mg",".com.mk",".com.mx",".com.my",".com.ng",".com.pl",".com.pr",".com.ps",".com.pt",".com.ro",".com.sa",".com.sb",".com.sg",".com.so",".com.sy",".com.tn",".com.tr",".com.tw",".com.ua",".com.vc",".coop.br",".cr",".cu",".cv",".cw",".cx",".cy",".cz",".czest.pl",".de",".desa.id",".dj",".dk",".dm",".dn.ua",".do",".dp.ua",".dz",".ec",".ed.cr",".ed.jp",".edu.af",".edu.au",".edu.bi",".edu.bo",".edu.br",".edu.co",".edu.dm",".edu.do",".edu.dz",".edu.ge",".edu.hk",".edu.hn",".edu.ht",".edu.in",".edu.ky",".edu.kz",".edu.lr",".edu.ly",".edu.mg",".edu.mx",".edu.my",".edu.ng",".edu.pl",".edu.pr",".edu.ps",".edu.pt",".edu.sa",".edu.sb",".edu.sg",".edu.ua",".edu.uy",".ee",".eg",".ehime.jp",".eng.br",".ens.tn",".er",".es",".esp.br",".et",".eti.br",".far.br",".fhsk.se",".fi",".fi.cr",".fi.it",".fj",".fj.cn",".fk",".fm",".fm.br",".fo",".fr",".from.hr",".fukui.jp",".fukuoka.jp",".fukushima.jp",".g12.br",".ga",".gb",".gd",".gd.cn",".gda.pl",".ge",".gen.in",".gen.tr",".gf",".gg",".gh",".gi",".gifu.jp",".gl",".gm",".gn",".go.cr",".go.id",".go.jp",".go.th",".go.tz",".go.ug",".gob.hn",".gob.mx",".gouv.ci",".gouv.fr",".gouv.ht",".gov.af",".gov.ag",".gov.ar",".gov.au",".gov.br",".gov.by",".gov.co",".gov.cx",".gov.dm",".gov.dz",".gov.ge",".gov.gi",".gov.hk",".gov.ie",".gov.il",".gov.in",".gov.it",".gov.ky",".gov.kz",".gov.lc",".gov.ma",".gov.mg",".gov.mw",".gov.my",".gov.ng",".gov.pl",".gov.pr",".gov.ps",".gov.pt",".gov.rw",".gov.sa",".gov.sb",".gov.sc",".gov.sg",".gov.sy",".gov.tn",".gov.ua",".gov.uk",".gov.zm",".gp",".gq",".gr",".gr.jp",".gs",".gt",".gu",".gub.uy",".gunma.jp",".gw",".gy",".hiroshima.jp",".hk",".hm",".hn",".hokkaido.jp",".hr",".ht",".hu",".hyogo.jp",".ibaraki.jp",".id",".id.au",".id.lv",".idv.hk",".idv.tw",".ie",".il",".im",".imb.br",".in",".in.th",".ind.br",".ind.in",".inf.br",".info.ke",".info.pl",".info.ro",".info.tn",".info.tr",".io",".iq",".ir",".is",".isla.pr",".it",".iwate.jp",".je",".jm",".jo",".jor.br",".jp",".jus.br",".kagoshima.jp",".kalisz.pl",".kanagawa.jp",".katowice.pl",".ke",".kg",".kh",".ki",".kiev.ua",".km",".kn",".kommune.no",".koriyama.fukushima.jp",".kp",".kr",".krakow.pl",".kuleuven.be",".kumamoto.jp",".kw",".ky",".kyoto.jp",".kz",".la",".lb",".lc",".leg.br",".lel.br",".lg.jp",".li",".lk",".lm.lt",".lodz.pl",".longueuil.qc.ca",".lr",".ls",".lt",".ltd.gi",".ltd.uk",".lu",".lv",".ly",".ma",".malopolska.pl",".mb.ca",".mc",".md",".me",".me.uk",".med.br",".med.sa",".media.pl",".mf",".mg",".mh",".mie.jp",".mil.ar",".mil.br",".mil.by",".mil.co",".mil.hn",".mil.pl",".mil.uy",".miyagi.jp",".miyazaki.jp",".mk",".mn",".mo",".mp",".mq",".mr",".ms",".msk.ru",".mt",".mu",".mus.br",".mv",".mw",".mx",".my",".my.id",".mz",".na",".nagano.jp",".nagasaki.jp",".nara.jp",".nat.tn",".nb.ca",".nc",".ne",".ne.jp",".ne.kr",".net.ae",".net.al",".net.ar",".net.au",".net.bo",".net.br",".net.cn",".net.co",".net.do",".net.ge",".net.gy",".net.hk",".net.il",".net.in",".net.kg",".net.lr",".net.ly",".net.ma",".net.mu",".net.mx",".net.nf",".net.ng",".net.pl",".net.pr",".net.rw",".net.sa",".net.sb",".net.sg",".net.so",".net.sy",".net.tn",".net.tr",".net.tw",".net.ua",".net.uk",".net.uy",".net.za",".nf",".nf.ca",".ng",".ni",".nic.in",".niigata.jp",".nl",".nl.ca",".no",".nom.br",".nom.co",".not.br",".np",".nr",".ns.ca",".nsw.edu.au",".nsw.gov.au",".nt.ca",".nt.edu.au",".nu",".nysa.pl",".nz",".off.ai",".oita.jp",".okayama.jp",".okinawa.jp",".olsztyn.pl",".om",".on.ca",".or.cr",".or.id",".or.jp",".or.ke",".or.kr",".or.tz",".or.ug",".org.af",".org.ar",".org.au",".org.br",".org.bw",".org.bz",".org.cn",".org.co",".org.do",".org.dz",".org.ge",".org.gg",".org.hk",".org.hn",".org.ht",".org.il",".org.im",".org.in",".org.kg",".org.ky",".org.kz",".org.lb",".org.ly",".org.ma",".org.mk",".org.mw",".org.mx",".org.my",".org.mz",".org.ng",".org.pl",".org.ps",".org.ro",".org.rs",".org.sa",".org.sb",".org.sg",".org.so",".org.tn",".org.ua",".org.ug",".org.uk",".org.uy",".org.za",".org.zm",".osaka.jp",".oslo.no",".pa",".pe",".pe.ca",".pe.kr",".pf",".pg",".ph",".pi.it",".pila.pl",".pk",".pl",".plc.uk",".pm",".pn",".poznan.pl",".pp.ru",".pp.se",".pp.ua",".ppg.br",".pr",".pr.it",".prd.fr",".pri.ee",".pro.br",".ps",".pt",".pub.sa",".pvt.ge",".pw",".py",".qa",".qc.ca",".qld.edu.au",".qld.gov.au",".radom.pl",".re",".re.it",".res.in",".rm.it",".ro",".roma.it",".rs",".ru",".rw",".rzeszow.pl",".sa",".sa.cr",".sa.edu.au",".sa.gov.au",".saitama.jp",".saskatoon.sk.ca",".sb",".sc",".sc.cn",".sch.uk",".sd",".se",".seoul.kr",".sg",".sh",".sh.cn",".shiga.jp",".shimane.jp",".shizuoka.jp",".si",".sj",".sk",".sk.ca",".sl",".sld.do",".sm",".sm.ua",".sn",".so",".sr",".srv.br",".ss",".st",".store.ro",".su",".suginami.tokyo.jp",".sv",".sx",".sx.cn",".sy",".sz",".szczecin.pl",".tas.edu.au",".tc",".td",".telenet.be",".tf",".tg",".th",".tj",".tk",".tl",".tm",".tm.fr",".tmp.br",".tn",".tn.it",".to",".to.it",".tokushima.jp",".tokyo.jp",".torun.pl",".tottori.jp",".toyama.jp",".tr",".trd.br",".tt",".tur.br",".tv",".tv.br",".tw",".tz",".ua",".ug",".uk",".us",".uy",".uz",".vc",".ve",".vet.br",".vg",".vgs.no",".vi",".vic.edu.au",".vic.gov.au",".vn",".volyn.ua",".vu",".wa.edu.au",".wa.gov.au",".wakayama.jp",".warszawa.pl",".waw.pl",".web.do",".web.id",".web.tr",".web.za",".wf",".wroc.pl",".ws",".yamagata.jp",".yamaguchi.jp",".yamanashi.jp",".ye",".yk.ca",".yokohama.jp",".yt",".za",".zgora.pl",".zm",".zw",".xn--80ao21a",".xn--j1amh",".xn--90ais",".xn--h2brj9c",".xn--fiqs8s",".xn--j6w193g"]
43
+
44
+ if url[0..3] != "http"
45
+ url = 'https://' + url
46
+ end
47
+
48
+ if url =~ URI::regexp
49
+ host = URI.parse(url).host
50
+ cnt = host.count('.')
51
+ while cnt > 0
52
+ dotln = host.index('.')
53
+ domn = host[dotln,host.length]
54
+ if tlds.include?(domn)
55
+ return host
56
+ end
57
+ cnt -= 1
58
+ host = domn[1,domn.length]
59
+ end
60
+ return 'DOMAIN NOT FOUND'
61
+ else
62
+ return 'DOMAIN NOT FOUND'
63
+ end
64
+ end
65
+
66
+ # Get domain extension from a URL/domain.
67
+ def self.get_domain_extension(str)
68
+ domain = get_domain_name(str)
69
+ return domain[(domain.index("."))..(domain.length)]
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,31 @@
1
+ require 'uri'
2
+ require 'json'
3
+ require 'net/http'
4
+ require "ip2location_io_ruby/configuration"
5
+ require "ip2location_io_ruby/version"
6
+
7
+ module IP2LocationIORuby
8
+ module Api
9
+ class IPGeolocation
10
+
11
+ # Lookup given IP address for an enriched data set.
12
+ def self.lookup(ip, language = '')
13
+ uri = URI.parse("https://api.ip2location.io/?key=" + IP2LocationIORuby::Configuration.api_key + "&format=json&ip=" + ip + "&lang=" + language + "&source=sdk-ruby-iplio&source_version=" + IP2LocationIORuby::VERSION)
14
+ http = Net::HTTP.new(uri.host, uri.port)
15
+ http.use_ssl = true
16
+ request = Net::HTTP::Get.new(uri.request_uri)
17
+
18
+ response = http.request(request)
19
+
20
+ if response == nil
21
+ raise Exception.new "IPGeolocation lookup error."
22
+ elsif JSON[response.body]['error']
23
+ raise Exception.new JSON[response.body]['error']['error_message']
24
+ else
25
+ return response
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ module IP2LocationIORuby
2
+ module Api
3
+ end
4
+ end
@@ -0,0 +1,9 @@
1
+ module IP2LocationIORuby
2
+ class Configuration
3
+ @api_key = ''
4
+
5
+ class << self
6
+ attr_accessor :api_key
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module IP2LocationIORuby
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "ip2location_io_ruby/api"
2
+ require "ip2location_io_ruby/api/ipgeolocation"
3
+ require "ip2location_io_ruby/api/domainwhois"
4
+ require "ip2location_io_ruby/configuration"
5
+ require "ip2location_io_ruby/version"
6
+
7
+ module IP2LocationIORuby
8
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "IP2LocationIORuby" do
4
+ it "work correctly with invalid Api Key" do
5
+ IP2LocationIORuby::Configuration.api_key = ''
6
+ begin
7
+ IP2LocationIORuby::Api::DomainWhois.lookup('example.c')
8
+ rescue Exception => e
9
+ expect(e.message).to eq 'Missing parameter.'
10
+ end
11
+ end
12
+
13
+ it "work correctly with Api Key exist" do
14
+ if $test_api_key == 'YOUR_API_KEY'
15
+ print "/*
16
+ * You could enter a FraudLabs Pro API Key in spec/spec_helper.rb
17
+ * for real web service calling test.
18
+ *
19
+ * You could sign up for a free API key at https://www.fraudlabspro.com/pricing
20
+ * if you do not have one.
21
+ */"
22
+ expect($test_api_key).to eq 'YOUR_API_KEY'
23
+ else
24
+ expect($test_api_key).to_not eq 'YOUR_API_KEY'
25
+ end
26
+ end
27
+
28
+ it "work correctly with lookup domain" do
29
+ IP2LocationIORuby::Configuration.api_key = $test_api_key
30
+ if $test_api_key == 'YOUR_API_KEY'
31
+ begin
32
+ IP2LocationIORuby::Api::DomainWhois.lookup('example.c')
33
+ rescue Exception => e
34
+ expect(e.message).to eq 'API key not found.'
35
+ end
36
+ else
37
+ begin
38
+ result = IP2LocationIORuby::Api::DomainWhois.lookup('example.c')
39
+ rescue Exception => e
40
+ expect(e.message).to eq 'Invalid domain.'
41
+ end
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "IP2LocationIORuby" do
4
+ it "work correctly with invalid Api Key" do
5
+ IP2LocationIORuby::Configuration.api_key = ''
6
+ begin
7
+ IP2LocationIORuby::Api::IPGeolocation.lookup('8.8.8.8')
8
+ rescue Exception => e
9
+ expect(e.message).to eq 'Invalid API key or insufficient credit.'
10
+ end
11
+ end
12
+
13
+ it "work correctly with Api Key exist" do
14
+ if $test_api_key == 'YOUR_API_KEY'
15
+ print "/*
16
+ * You could enter a FraudLabs Pro API Key in spec/spec_helper.rb
17
+ * for real web service calling test.
18
+ *
19
+ * You could sign up for a free API key at https://www.fraudlabspro.com/pricing
20
+ * if you do not have one.
21
+ */"
22
+ expect($test_api_key).to eq 'YOUR_API_KEY'
23
+ else
24
+ expect($test_api_key).to_not eq 'YOUR_API_KEY'
25
+ end
26
+ end
27
+
28
+ it "work correctly with lookup IP" do
29
+ IP2LocationIORuby::Configuration.api_key = $test_api_key
30
+ if $test_api_key == 'YOUR_API_KEY'
31
+ begin
32
+ IP2LocationIORuby::Api::IPGeolocation.lookup('8.8.8.8')
33
+ rescue Exception => e
34
+ expect(e.message).to eq 'Invalid API key or insufficient credit.'
35
+ end
36
+ else
37
+ result = IP2LocationIORuby::Api::IPGeolocation.lookup('8.8.8.8')
38
+ expect(JSON[result.body]['country_code']).to eq 'US'
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'ip2location_io_ruby'
5
+ require 'json'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+
13
+ end
14
+
15
+ $test_api_key = 'YOUR_API_KEY'
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ip2location_io_ruby
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: 2023-04-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: IP2Location.IO Ruby SDK allows user to query for an enriched data set
14
+ based on IP address and provides WHOIS lookup api that helps users to obtain domain
15
+ information.
16
+ email:
17
+ - support@ip2location.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files:
21
+ - LICENSE.txt
22
+ - README.md
23
+ files:
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - example.rb
30
+ - ip2location_io_ruby.gemspec
31
+ - lib/ip2location_io_ruby.rb
32
+ - lib/ip2location_io_ruby/api.rb
33
+ - lib/ip2location_io_ruby/api/domainwhois.rb
34
+ - lib/ip2location_io_ruby/api/ipgeolocation.rb
35
+ - lib/ip2location_io_ruby/configuration.rb
36
+ - lib/ip2location_io_ruby/version.rb
37
+ - spec/ip2location_io_ruby_domainwhois_spec.rb
38
+ - spec/ip2location_io_ruby_ipgeolocation_spec.rb
39
+ - spec/spec_helper.rb
40
+ homepage: https://github.com/ip2location/ip2location-io-ruby
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.3.7
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: IP2Location IO Ruby SDK
63
+ test_files: []