ipinfo-rails 1.1.0 → 1.3.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 +4 -4
- data/.github/workflows/release.yml +37 -0
- data/Gemfile +1 -1
- data/README.md +58 -19
- data/ipinfo-rails.gemspec +1 -1
- data/lib/ipinfo-rails/version.rb +1 -1
- data/lib/ipinfo-rails.rb +92 -0
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b8540a5ad2a5b468813f8bcab30fa9f09d783ccdd4b03bce03b6e029904e9cc4
|
|
4
|
+
data.tar.gz: a28a3e886ff40cc21029f70c29d4e677379a0f06cfbc6a61bf19268b4875cbb0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 451429e2d9fe254f2c99b98dbdf9954ad5879c2b65804f376462ab69be62a4514878cf8c53e4d70959079a9fc85b6c4baea171be9b526abcccb8f14db3e351e1
|
|
7
|
+
data.tar.gz: 97a87924479bd46f5eb2bdc36fe9a139ab02ac0b28980d72097ad5bcc16c36962be219bf3d5f42270a528a9c5ffdc7fad2d34efa474483b9e2cd4a1d2cbdb805
|
|
@@ -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
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
id-token: write
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout
|
|
17
|
+
uses: actions/checkout@v3
|
|
18
|
+
|
|
19
|
+
- name: Install apt dependencies
|
|
20
|
+
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev # needed by faraday-patron gem
|
|
21
|
+
|
|
22
|
+
- name: Set up Ruby
|
|
23
|
+
uses: ruby/setup-ruby@v1
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: bundle install
|
|
27
|
+
|
|
28
|
+
- name: Run tests
|
|
29
|
+
run: bundle exec rake
|
|
30
|
+
env:
|
|
31
|
+
IPINFO_TOKEN: ${{ secrets.IPINFO_TOKEN }}
|
|
32
|
+
|
|
33
|
+
- name: Build
|
|
34
|
+
run: gem build *.gemspec
|
|
35
|
+
|
|
36
|
+
- name: Publish
|
|
37
|
+
uses: rubygems/release-gem@v1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -21,30 +21,30 @@ The library also supports the Lite API, see the [Lite API section](#lite-api) fo
|
|
|
21
21
|
|
|
22
22
|
1. Option 1) Add this line to your application's Gemfile:
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
```ruby
|
|
25
|
+
gem 'ipinfo-rails'
|
|
26
|
+
```
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Then execute:
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
```bash
|
|
31
|
+
$ bundle install
|
|
32
|
+
```
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
Option 2) Install it yourself by running the following command:
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
```bash
|
|
37
|
+
$ gem install ipinfo-rails
|
|
38
|
+
```
|
|
39
39
|
|
|
40
40
|
1. Open your `config/environment.rb` file or your preferred file in the `config/environment` directory. Add the following code to your chosen configuration file.
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
```ruby
|
|
43
|
+
require 'ipinfo-rails'
|
|
44
|
+
config.middleware.use(IPinfoMiddleware, {token: "<your_token>"})
|
|
45
|
+
```
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
Note: if editing `config/environment.rb`, this needs to come before `Rails.application.initialize!` and with `Rails.application.` prepended to `config`, otherwise you'll get runtime errors.
|
|
48
48
|
|
|
49
49
|
1. Restart your development server.
|
|
50
50
|
|
|
@@ -120,7 +120,7 @@ request.env['ipinfo'].all ==
|
|
|
120
120
|
|
|
121
121
|
## Configuration
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
In addition to the steps listed in the Installation section, it is possible to configure the library with more detail. The following arguments are allowed and are described in detail below.
|
|
124
124
|
|
|
125
125
|
```ruby
|
|
126
126
|
require 'ipinfo-rails/ip_selector/xforwarded_ip_selector'
|
|
@@ -231,10 +231,10 @@ config.middleware.use(IPinfoMiddleware, {:countries => <path_to_settings_file>})
|
|
|
231
231
|
|
|
232
232
|
By default, `ipinfo-rails` filters out requests that have `bot` or `spider` in the user-agent. Instead of looking up IP address data for these requests, the `request.env['ipinfo']` attribute is set to `nil`. This is to prevent you from unnecessarily using up requests on non-user traffic.
|
|
233
233
|
|
|
234
|
-
To set your own filtering rules,
|
|
234
|
+
To set your own filtering rules, _thereby replacing the default filter_, you can set `:filter` to your own, custom callable function which satisfies the following rules:
|
|
235
235
|
|
|
236
236
|
- Accepts one request.
|
|
237
|
-
- Returns
|
|
237
|
+
- Returns _True to filter out, False to allow lookup_
|
|
238
238
|
|
|
239
239
|
To use your own filter rules:
|
|
240
240
|
|
|
@@ -259,6 +259,45 @@ require 'ipinfo-rails'
|
|
|
259
259
|
config.middleware.use(IPinfoLiteMiddleware, {token: "<your_token>"})
|
|
260
260
|
```
|
|
261
261
|
|
|
262
|
+
## Core API
|
|
263
|
+
|
|
264
|
+
The library also supports the [Core API](https://ipinfo.io/developers/data-types#core-data), which provides city-level geolocation with nested geo and AS objects. Authentication with your token is required.
|
|
265
|
+
|
|
266
|
+
```ruby
|
|
267
|
+
require 'ipinfo-rails'
|
|
268
|
+
config.middleware.use(IPinfoCoreMiddleware, {token: "<your_token>"})
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## Plus API
|
|
272
|
+
|
|
273
|
+
The library also supports the [Plus API](https://ipinfo.io/developers/data-types#plus-data), which provides enhanced data including mobile carrier info and privacy detection. Authentication with your token is required.
|
|
274
|
+
|
|
275
|
+
```ruby
|
|
276
|
+
require 'ipinfo-rails'
|
|
277
|
+
config.middleware.use(IPinfoPlusMiddleware, {token: "<your_token>"})
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Residential Proxy API
|
|
281
|
+
|
|
282
|
+
The library also supports the [Residential Proxy API](https://ipinfo.io/developers/residential-proxy-api), which allows you to check if an IP address is a residential proxy. Authentication with your token is required.
|
|
283
|
+
|
|
284
|
+
```ruby
|
|
285
|
+
require 'ipinfo-rails'
|
|
286
|
+
config.middleware.use(IPinfoResproxyMiddleware, {token: "<your_token>"})
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
The residential proxy details will be available through `request.env['ipinfo_resproxy']`:
|
|
290
|
+
|
|
291
|
+
```ruby
|
|
292
|
+
resproxy = request.env['ipinfo_resproxy']
|
|
293
|
+
if resproxy
|
|
294
|
+
resproxy.ip # 175.107.211.204
|
|
295
|
+
resproxy.last_seen # 2025-01-20
|
|
296
|
+
resproxy.percent_days_seen # 0.85
|
|
297
|
+
resproxy.service # Bright Data
|
|
298
|
+
end
|
|
299
|
+
```
|
|
300
|
+
|
|
262
301
|
## Other Libraries
|
|
263
302
|
|
|
264
303
|
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.
|
data/ipinfo-rails.gemspec
CHANGED
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
|
21
21
|
s.homepage = 'https://ipinfo.io'
|
|
22
22
|
s.license = 'Apache-2.0'
|
|
23
23
|
|
|
24
|
-
s.add_dependency 'IPinfo', '~> 2.
|
|
24
|
+
s.add_dependency 'IPinfo', '~> 2.5'
|
|
25
25
|
s.add_dependency 'rack', '~> 2.0'
|
|
26
26
|
|
|
27
27
|
s.add_development_dependency 'mocha', '~> 2.7'
|
data/lib/ipinfo-rails/version.rb
CHANGED
data/lib/ipinfo-rails.rb
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
require 'rack'
|
|
4
4
|
require 'ipinfo'
|
|
5
5
|
require 'ipinfo_lite'
|
|
6
|
+
require 'ipinfo_core'
|
|
7
|
+
require 'ipinfo_plus'
|
|
6
8
|
require 'ipinfo-rails/ip_selector/default_ip_selector'
|
|
7
9
|
|
|
8
10
|
def is_bot(request)
|
|
@@ -73,3 +75,93 @@ class IPinfoLiteMiddleware
|
|
|
73
75
|
@app.call(env)
|
|
74
76
|
end
|
|
75
77
|
end
|
|
78
|
+
|
|
79
|
+
class IPinfoCoreMiddleware
|
|
80
|
+
def initialize(app, options = {})
|
|
81
|
+
@app = app
|
|
82
|
+
@token = options.fetch(:token, nil)
|
|
83
|
+
@ipinfo = IPinfoCore.create(@token, options)
|
|
84
|
+
@filter = options.fetch(:filter, nil)
|
|
85
|
+
@ip_selector = options.fetch(:ip_selector, DefaultIPSelector)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def call(env)
|
|
89
|
+
env['called'] = 'yes'
|
|
90
|
+
request = Rack::Request.new(env)
|
|
91
|
+
ip_selector = @ip_selector.new(request)
|
|
92
|
+
filtered = if @filter.nil?
|
|
93
|
+
is_bot(request)
|
|
94
|
+
else
|
|
95
|
+
@filter.call(request)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
if filtered
|
|
99
|
+
env['ipinfo'] = nil
|
|
100
|
+
else
|
|
101
|
+
ip = ip_selector.get_ip
|
|
102
|
+
env['ipinfo'] = @ipinfo.details(ip)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
@app.call(env)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
class IPinfoPlusMiddleware
|
|
110
|
+
def initialize(app, options = {})
|
|
111
|
+
@app = app
|
|
112
|
+
@token = options.fetch(:token, nil)
|
|
113
|
+
@ipinfo = IPinfoPlus.create(@token, options)
|
|
114
|
+
@filter = options.fetch(:filter, nil)
|
|
115
|
+
@ip_selector = options.fetch(:ip_selector, DefaultIPSelector)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def call(env)
|
|
119
|
+
env['called'] = 'yes'
|
|
120
|
+
request = Rack::Request.new(env)
|
|
121
|
+
ip_selector = @ip_selector.new(request)
|
|
122
|
+
filtered = if @filter.nil?
|
|
123
|
+
is_bot(request)
|
|
124
|
+
else
|
|
125
|
+
@filter.call(request)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
if filtered
|
|
129
|
+
env['ipinfo'] = nil
|
|
130
|
+
else
|
|
131
|
+
ip = ip_selector.get_ip
|
|
132
|
+
env['ipinfo'] = @ipinfo.details(ip)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
@app.call(env)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
class IPinfoResproxyMiddleware
|
|
140
|
+
def initialize(app, options = {})
|
|
141
|
+
@app = app
|
|
142
|
+
@token = options.fetch(:token, nil)
|
|
143
|
+
@ipinfo = IPinfo.create(@token, options)
|
|
144
|
+
@filter = options.fetch(:filter, nil)
|
|
145
|
+
@ip_selector = options.fetch(:ip_selector, DefaultIPSelector)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def call(env)
|
|
149
|
+
env['called'] = 'yes'
|
|
150
|
+
request = Rack::Request.new(env)
|
|
151
|
+
ip_selector = @ip_selector.new(request)
|
|
152
|
+
filtered = if @filter.nil?
|
|
153
|
+
is_bot(request)
|
|
154
|
+
else
|
|
155
|
+
@filter.call(request)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
if filtered
|
|
159
|
+
env['ipinfo_resproxy'] = nil
|
|
160
|
+
else
|
|
161
|
+
ip = ip_selector.get_ip
|
|
162
|
+
env['ipinfo_resproxy'] = @ipinfo.resproxy(ip)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
@app.call(env)
|
|
166
|
+
end
|
|
167
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ipinfo-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- IPinfo releases
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-01-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: IPinfo
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '2.
|
|
19
|
+
version: '2.5'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '2.
|
|
26
|
+
version: '2.5'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rack
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -62,6 +62,7 @@ executables: []
|
|
|
62
62
|
extensions: []
|
|
63
63
|
extra_rdoc_files: []
|
|
64
64
|
files:
|
|
65
|
+
- ".github/workflows/release.yml"
|
|
65
66
|
- ".github/workflows/test.yml"
|
|
66
67
|
- ".gitignore"
|
|
67
68
|
- ".rubocop.yml"
|