IPinfo 1.0.1 → 2.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/cd_rubygems.yaml +37 -0
- data/.github/workflows/unittest.yaml +35 -0
- data/.rubocop.yml +6 -0
- data/.ruby-version +1 -1
- data/README.md +88 -20
- data/ipinfo.gemspec +8 -10
- data/lib/ipinfo/adapter.rb +15 -5
- data/lib/ipinfo/countriesData.rb +1045 -0
- data/lib/ipinfo/ipAddressMatcher.rb +92 -0
- data/lib/ipinfo/version.rb +1 -1
- data/lib/ipinfo.rb +123 -32
- metadata +92 -6
- data/.travis.yml +0 -11
- data/lib/ipinfo/countries.json +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea1d36760a8a4b60cdc8f48946859ba2cf05d71d7f2c7efe11c7333563a9cb8e
|
4
|
+
data.tar.gz: 49fef88c8e2df4c69006ef76b9d7ad86028dc0cc621e4cb4d529cad060f9802f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1465262219a3a9d5a30d387f63fee35721bd667555eff9b6b25d131b1d58093a70087bf51bf6842bf22331573ef796e7a8ad3689539882976783f18e2233b244
|
7
|
+
data.tar.gz: 97456bb0d405e97448bdb1f6b897914a1aebd749b8f348457e5447630e36a17d420e3e35e04eef565eef946cc4a90475e7c483b366ccd88a8f5d680201e0c1a3
|
@@ -0,0 +1,37 @@
|
|
1
|
+
name: Release package to rubygems.org
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags:
|
6
|
+
- 'v*'
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
publish:
|
10
|
+
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- name: Checkout
|
15
|
+
uses: actions/checkout@v3
|
16
|
+
|
17
|
+
- name: Install apt dependencies
|
18
|
+
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev # needed by faraday-patron gem
|
19
|
+
|
20
|
+
- name: Set up Ruby
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
|
23
|
+
- name: Install dependencies
|
24
|
+
run: bundle install
|
25
|
+
|
26
|
+
- name: Run tests
|
27
|
+
run: bundle exec rake
|
28
|
+
env:
|
29
|
+
IPINFO_TOKEN: ${{ secrets.IPINFO_TOKEN }}
|
30
|
+
|
31
|
+
- name: Build
|
32
|
+
run: gem build *.gemspec
|
33
|
+
|
34
|
+
- name: Publish
|
35
|
+
run: gem push *.gem
|
36
|
+
env:
|
37
|
+
GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
name: Unit Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
|
6
|
+
permissions:
|
7
|
+
contents: read
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
run:
|
11
|
+
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
ruby-version: ['3.2', '3.1', '3.0', '2.7', '2.6']
|
16
|
+
|
17
|
+
steps:
|
18
|
+
- name: Checkout
|
19
|
+
uses: actions/checkout@v3
|
20
|
+
|
21
|
+
- name: Install apt dependencies
|
22
|
+
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev # needed by faraday-patron gem
|
23
|
+
|
24
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
25
|
+
uses: ruby/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: ${{ matrix.ruby-version }}
|
28
|
+
|
29
|
+
- name: Install dependencies
|
30
|
+
run: bundle install
|
31
|
+
|
32
|
+
- name: Run tests
|
33
|
+
env:
|
34
|
+
IPINFO_TOKEN: ${{ secrets.IPINFO_TOKEN }}
|
35
|
+
run: bundle exec rake
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
3.2.2
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# [<img src="https://ipinfo.io/static/ipinfo-small.svg" alt="IPinfo" width="24"/>](https://ipinfo.io/) IPinfo Ruby Client Library
|
2
2
|
|
3
|
-
This is the official Ruby client library for the [IPinfo.io](https://ipinfo.io) IP address API, allowing you to
|
4
|
-
- [IP geolocation data](https://ipinfo.io/ip-geolocation-api) (city, region, country, postal code, latitude and longitude)
|
5
|
-
- [ASN information](https://ipinfo.io/asn-api) (ISP or network operator, associated domain name, and type, such as business, hosting or company)
|
3
|
+
This is the official Ruby client library for the [IPinfo.io](https://ipinfo.io) IP address API, allowing you to look up your own IP address, or get any of the following details for an IP:
|
4
|
+
- [IP geolocation data](https://ipinfo.io/ip-geolocation-api) (city, region, country, postal code, latitude, and longitude)
|
5
|
+
- [ASN information](https://ipinfo.io/asn-api) (ISP or network operator, associated domain name, and type, such as business, hosting, or company)
|
6
6
|
- [Firmographic data](https://ipinfo.io/ip-company-api) (the name and domain of the business that uses the IP address)
|
7
7
|
- [Carrier details](https://ipinfo.io/ip-carrier-api) (the name of the mobile carrier and MNC and MCC for that carrier if the IP is used exclusively for mobile traffic)
|
8
8
|
|
@@ -10,7 +10,7 @@ Check all the data we have for your IP address [here](https://ipinfo.io/what-is-
|
|
10
10
|
|
11
11
|
### Getting Started
|
12
12
|
|
13
|
-
You'll need an IPinfo API access token, which you can get by
|
13
|
+
You'll need an IPinfo API access token, which you can get by signing up for a free account at [https://ipinfo.io/signup](https://ipinfo.io/signup).
|
14
14
|
|
15
15
|
The free plan is limited to 50,000 requests per month, and doesn't include some of the data fields such as IP type and company data. To enable all the data fields and additional request volumes see [https://ipinfo.io/pricing](https://ipinfo.io/pricing)
|
16
16
|
|
@@ -33,30 +33,44 @@ Or install it yourself as:
|
|
33
33
|
#### Quick Start
|
34
34
|
|
35
35
|
```ruby
|
36
|
-
require '
|
36
|
+
require 'ipinfo'
|
37
37
|
|
38
38
|
access_token = '123456789abc'
|
39
39
|
handler = IPinfo::create(access_token)
|
40
40
|
ip_address = '216.239.36.21'
|
41
41
|
|
42
42
|
details = handler.details(ip_address)
|
43
|
+
details_v6 = handler.details_v6() # to get details from ipinfo's IPv6 host
|
43
44
|
city = details.city # Emeryville
|
44
45
|
loc = details.loc # 37.8342,-122.2900
|
45
46
|
```
|
46
47
|
|
48
|
+
##### Note about Rails 6+
|
49
|
+
|
50
|
+
If using this package in Rails 6+, the Zeitwerk auto-loader may not properly
|
51
|
+
recognize the gem due to its naming conventions (uppercased gem/module name).
|
52
|
+
See issue https://github.com/ipinfo/ruby/issues/24.
|
53
|
+
|
54
|
+
A workaround is to insert this in `application.rb`:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
require 'ipinfo' unless defined?(IPinfo)
|
58
|
+
```
|
59
|
+
|
47
60
|
#### Usage
|
48
61
|
|
49
|
-
The `IPinfo.details()`
|
62
|
+
The `IPinfo.details()` and `IPinfo.details_v6()` methods accept an IP address as an optional, positional
|
50
63
|
argument. If no IP address is specified, the API will return data for the IP
|
51
64
|
address from which it receives the request.
|
52
65
|
|
53
66
|
```ruby
|
54
|
-
require '
|
67
|
+
require 'ipinfo'
|
55
68
|
|
56
69
|
access_token = '123456789abc'
|
57
70
|
handler = IPinfo::create(access_token)
|
58
71
|
|
59
72
|
details = handler.details()
|
73
|
+
details_v6 = handler.details_v6() # to get details from ipinfo's IPv6 host
|
60
74
|
city = details.city # "Emeryville"
|
61
75
|
loc = details.loc # 37.8342,-122.2900
|
62
76
|
```
|
@@ -74,7 +88,7 @@ handler = IPinfo::create(access_token)
|
|
74
88
|
|
75
89
|
#### Details Data
|
76
90
|
|
77
|
-
`handler.details()` will return a `Response` object that contains all fields
|
91
|
+
`handler.details()` and `handler.details_v6` will return a `Response` object that contains all fields
|
78
92
|
listed in the [IPinfo developerdocs](https://ipinfo.io/developers/responses#full-response)
|
79
93
|
with a few minor additions. Properties can be accessed directly.
|
80
94
|
|
@@ -84,18 +98,74 @@ hostname = details.hostname # cpe-104-175-221-247.socal.res.rr.com
|
|
84
98
|
|
85
99
|
##### Country Name
|
86
100
|
|
87
|
-
`details.country_name` will return the country name, as
|
88
|
-
`
|
89
|
-
with non-English languages. `details.country` will still return country code.
|
101
|
+
`details.country_name` will return the country name, as defined by `DEFAULT_COUNTRY_LIST`
|
102
|
+
within `countriesData.rb`. See below for instructions on changing that file for use
|
103
|
+
with non-English languages. `details.country` will still return the country code.
|
90
104
|
|
91
105
|
```ruby
|
92
106
|
country = details.country # US
|
93
107
|
country_name = details.country_name # United States
|
94
108
|
```
|
95
109
|
|
110
|
+
##### European Union (EU) Country
|
111
|
+
|
112
|
+
`details.is_eu` will return `true` if the country is a member of the European Union (EU)
|
113
|
+
, as defined by `DEFAULT_EU_COUNTRIES_LIST` within `countriesData.rb`.
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
is_eu = details.is_eu # false
|
117
|
+
```
|
118
|
+
|
119
|
+
It is possible to change the file by setting the `eu_countries` setting when creating the `IPinfo` object.
|
120
|
+
|
121
|
+
##### Country Flag
|
122
|
+
|
123
|
+
`details.country_flag` will return `emoji` and `unicode` of a country's flag, as defined by
|
124
|
+
`DEFAULT_COUNTRIES_FLAG_LIST` within `countriesData.rb`.
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
country_flag = details.country_flag # {"emoji"=>"🇺🇸", "unicode"=>"U+1F1FA U+1F1F8"}
|
128
|
+
country_flag_emoji = details.country_flag['emoji'] # 🇺🇸
|
129
|
+
country_flag_unicode = details.country_flag['unicode'] # U+1F1FA U+1F1F8
|
130
|
+
```
|
131
|
+
|
132
|
+
##### Country Flag URL
|
133
|
+
|
134
|
+
`details.country_flag_url` will return a public link to the country's flag image as an SVG which can be used anywhere.
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
country_flag = details.country_flag_url # {"https://cdn.ipinfo.io/static/images/countries-flags/US.svg"}
|
138
|
+
```
|
139
|
+
|
140
|
+
##### Country Currency
|
141
|
+
|
142
|
+
`details.country_currency` will return `code` and `symbol` of a country's currency, as defined by
|
143
|
+
`DEFAULT_COUNTRIES_CURRENCIES_LIST` within `countriesData.rb`.
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
country_currency = details.country_currency # {"code"=>"USD", "symbol"=>"$"}
|
147
|
+
country_currency_code = details.country_currency['code'] # USD
|
148
|
+
country_currency_symbol = details.country_currency['symbol'] # $
|
149
|
+
```
|
150
|
+
|
151
|
+
It is possible to change the file by setting the `countries_currencies` setting when creating the `IPinfo` object.
|
152
|
+
|
153
|
+
##### Continent
|
154
|
+
|
155
|
+
`details.continent` will return `code` and `name` of the continent, as defined by
|
156
|
+
`DEFAULT_CONTINENT_LIST` within `countriesData.rb`.
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
continent = details.continent # {"code"=>"NA", "name"=>"North America"}
|
160
|
+
continent_code = details.continent['code'] # NA
|
161
|
+
continent_name = details.continent['name'] # North America
|
162
|
+
```
|
163
|
+
|
164
|
+
It is possible to change the file by setting the `continents` setting when creating the `IPinfo` object.
|
165
|
+
|
96
166
|
#### IP Address
|
97
167
|
|
98
|
-
`details.ip_address` will return the
|
168
|
+
`details.ip_address` will return the `IPAddr` object from the
|
99
169
|
[Ruby Standard Library](https://ruby-doc.org/stdlib-2.5.1/libdoc/ipaddr/rdoc/IPAddr.html).
|
100
170
|
`details.ip` will still return a string.
|
101
171
|
|
@@ -203,24 +273,22 @@ When looking up an IP address, the response object includes a
|
|
203
273
|
American English. It is possible to return the country name in other languages
|
204
274
|
by setting the `countries` setting when creating the `IPinfo` object.
|
205
275
|
|
206
|
-
The file must be a `.json` file with the following structure:
|
207
|
-
|
208
276
|
```
|
209
277
|
{
|
210
|
-
"BD"
|
211
|
-
"BE"
|
212
|
-
"BF"
|
213
|
-
"BG"
|
278
|
+
"BD" => "Bangladesh",
|
279
|
+
"BE" => "Belgium",
|
280
|
+
"BF" => "Burkina Faso",
|
281
|
+
"BG" => "Bulgaria"
|
214
282
|
...
|
215
283
|
}
|
216
284
|
```
|
217
285
|
|
218
286
|
### Other Libraries
|
219
287
|
|
220
|
-
There are official IPinfo client libraries available for many languages including PHP, Go, Java, Ruby, and many popular frameworks such as Django, Rails and Laravel. There are also many third
|
288
|
+
There are official IPinfo client libraries available for many languages including PHP, Go, Java, Ruby, and many popular frameworks such as Django, Rails, and Laravel. There are also many third-party libraries and integrations available for our API.
|
221
289
|
|
222
290
|
### About IPinfo
|
223
291
|
|
224
|
-
Founded in 2013, IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier,
|
292
|
+
Founded in 2013, IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier, VPN detection, hosted domains, and IP type data sets. Our API handles over 40 billion requests a month for 100,000 businesses and developers.
|
225
293
|
|
226
294
|
[![image](https://avatars3.githubusercontent.com/u/15721521?s=128&u=7bb7dde5c4991335fb234e68a30971944abc6bf3&v=4)](https://ipinfo.io/)
|
data/ipinfo.gemspec
CHANGED
@@ -16,17 +16,15 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.description = ' This is a ruby wrapper for http://ipinfo.io. '
|
17
17
|
spec.homepage = 'https://ipinfo.io'
|
18
18
|
|
19
|
-
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
19
|
+
spec.add_runtime_dependency 'faraday', '~> 2.0'
|
20
|
+
# add development dependency to test against faraday adapters that are been moved out the gem
|
21
|
+
spec.add_development_dependency 'async-http-faraday'
|
22
|
+
spec.add_development_dependency 'faraday-net_http_persistent', '~> 2.0'
|
23
|
+
spec.add_development_dependency 'faraday-typhoeus', '~> 1.0'
|
24
|
+
spec.add_development_dependency 'faraday-patron', '~> 2.0'
|
25
|
+
spec.add_development_dependency 'faraday-httpclient', '~> 2.0'
|
26
|
+
spec.add_development_dependency 'faraday-excon', '~> 2.1'
|
28
27
|
|
29
|
-
spec.add_runtime_dependency 'faraday', '~> 1.0'
|
30
28
|
spec.add_runtime_dependency 'json', '~> 2.1'
|
31
29
|
spec.add_runtime_dependency 'lru_redux', '~> 1.1'
|
32
30
|
|
data/lib/ipinfo/adapter.rb
CHANGED
@@ -3,9 +3,11 @@
|
|
3
3
|
require 'faraday'
|
4
4
|
require 'cgi'
|
5
5
|
require 'ipinfo/mod'
|
6
|
+
require_relative './version.rb'
|
6
7
|
|
7
8
|
class IPinfo::Adapter
|
8
|
-
HOST = 'ipinfo.io'
|
9
|
+
HOST = 'https://ipinfo.io'
|
10
|
+
HOST_V6 = 'https://v6.ipinfo.io'
|
9
11
|
|
10
12
|
attr_reader :conn
|
11
13
|
|
@@ -14,8 +16,9 @@ class IPinfo::Adapter
|
|
14
16
|
@conn = connection(adapter)
|
15
17
|
end
|
16
18
|
|
17
|
-
def get(uri)
|
18
|
-
|
19
|
+
def get(uri, host_type= :v4)
|
20
|
+
host = (host_type == :v6) ? HOST_V6 : HOST
|
21
|
+
@conn.get(host + uri) do |req|
|
19
22
|
default_headers.each_pair do |key, value|
|
20
23
|
req.headers[key] = value
|
21
24
|
end
|
@@ -23,19 +26,26 @@ class IPinfo::Adapter
|
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
29
|
+
def post(uri, body, timeout = 2)
|
30
|
+
@conn.post(HOST + uri) do |req|
|
31
|
+
req.body = body
|
32
|
+
req.options.timeout = timeout
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
26
36
|
private
|
27
37
|
|
28
38
|
attr_reader :token
|
29
39
|
|
30
40
|
def connection(adapter)
|
31
|
-
Faraday.new(
|
41
|
+
Faraday.new() do |conn|
|
32
42
|
conn.adapter(adapter)
|
33
43
|
end
|
34
44
|
end
|
35
45
|
|
36
46
|
def default_headers
|
37
47
|
headers = {
|
38
|
-
'User-Agent' =>
|
48
|
+
'User-Agent' => "IPinfoClient/Ruby/#{IPinfo::VERSION}",
|
39
49
|
'Accept' => 'application/json'
|
40
50
|
}
|
41
51
|
headers['Authorization'] = "Bearer #{CGI.escape(token)}" if token
|