IPinfo 2.2.4 → 2.3.1
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 +4 -4
- data/.github/workflows/cd_rubygems.yaml +6 -6
- data/.github/workflows/unittest.yaml +6 -1
- data/README.md +19 -0
- data/ipinfo.gemspec +2 -2
- data/lib/ipinfo/adapter.rb +39 -0
- data/lib/ipinfo/mod.rb +3 -0
- data/lib/ipinfo/version.rb +1 -1
- data/lib/ipinfo.rb +1 -0
- data/lib/ipinfo_lite.rb +116 -0
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d123a1cdf07b3693cc28ea77d42da4d9984cbdc8676ab235c5a837d8cfb2d272
|
4
|
+
data.tar.gz: e322a8feefc0bb770b0318ecb66967c0ab50e0171bf5ca5d1921deb4ab79bdd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18d5583c9b890e82dd229ee7138a7f956ed4ce8e32267cf0b0b2eb61417f85792963a83711e7756f572868cfbeefdf828460c9c547c27578d9d5d47bef909ecf
|
7
|
+
data.tar.gz: d404fa4474c572d6c0e1076ecd4c460224db7393ebb9e4c1344f73ecbe4b96d92fdcd0d4f7ce2d8b5f51372c85ad2859ca5cd3328cba1b0d2070808dd17f0cfa
|
@@ -3,13 +3,15 @@ name: Release package to rubygems.org
|
|
3
3
|
on:
|
4
4
|
push:
|
5
5
|
tags:
|
6
|
-
-
|
6
|
+
- "v*"
|
7
7
|
|
8
8
|
jobs:
|
9
9
|
publish:
|
10
|
-
|
11
10
|
runs-on: ubuntu-latest
|
12
11
|
|
12
|
+
permissions:
|
13
|
+
id-token: write
|
14
|
+
|
13
15
|
steps:
|
14
16
|
- name: Checkout
|
15
17
|
uses: actions/checkout@v3
|
@@ -25,13 +27,11 @@ jobs:
|
|
25
27
|
|
26
28
|
- name: Run tests
|
27
29
|
run: bundle exec rake
|
28
|
-
env:
|
30
|
+
env:
|
29
31
|
IPINFO_TOKEN: ${{ secrets.IPINFO_TOKEN }}
|
30
32
|
|
31
33
|
- name: Build
|
32
34
|
run: gem build *.gemspec
|
33
35
|
|
34
36
|
- name: Publish
|
35
|
-
|
36
|
-
env:
|
37
|
-
GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
|
37
|
+
uses: rubygems/release-gem@v1
|
@@ -1,7 +1,12 @@
|
|
1
1
|
name: Unit Tests
|
2
2
|
|
3
3
|
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
4
7
|
pull_request:
|
8
|
+
branches:
|
9
|
+
- master
|
5
10
|
|
6
11
|
permissions:
|
7
12
|
contents: read
|
@@ -12,7 +17,7 @@ jobs:
|
|
12
17
|
runs-on: ubuntu-latest
|
13
18
|
strategy:
|
14
19
|
matrix:
|
15
|
-
ruby-version: ['
|
20
|
+
ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4']
|
16
21
|
|
17
22
|
steps:
|
18
23
|
- name: Checkout
|
data/README.md
CHANGED
@@ -14,6 +14,8 @@ You'll need an IPinfo API access token, which you can get by signing up for a fr
|
|
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
|
|
17
|
+
The library also supports the Lite API, see the [Lite API section](#lite-api) for more info.
|
18
|
+
|
17
19
|
#### Installation
|
18
20
|
|
19
21
|
Add this line to your application's Gemfile:
|
@@ -215,6 +217,23 @@ details.all = {
|
|
215
217
|
}
|
216
218
|
```
|
217
219
|
|
220
|
+
### Lite API
|
221
|
+
|
222
|
+
The library gives the possibility to use the [Lite API](https://ipinfo.io/developers/lite-api) too, authentication with your token is still required.
|
223
|
+
|
224
|
+
The returned details are slightly different from the Core API.
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
require 'ipinfo_lite'
|
228
|
+
|
229
|
+
access_token = '123456789abc'
|
230
|
+
handler = IPinfoLite::create(access_token)
|
231
|
+
|
232
|
+
details = handler.details('8.8.8.8')
|
233
|
+
details.country_code # US
|
234
|
+
details.country # United States
|
235
|
+
```
|
236
|
+
|
218
237
|
#### Caching
|
219
238
|
|
220
239
|
In-memory caching of `details` data is provided by default via the
|
data/ipinfo.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.name = 'IPinfo'
|
10
10
|
spec.version = IPinfo::VERSION
|
11
11
|
spec.required_ruby_version = '>= 2.5.0'
|
12
|
-
spec.authors = ['
|
13
|
-
spec.email = ['
|
12
|
+
spec.authors = ['IPinfo releases']
|
13
|
+
spec.email = ['releases@ipinfo.io']
|
14
14
|
|
15
15
|
spec.summary = ' This is a ruby wrapper for http://ipinfo.io. '
|
16
16
|
spec.description = ' This is a ruby wrapper for http://ipinfo.io. '
|
data/lib/ipinfo/adapter.rb
CHANGED
@@ -52,3 +52,42 @@ class IPinfo::Adapter
|
|
52
52
|
headers
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
class IPinfo::AdapterLite
|
57
|
+
HOST = 'https://api.ipinfo.io/lite/'
|
58
|
+
|
59
|
+
attr_reader :conn
|
60
|
+
|
61
|
+
def initialize(token = nil, adapter = :net_http)
|
62
|
+
@token = token
|
63
|
+
@conn = connection(adapter)
|
64
|
+
end
|
65
|
+
|
66
|
+
def get(uri)
|
67
|
+
@conn.get(HOST + uri) do |req|
|
68
|
+
default_headers.each_pair do |key, value|
|
69
|
+
req.headers[key] = value
|
70
|
+
end
|
71
|
+
req.params['token'] = CGI.escape(token) if token
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
attr_reader :token
|
78
|
+
|
79
|
+
def connection(adapter)
|
80
|
+
Faraday.new() do |conn|
|
81
|
+
conn.adapter(adapter)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def default_headers
|
86
|
+
headers = {
|
87
|
+
'User-Agent' => "IPinfoClient/Ruby/#{IPinfo::VERSION}",
|
88
|
+
'Accept' => 'application/json'
|
89
|
+
}
|
90
|
+
headers['Authorization'] = "Bearer #{CGI.escape(token)}" if token
|
91
|
+
headers
|
92
|
+
end
|
93
|
+
end
|
data/lib/ipinfo/mod.rb
CHANGED
data/lib/ipinfo/version.rb
CHANGED
data/lib/ipinfo.rb
CHANGED
data/lib/ipinfo_lite.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ipinfo/adapter'
|
4
|
+
require 'ipinfo/cache/default_cache'
|
5
|
+
require 'ipinfo/errors'
|
6
|
+
require 'ipinfo/response'
|
7
|
+
require_relative 'ipinfo/ipAddressMatcher'
|
8
|
+
require_relative 'ipinfo/countriesData'
|
9
|
+
require 'ipaddr'
|
10
|
+
require 'cgi'
|
11
|
+
|
12
|
+
module IPinfoLite
|
13
|
+
include CountriesData
|
14
|
+
DEFAULT_CACHE_MAXSIZE = 4096
|
15
|
+
DEFAULT_CACHE_TTL = 60 * 60 * 24
|
16
|
+
RATE_LIMIT_MESSAGE = 'To increase your limits, please review our ' \
|
17
|
+
'paid plans at https://ipinfo.io/pricing'
|
18
|
+
# Base URL to get country flag image link.
|
19
|
+
# "PK" -> "https://cdn.ipinfo.io/static/images/countries-flags/PK.svg"
|
20
|
+
COUNTRY_FLAGS_URL = 'https://cdn.ipinfo.io/static/images/countries-flags/'
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def create(access_token = nil, settings = {})
|
24
|
+
IPinfo::IPinfoLite.new(access_token, settings)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class IPinfo::IPinfoLite
|
30
|
+
include IPinfoLite
|
31
|
+
attr_accessor :access_token, :countries, :httpc
|
32
|
+
|
33
|
+
def initialize(access_token = nil, settings = {})
|
34
|
+
@access_token = access_token
|
35
|
+
@httpc = IPinfo::AdapterLite.new(access_token, httpc || :net_http)
|
36
|
+
|
37
|
+
maxsize = settings.fetch('maxsize', DEFAULT_CACHE_MAXSIZE)
|
38
|
+
ttl = settings.fetch('ttl', DEFAULT_CACHE_TTL)
|
39
|
+
@cache = settings.fetch('cache', IPinfo::DefaultCache.new(ttl, maxsize))
|
40
|
+
@countries = settings.fetch('countries', DEFAULT_COUNTRY_LIST)
|
41
|
+
@eu_countries = settings.fetch('eu_countries', DEFAULT_EU_COUNTRIES_LIST)
|
42
|
+
@countries_flags = settings.fetch('countries_flags', DEFAULT_COUNTRIES_FLAG_LIST)
|
43
|
+
@countries_currencies = settings.fetch('countries_currencies', DEFAULT_COUNTRIES_CURRENCIES_LIST)
|
44
|
+
@continents = settings.fetch('continents', DEFAULT_CONTINENT_LIST)
|
45
|
+
end
|
46
|
+
|
47
|
+
def details(ip_address = nil)
|
48
|
+
details_base(ip_address)
|
49
|
+
end
|
50
|
+
|
51
|
+
def request_details(ip_address = nil)
|
52
|
+
if ip_address && ip_address != 'me' && isBogon(ip_address)
|
53
|
+
details[:ip] = ip_address
|
54
|
+
details[:bogon] = true
|
55
|
+
details[:ip_address] = IPAddr.new(ip_address)
|
56
|
+
|
57
|
+
return details
|
58
|
+
end
|
59
|
+
|
60
|
+
res = @cache.get(cache_key(ip_address))
|
61
|
+
return res unless res.nil?
|
62
|
+
|
63
|
+
ip_address ||= 'me'
|
64
|
+
response = @httpc.get(escape_path(ip_address))
|
65
|
+
|
66
|
+
if response.status.eql?(429)
|
67
|
+
raise RateLimitError,
|
68
|
+
RATE_LIMIT_MESSAGE
|
69
|
+
end
|
70
|
+
|
71
|
+
details = JSON.parse(response.body, symbolize_names: true)
|
72
|
+
@cache.set(cache_key(ip_address), details)
|
73
|
+
details
|
74
|
+
end
|
75
|
+
|
76
|
+
def details_base(ip_address)
|
77
|
+
details = request_details(ip_address)
|
78
|
+
if details.key? :country_code
|
79
|
+
details[:country_name] =
|
80
|
+
@countries.fetch(details.fetch(:country_code), nil)
|
81
|
+
details[:is_eu] =
|
82
|
+
@eu_countries.include?(details.fetch(:country_code))
|
83
|
+
details[:country_flag] =
|
84
|
+
@countries_flags.fetch(details.fetch(:country_code), nil)
|
85
|
+
details[:country_currency] =
|
86
|
+
@countries_currencies.fetch(details.fetch(:country_code), nil)
|
87
|
+
details[:continent] =
|
88
|
+
@continents.fetch(details.fetch(:country_code), nil)
|
89
|
+
details[:country_flag_url] = "#{COUNTRY_FLAGS_URL}#{details.fetch(:country_code)}.svg"
|
90
|
+
end
|
91
|
+
|
92
|
+
if details.key? :ip
|
93
|
+
details[:ip_address] =
|
94
|
+
IPAddr.new(details.fetch(:ip))
|
95
|
+
end
|
96
|
+
|
97
|
+
IPinfo::Response.new(details)
|
98
|
+
end
|
99
|
+
|
100
|
+
def isBogon(ip)
|
101
|
+
if ip.nil?
|
102
|
+
return false
|
103
|
+
end
|
104
|
+
|
105
|
+
matcher_object = IPinfo::IpAddressMatcher.new(ip)
|
106
|
+
matcher_object.matches
|
107
|
+
end
|
108
|
+
|
109
|
+
def escape_path(ip)
|
110
|
+
ip ? "/#{CGI.escape(ip)}" : '/'
|
111
|
+
end
|
112
|
+
|
113
|
+
def cache_key(ip)
|
114
|
+
"1:#{ip}"
|
115
|
+
end
|
116
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: IPinfo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
|
9
|
-
autorequire:
|
7
|
+
- IPinfo releases
|
8
|
+
autorequire:
|
10
9
|
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2025-08-04 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: faraday
|
@@ -139,8 +138,7 @@ dependencies:
|
|
139
138
|
version: '1.1'
|
140
139
|
description: " This is a ruby wrapper for http://ipinfo.io. "
|
141
140
|
email:
|
142
|
-
-
|
143
|
-
- uman@mslm.io
|
141
|
+
- releases@ipinfo.io
|
144
142
|
executables: []
|
145
143
|
extensions: []
|
146
144
|
extra_rdoc_files: []
|
@@ -168,10 +166,11 @@ files:
|
|
168
166
|
- lib/ipinfo/mod.rb
|
169
167
|
- lib/ipinfo/response.rb
|
170
168
|
- lib/ipinfo/version.rb
|
169
|
+
- lib/ipinfo_lite.rb
|
171
170
|
homepage: https://ipinfo.io
|
172
171
|
licenses: []
|
173
172
|
metadata: {}
|
174
|
-
post_install_message:
|
173
|
+
post_install_message:
|
175
174
|
rdoc_options: []
|
176
175
|
require_paths:
|
177
176
|
- lib
|
@@ -187,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
186
|
version: '0'
|
188
187
|
requirements: []
|
189
188
|
rubygems_version: 3.4.10
|
190
|
-
signing_key:
|
189
|
+
signing_key:
|
191
190
|
specification_version: 4
|
192
191
|
summary: This is a ruby wrapper for http://ipinfo.io.
|
193
192
|
test_files: []
|