dbip_util 0.1.0.2025.07
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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +271 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +38 -0
- data/README.md +71 -0
- data/Rakefile +12 -0
- data/bin/console +11 -0
- data/bin/dbiputil-refresh +25 -0
- data/bin/setup +8 -0
- data/lib/dbip_util/db/dbip-asn-lite.mmdb +0 -0
- data/lib/dbip_util/db/dbip-city-lite.mmdb +0 -0
- data/lib/dbip_util/db/dbip-country-lite.mmdb +0 -0
- data/lib/dbip_util/version.rb +6 -0
- data/lib/dbip_util.rb +44 -0
- data/sig/dbip_util/version.rbs +5 -0
- data/sig/dbip_util.rbs +16 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aaaa32a97d1442cbb719e80a4e9b807f0a08c4c8a302f98977a6461c726ca740
|
4
|
+
data.tar.gz: daa998a114a3b13c8036e91da64b6ab9972b8a637dda67ab2df0bd035ae5474b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 61549e7205ef41e77e5bd4b6f8bf3c8b3939ca6d9191793530715ab8272a297c02ff1bb34e5e467d81f521b66de3af28a16938548a05d9d8de972943c37c58d5
|
7
|
+
data.tar.gz: 6d37b8e33fdd40045e92a5fcaf04f0a51cbcdfcc7cd28710f2352b983f3c967b2bbdabdb38aa706bd04e549f0ba2a12a3ac974b6dee27995d4025fc6767a81b7
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,271 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 3.1
|
3
|
+
|
4
|
+
Style/StringLiterals:
|
5
|
+
EnforcedStyle: double_quotes
|
6
|
+
|
7
|
+
Style/StringLiteralsInInterpolation:
|
8
|
+
EnforcedStyle: double_quotes
|
9
|
+
|
10
|
+
# We use an open method which has nothing to do with Kernel#open.
|
11
|
+
Security/Open:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Gemspec/AddRuntimeDependency: # new in 1.65
|
15
|
+
Enabled: true
|
16
|
+
Gemspec/DeprecatedAttributeAssignment: # new in 1.30
|
17
|
+
Enabled: true
|
18
|
+
Gemspec/DevelopmentDependencies: # new in 1.44
|
19
|
+
Enabled: true
|
20
|
+
Gemspec/RequireMFA: # new in 1.23
|
21
|
+
Enabled: true
|
22
|
+
Layout/LineContinuationLeadingSpace: # new in 1.31
|
23
|
+
Enabled: true
|
24
|
+
Layout/LineContinuationSpacing: # new in 1.31
|
25
|
+
Enabled: true
|
26
|
+
Layout/LineEndStringConcatenationIndentation: # new in 1.18
|
27
|
+
Enabled: true
|
28
|
+
Layout/SpaceBeforeBrackets: # new in 1.7
|
29
|
+
Enabled: true
|
30
|
+
Lint/AmbiguousAssignment: # new in 1.7
|
31
|
+
Enabled: true
|
32
|
+
Lint/AmbiguousOperatorPrecedence: # new in 1.21
|
33
|
+
Enabled: true
|
34
|
+
Lint/AmbiguousRange: # new in 1.19
|
35
|
+
Enabled: true
|
36
|
+
Lint/ArrayLiteralInRegexp: # new in 1.71
|
37
|
+
Enabled: true
|
38
|
+
Lint/ConstantOverwrittenInRescue: # new in 1.31
|
39
|
+
Enabled: true
|
40
|
+
Lint/ConstantReassignment: # new in 1.70
|
41
|
+
Enabled: true
|
42
|
+
Lint/CopDirectiveSyntax: # new in 1.72
|
43
|
+
Enabled: true
|
44
|
+
Lint/DeprecatedConstants: # new in 1.8
|
45
|
+
Enabled: true
|
46
|
+
Lint/DuplicateBranch: # new in 1.3
|
47
|
+
Enabled: true
|
48
|
+
Lint/DuplicateMagicComment: # new in 1.37
|
49
|
+
Enabled: true
|
50
|
+
Lint/DuplicateMatchPattern: # new in 1.50
|
51
|
+
Enabled: true
|
52
|
+
Lint/DuplicateRegexpCharacterClassElement: # new in 1.1
|
53
|
+
Enabled: true
|
54
|
+
Lint/DuplicateSetElement: # new in 1.67
|
55
|
+
Enabled: true
|
56
|
+
Lint/EmptyBlock: # new in 1.1
|
57
|
+
Enabled: true
|
58
|
+
Lint/EmptyClass: # new in 1.3
|
59
|
+
Enabled: true
|
60
|
+
Lint/EmptyInPattern: # new in 1.16
|
61
|
+
Enabled: true
|
62
|
+
Lint/HashNewWithKeywordArgumentsAsDefault: # new in 1.69
|
63
|
+
Enabled: true
|
64
|
+
Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
|
65
|
+
Enabled: true
|
66
|
+
Lint/ItWithoutArgumentsInBlock: # new in 1.59
|
67
|
+
Enabled: true
|
68
|
+
Lint/LambdaWithoutLiteralBlock: # new in 1.8
|
69
|
+
Enabled: true
|
70
|
+
Lint/LiteralAssignmentInCondition: # new in 1.58
|
71
|
+
Enabled: true
|
72
|
+
Lint/MixedCaseRange: # new in 1.53
|
73
|
+
Enabled: true
|
74
|
+
Lint/NoReturnInBeginEndBlocks: # new in 1.2
|
75
|
+
Enabled: true
|
76
|
+
Lint/NonAtomicFileOperation: # new in 1.31
|
77
|
+
Enabled: true
|
78
|
+
Lint/NumberedParameterAssignment: # new in 1.9
|
79
|
+
Enabled: true
|
80
|
+
Lint/NumericOperationWithConstantResult: # new in 1.69
|
81
|
+
Enabled: true
|
82
|
+
Lint/OrAssignmentToConstant: # new in 1.9
|
83
|
+
Enabled: true
|
84
|
+
Lint/RedundantDirGlobSort: # new in 1.8
|
85
|
+
Enabled: true
|
86
|
+
Lint/RedundantRegexpQuantifiers: # new in 1.53
|
87
|
+
Enabled: true
|
88
|
+
Lint/RedundantTypeConversion: # new in 1.72
|
89
|
+
Enabled: true
|
90
|
+
Lint/RefinementImportMethods: # new in 1.27
|
91
|
+
Enabled: true
|
92
|
+
Lint/RequireRangeParentheses: # new in 1.32
|
93
|
+
Enabled: true
|
94
|
+
Lint/RequireRelativeSelfPath: # new in 1.22
|
95
|
+
Enabled: true
|
96
|
+
Lint/SharedMutableDefault: # new in 1.70
|
97
|
+
Enabled: true
|
98
|
+
Lint/SuppressedExceptionInNumberConversion: # new in 1.72
|
99
|
+
Enabled: true
|
100
|
+
Lint/SymbolConversion: # new in 1.9
|
101
|
+
Enabled: true
|
102
|
+
Lint/ToEnumArguments: # new in 1.1
|
103
|
+
Enabled: true
|
104
|
+
Lint/TripleQuotes: # new in 1.9
|
105
|
+
Enabled: true
|
106
|
+
Lint/UnescapedBracketInRegexp: # new in 1.68
|
107
|
+
Enabled: true
|
108
|
+
Lint/UnexpectedBlockArity: # new in 1.5
|
109
|
+
Enabled: true
|
110
|
+
Lint/UnmodifiedReduceAccumulator: # new in 1.1
|
111
|
+
Enabled: true
|
112
|
+
Lint/UselessConstantScoping: # new in 1.72
|
113
|
+
Enabled: true
|
114
|
+
Lint/UselessDefined: # new in 1.69
|
115
|
+
Enabled: true
|
116
|
+
Lint/UselessNumericOperation: # new in 1.66
|
117
|
+
Enabled: true
|
118
|
+
Lint/UselessRescue: # new in 1.43
|
119
|
+
Enabled: true
|
120
|
+
Lint/UselessRuby2Keywords: # new in 1.23
|
121
|
+
Enabled: true
|
122
|
+
Metrics/CollectionLiteralLength: # new in 1.47
|
123
|
+
Enabled: true
|
124
|
+
Naming/BlockForwarding: # new in 1.24
|
125
|
+
Enabled: true
|
126
|
+
Security/CompoundHash: # new in 1.28
|
127
|
+
Enabled: true
|
128
|
+
Security/IoMethods: # new in 1.22
|
129
|
+
Enabled: true
|
130
|
+
Style/AmbiguousEndlessMethodDefinition: # new in 1.68
|
131
|
+
Enabled: true
|
132
|
+
Style/ArgumentsForwarding: # new in 1.1
|
133
|
+
Enabled: true
|
134
|
+
Style/ArrayIntersect: # new in 1.40
|
135
|
+
Enabled: true
|
136
|
+
Style/BitwisePredicate: # new in 1.68
|
137
|
+
Enabled: true
|
138
|
+
Style/CollectionCompact: # new in 1.2
|
139
|
+
Enabled: true
|
140
|
+
Style/CombinableDefined: # new in 1.68
|
141
|
+
Enabled: true
|
142
|
+
Style/ComparableClamp: # new in 1.44
|
143
|
+
Enabled: true
|
144
|
+
Style/ConcatArrayLiterals: # new in 1.41
|
145
|
+
Enabled: true
|
146
|
+
Style/DataInheritance: # new in 1.49
|
147
|
+
Enabled: true
|
148
|
+
Style/DigChain: # new in 1.69
|
149
|
+
Enabled: true
|
150
|
+
Style/DirEmpty: # new in 1.48
|
151
|
+
Enabled: true
|
152
|
+
Style/DocumentDynamicEvalDefinition: # new in 1.1
|
153
|
+
Enabled: true
|
154
|
+
Style/EmptyHeredoc: # new in 1.32
|
155
|
+
Enabled: true
|
156
|
+
Style/EndlessMethod: # new in 1.8
|
157
|
+
Enabled: true
|
158
|
+
Style/EnvHome: # new in 1.29
|
159
|
+
Enabled: true
|
160
|
+
Style/ExactRegexpMatch: # new in 1.51
|
161
|
+
Enabled: true
|
162
|
+
Style/FetchEnvVar: # new in 1.28
|
163
|
+
Enabled: true
|
164
|
+
Style/FileEmpty: # new in 1.48
|
165
|
+
Enabled: true
|
166
|
+
Style/FileNull: # new in 1.69
|
167
|
+
Enabled: true
|
168
|
+
Style/FileRead: # new in 1.24
|
169
|
+
Enabled: true
|
170
|
+
Style/FileTouch: # new in 1.69
|
171
|
+
Enabled: true
|
172
|
+
Style/FileWrite: # new in 1.24
|
173
|
+
Enabled: true
|
174
|
+
Style/HashConversion: # new in 1.10
|
175
|
+
Enabled: true
|
176
|
+
Style/HashExcept: # new in 1.7
|
177
|
+
Enabled: true
|
178
|
+
Style/HashSlice: # new in 1.71
|
179
|
+
Enabled: true
|
180
|
+
Style/IfWithBooleanLiteralBranches: # new in 1.9
|
181
|
+
Enabled: true
|
182
|
+
Style/InPatternThen: # new in 1.16
|
183
|
+
Enabled: true
|
184
|
+
Style/ItAssignment: # new in 1.70
|
185
|
+
Enabled: true
|
186
|
+
Style/KeywordArgumentsMerging: # new in 1.68
|
187
|
+
Enabled: true
|
188
|
+
Style/MagicCommentFormat: # new in 1.35
|
189
|
+
Enabled: true
|
190
|
+
Style/MapCompactWithConditionalBlock: # new in 1.30
|
191
|
+
Enabled: true
|
192
|
+
Style/MapIntoArray: # new in 1.63
|
193
|
+
Enabled: true
|
194
|
+
Style/MapToHash: # new in 1.24
|
195
|
+
Enabled: true
|
196
|
+
Style/MapToSet: # new in 1.42
|
197
|
+
Enabled: true
|
198
|
+
Style/MinMaxComparison: # new in 1.42
|
199
|
+
Enabled: true
|
200
|
+
Style/MultilineInPatternThen: # new in 1.16
|
201
|
+
Enabled: true
|
202
|
+
Style/NegatedIfElseCondition: # new in 1.2
|
203
|
+
Enabled: true
|
204
|
+
Style/NestedFileDirname: # new in 1.26
|
205
|
+
Enabled: true
|
206
|
+
Style/NilLambda: # new in 1.3
|
207
|
+
Enabled: true
|
208
|
+
Style/NumberedParameters: # new in 1.22
|
209
|
+
Enabled: true
|
210
|
+
Style/NumberedParametersLimit: # new in 1.22
|
211
|
+
Enabled: true
|
212
|
+
Style/ObjectThen: # new in 1.28
|
213
|
+
Enabled: true
|
214
|
+
Style/OpenStructUse: # new in 1.23
|
215
|
+
Enabled: true
|
216
|
+
Style/OperatorMethodCall: # new in 1.37
|
217
|
+
Enabled: true
|
218
|
+
Style/QuotedSymbols: # new in 1.16
|
219
|
+
Enabled: true
|
220
|
+
Style/RedundantArgument: # new in 1.4
|
221
|
+
Enabled: true
|
222
|
+
Style/RedundantArrayConstructor: # new in 1.52
|
223
|
+
Enabled: true
|
224
|
+
Style/RedundantConstantBase: # new in 1.40
|
225
|
+
Enabled: true
|
226
|
+
Style/RedundantCurrentDirectoryInPath: # new in 1.53
|
227
|
+
Enabled: true
|
228
|
+
Style/RedundantDoubleSplatHashBraces: # new in 1.41
|
229
|
+
Enabled: true
|
230
|
+
Style/RedundantEach: # new in 1.38
|
231
|
+
Enabled: true
|
232
|
+
Style/RedundantFilterChain: # new in 1.52
|
233
|
+
Enabled: true
|
234
|
+
Style/RedundantFormat: # new in 1.72
|
235
|
+
Enabled: true
|
236
|
+
Style/RedundantHeredocDelimiterQuotes: # new in 1.45
|
237
|
+
Enabled: true
|
238
|
+
Style/RedundantInitialize: # new in 1.27
|
239
|
+
Enabled: true
|
240
|
+
Style/RedundantInterpolationUnfreeze: # new in 1.66
|
241
|
+
Enabled: true
|
242
|
+
Style/RedundantLineContinuation: # new in 1.49
|
243
|
+
Enabled: true
|
244
|
+
Style/RedundantRegexpArgument: # new in 1.53
|
245
|
+
Enabled: true
|
246
|
+
Style/RedundantRegexpConstructor: # new in 1.52
|
247
|
+
Enabled: true
|
248
|
+
Style/RedundantSelfAssignmentBranch: # new in 1.19
|
249
|
+
Enabled: true
|
250
|
+
Style/RedundantStringEscape: # new in 1.37
|
251
|
+
Enabled: true
|
252
|
+
Style/ReturnNilInPredicateMethodDefinition: # new in 1.53
|
253
|
+
Enabled: true
|
254
|
+
Style/SafeNavigationChainLength: # new in 1.68
|
255
|
+
Enabled: true
|
256
|
+
Style/SelectByRegexp: # new in 1.22
|
257
|
+
Enabled: true
|
258
|
+
Style/SendWithLiteralMethodName: # new in 1.64
|
259
|
+
Enabled: true
|
260
|
+
Style/SingleLineDoEndBlock: # new in 1.57
|
261
|
+
Enabled: true
|
262
|
+
Style/StringChars: # new in 1.12
|
263
|
+
Enabled: true
|
264
|
+
Style/SuperArguments: # new in 1.64
|
265
|
+
Enabled: true
|
266
|
+
Style/SuperWithArgsParentheses: # new in 1.58
|
267
|
+
Enabled: true
|
268
|
+
Style/SwapValues: # new in 1.1
|
269
|
+
Enabled: true
|
270
|
+
Style/YAMLFileRead: # new in 1.53
|
271
|
+
Enabled: true
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 hmdne
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
22
|
+
|
23
|
+
---------------------------------------------------------------------------
|
24
|
+
|
25
|
+
This gem contains database that is licensed under a following license:
|
26
|
+
|
27
|
+
The free IP to City Lite database by DB-IP is licensed under a
|
28
|
+
Creative Commons Attribution 4.0 International License.
|
29
|
+
|
30
|
+
You are free to use this IP to City Lite database in your application,
|
31
|
+
provided you give attribution to DB-IP.com for the data.
|
32
|
+
|
33
|
+
In the case of a web application, you must include a link back to
|
34
|
+
DB-IP.com on pages that display or use results from the database.
|
35
|
+
You may do it by pasting the HTML code snippet below into your code :
|
36
|
+
|
37
|
+
<a href='https://db-ip.com'>IP Geolocation by DB-IP</a>
|
38
|
+
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# DbipUtil
|
2
|
+
|
3
|
+
DbipUtil includes DB-IP Lite databases and a simple interface to them, based on `maxmind-db` gem.
|
4
|
+
|
5
|
+
The included databases are refreshed automatically. A GitHub Actions workflow runs `bin/dbiputil-refresh` and then `rake release` at **00:45 GMT+1 on the 15th of every month** to publish a new gem version. Ensure to comply with the database licensing terms below in this document.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
```bash
|
12
|
+
bundle add dbip_util
|
13
|
+
```
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
gem install dbip_util
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
record = DbipUtil::Country.get("1.1.1.1")
|
25
|
+
if record.nil?
|
26
|
+
puts '1.1.1.1 was not found in the database'
|
27
|
+
else
|
28
|
+
puts record['country']['iso_code']
|
29
|
+
puts record['country']['names']['en']
|
30
|
+
end
|
31
|
+
|
32
|
+
# Also: DbipUtil::ASN, DbipUtil::City
|
33
|
+
```
|
34
|
+
|
35
|
+
This gem uses a `maxmind-db` gem. More documentation is provided by said gem: https://www.rubydoc.info/gems/maxmind-db
|
36
|
+
|
37
|
+
The databases are documented here:
|
38
|
+
|
39
|
+
- https://db-ip.com/db/format/ip-to-country-lite/mmdb.html
|
40
|
+
- https://db-ip.com/db/format/ip-to-city-lite/mmdb.html
|
41
|
+
- https://db-ip.com/db/format/ip-to-asn-lite/mmdb.html
|
42
|
+
|
43
|
+
## Development
|
44
|
+
|
45
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
46
|
+
|
47
|
+
To install this gem onto your local machine, run `bundle exec rake install`. If you need to trigger a release manually, run `bin/dbiputil-refresh` and then `bundle exec rake release`. This will create a git tag for the version, push commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rbutils/dbip_util.
|
52
|
+
|
53
|
+
## License
|
54
|
+
|
55
|
+
The code inside this gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
56
|
+
|
57
|
+
Note that this gem contains DB-IP Lite databases. The license terms of those databases are as follows:
|
58
|
+
|
59
|
+
```
|
60
|
+
The free IP to City Lite database by DB-IP is licensed under a
|
61
|
+
Creative Commons Attribution 4.0 International License.
|
62
|
+
|
63
|
+
You are free to use this IP to City Lite database in your application,
|
64
|
+
provided you give attribution to DB-IP.com for the data.
|
65
|
+
|
66
|
+
In the case of a web application, you must include a link back to
|
67
|
+
DB-IP.com on pages that display or use results from the database.
|
68
|
+
You may do it by pasting the HTML code snippet below into your code :
|
69
|
+
|
70
|
+
<a href='https://db-ip.com'>IP Geolocation by DB-IP</a>
|
71
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "dbip_util"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
require "irb"
|
11
|
+
IRB.start(__FILE__)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
|
6
|
+
Dir.chdir "#{__dir__}/../lib/dbip_util" do
|
7
|
+
date = Time.now.strftime("%Y-%m")
|
8
|
+
date_ver = date.gsub("-", ".")
|
9
|
+
|
10
|
+
system "rm -rf db"
|
11
|
+
system "mkdir db"
|
12
|
+
Dir.chdir "db" do
|
13
|
+
%i[country city asn].each do |type|
|
14
|
+
system <<~SH
|
15
|
+
curl 'https://download.db-ip.com/free/dbip-#{type}-lite-#{date}.mmdb.gz' |
|
16
|
+
gunzip -c > dbip-#{type}-lite.mmdb
|
17
|
+
SH
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Version bump
|
22
|
+
version_file = File.read("version.rb")
|
23
|
+
version_file = version_file.gsub(/DB_VERSION = .*/, %(DB_VERSION = "#{date_ver}"))
|
24
|
+
File.write("version.rb", version_file)
|
25
|
+
end
|
data/bin/setup
ADDED
Binary file
|
Binary file
|
Binary file
|
data/lib/dbip_util.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dbip_util/version"
|
4
|
+
require "maxmind/db"
|
5
|
+
|
6
|
+
# DbipUtil includes DB-IP Lite databases and a simple interface to them, based on `maxmind-db` gem.
|
7
|
+
module DbipUtil
|
8
|
+
extend self
|
9
|
+
|
10
|
+
def open(db, options = {})
|
11
|
+
ensure_provisioned!
|
12
|
+
|
13
|
+
options = { mode: MaxMind::DB::MODE_FILE }.merge(options)
|
14
|
+
fn = db_path(db)
|
15
|
+
MaxMind::DB.new(fn, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def const_missing(const)
|
19
|
+
case const
|
20
|
+
when :Country
|
21
|
+
const_set(const, open(:country))
|
22
|
+
when :City
|
23
|
+
const_set(const, open(:city))
|
24
|
+
when :ASN
|
25
|
+
const_set(const, open(:asn))
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def db_path(db)
|
34
|
+
__dir__ + "/dbip_util/db/dbip-#{db}-lite.mmdb"
|
35
|
+
end
|
36
|
+
|
37
|
+
def ensure_provisioned!
|
38
|
+
# Check for a sample database. If not present, provision it.
|
39
|
+
system "#{__dir__}/../bin/dbiputil-refresh" unless File.exist?(db_path(:country))
|
40
|
+
rescue StandardError
|
41
|
+
warn "Couldn't provision a database! Use a `dbip_util` gem from Rubygems, as it includes a database."
|
42
|
+
raise
|
43
|
+
end
|
44
|
+
end
|
data/sig/dbip_util.rbs
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# DbipUtil includes DB-IP Lite databases and a simple interface to them, based on `maxmind-db` gem.
|
2
|
+
module DbipUtil
|
3
|
+
extend ::DbipUtil
|
4
|
+
|
5
|
+
def open: (Symbol db, ?::Hash[Symbol, untyped] options) -> MaxMind::DB
|
6
|
+
def const_missing: (Symbol const) -> MaxMind::DB
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def db_path: (Symbol db) -> String
|
11
|
+
def ensure_provisioned!: () -> untyped
|
12
|
+
|
13
|
+
AST: MaxMind::DB
|
14
|
+
City: MaxMind::DB
|
15
|
+
Country: MaxMind::DB
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dbip_util
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.2025.07
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hmdne
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: maxmind-db
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.3'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '1.3'
|
26
|
+
email:
|
27
|
+
- 54514036+hmdne@users.noreply.github.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- ".rspec"
|
33
|
+
- ".rubocop.yml"
|
34
|
+
- CHANGELOG.md
|
35
|
+
- LICENSE.txt
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- bin/console
|
39
|
+
- bin/dbiputil-refresh
|
40
|
+
- bin/setup
|
41
|
+
- lib/dbip_util.rb
|
42
|
+
- lib/dbip_util/db/dbip-asn-lite.mmdb
|
43
|
+
- lib/dbip_util/db/dbip-city-lite.mmdb
|
44
|
+
- lib/dbip_util/db/dbip-country-lite.mmdb
|
45
|
+
- lib/dbip_util/version.rb
|
46
|
+
- sig/dbip_util.rbs
|
47
|
+
- sig/dbip_util/version.rbs
|
48
|
+
homepage: https://github.com/rbutils/dbip_util
|
49
|
+
licenses:
|
50
|
+
- MIT + CC-BY-4.0
|
51
|
+
metadata:
|
52
|
+
homepage_uri: https://github.com/rbutils/dbip_util
|
53
|
+
source_code_uri: https://github.com/rbutils/dbip_util
|
54
|
+
changelog_uri: https://github.com/rbutils/dbip_util/blob/master/CHANGELOG.md
|
55
|
+
rubygems_mfa_required: 'true'
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 3.1.0
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubygems_version: 3.6.7
|
71
|
+
specification_version: 4
|
72
|
+
summary: DbipUtil includes DB-IP Lite databases and a simple interface to them, based
|
73
|
+
on `maxmind-db` gem
|
74
|
+
test_files: []
|