ipmax 0.1.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.
@@ -0,0 +1,571 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IPMax
4
+ module Models
5
+ module AnonymizerExemptionReason
6
+ CLOUDFLARE_CDN_ORIGIN = "cloudflare_cdn_origin"
7
+ SEARCH_ENGINE_CRAWLER = "search_engine_crawler"
8
+ end
9
+
10
+ module CpePart
11
+ APPLICATION = "application"
12
+ OPERATING_SYSTEM = "operating_system"
13
+ HARDWARE = "hardware"
14
+ end
15
+
16
+ module ErrorCode
17
+ INVALID_REQUEST = 1000
18
+ INVALID_PAYLOAD = 1001
19
+ INVALID_IP = 1002
20
+ IP_NOT_FOUND = 1003
21
+ ROUTE_NOT_FOUND = 1004
22
+ INVALID_API_KEY = 1010
23
+ RATE_LIMIT_EXCEEDED = 1011
24
+ SERVICE_UNAVAILABLE = 1400
25
+ INTERNAL_ERROR = 1401
26
+ INSUFFICIENT_BALANCE = 1500
27
+ IDEMPOTENCY_KEY_CONFLICT = 1501
28
+ end
29
+
30
+ module LiveIntelligenceTag
31
+ HOSTING = "hosting"
32
+ PUBLIC_DNS_RESOLVER = "public_dns_resolver"
33
+ WEB_SERVER = "web_server"
34
+ VPN = "vpn"
35
+ RESIDENTIAL_PROXY = "residential_proxy"
36
+ end
37
+
38
+ module NetworkClass
39
+ MOBILE = "mobile"
40
+ HOSTING = "hosting"
41
+ RESIDENTIAL = "residential"
42
+ BUSINESS = "business"
43
+ ORGANIZATION = "organization"
44
+ GOVERNMENT = "government"
45
+ MILITARY = "military"
46
+ EDUCATION = "education"
47
+ LIBRARY = "library"
48
+ DEDICATED = "dedicated"
49
+ SATELLITE = "satellite"
50
+ IXP = "ixp"
51
+ SEARCH_ENGINE = "search_engine"
52
+ AI_CRAWLER = "ai_crawler"
53
+ UNKNOWN = "unknown"
54
+ end
55
+
56
+ module NetworkClassSource
57
+ DOMESTIC_ISP = "domestic_isp"
58
+ USAGE_TYPE = "usage_type"
59
+ MOBILE_CARRIER = "mobile_carrier"
60
+ CONNECTION_TYPE = "connection_type"
61
+ NETWORK_TAG = "network_tag"
62
+ THREAT_INTELLIGENCE = "threat_intelligence"
63
+ ASN_TAG = "asn_tag"
64
+ IXP = "ixp"
65
+ NONE = "none"
66
+ end
67
+
68
+ module Product
69
+ GEOIP = "geoip"
70
+ INTELLIGENCE = "intelligence"
71
+ end
72
+
73
+ module PtrConfidenceLevel
74
+ HIGH = "high"
75
+ MEDIUM = "medium"
76
+ LOW = "low"
77
+ end
78
+
79
+ module PtrDatasetName
80
+ GEONAMES = "geonames"
81
+ OURAIRPORTS = "ourairports"
82
+ OPERATOR_OVERRIDES = "operator-overrides"
83
+ UNLOCODE = "unlocode"
84
+ end
85
+
86
+ module PtrHintKind
87
+ IATA = "iata"
88
+ UNLOCODE = "unlocode"
89
+ CLLI = "clli"
90
+ CITY_NAME = "city_name"
91
+ OPERATOR_CODE = "operator_code"
92
+ end
93
+
94
+ module RevokedNetworkTag
95
+ BUSINESS_BROADBAND = "business_broadband"
96
+ HOME_ISP = "home_isp"
97
+ MOBILE_ISP = "mobile_isp"
98
+ end
99
+
100
+ module RpkiSource
101
+ RTR_LIVE = "RTR Live"
102
+ LOCAL_CACHE = "Local Cache"
103
+ LOCAL_DB = "Local DB"
104
+ end
105
+
106
+ module RpkiStatus
107
+ VALID = "valid"
108
+ INVALID_ASN = "invalid_asn"
109
+ INVALID_LENGTH = "invalid_length"
110
+ UNKNOWN = "unknown"
111
+ NOT_ROUTED = "not_routed"
112
+ end
113
+
114
+ AbuseCategoryCount = Internal::Schema.define do
115
+ required :id, :integer
116
+ required :count, :integer
117
+ end
118
+
119
+ AbuseContact = Internal::Schema.define do
120
+ required :name, :string, null: true
121
+ required :address, :string, null: true
122
+ required :country, :string, null: true
123
+ required :email, :string, null: true
124
+ required :network, :string, null: true
125
+ required :phone, :string, null: true
126
+ optional :source, :string
127
+ end
128
+
129
+ AbuseReports = Internal::Schema.define do
130
+ required :confidence_score, :integer
131
+ required :total_reports, :integer
132
+ required :distinct_reporters, :integer
133
+ required :last_reported_at, :string, null: true
134
+ required :is_whitelisted, :boolean, null: true
135
+ required :categories, [AbuseCategoryCount]
136
+ end
137
+
138
+ Wallet = Internal::Schema.define do
139
+ required :product, :string
140
+ required :balance_micros, :float, key: "balanceMicros"
141
+ end
142
+
143
+ LedgerEntry = Internal::Schema.define do
144
+ required :id, :string
145
+ required :product, :string
146
+ required :kind, :string
147
+ required :amount_micros, :float, key: "amountMicros"
148
+ required :balance_micros, :float, key: "balanceMicros"
149
+ required :reference, :string
150
+ required :created_at, :string, key: "createdAt"
151
+ end
152
+
153
+ Account = Internal::Schema.define do
154
+ required :id, :string
155
+ required :name, :string
156
+ required :key_prefix, :string, key: "keyPrefix"
157
+ required :wallets, [Wallet]
158
+ required :entries, [LedgerEntry]
159
+ end
160
+
161
+ AccountResponse = Internal::Schema.define do
162
+ required :status, :boolean
163
+ required :data, Account
164
+ end
165
+
166
+ ApiError = Internal::Schema.define do
167
+ required :code, :integer
168
+ required :message, :string
169
+ required :request_id, :string
170
+ required :retryable, :boolean
171
+ end
172
+
173
+ ErrorResponse = Internal::Schema.define do
174
+ required :status, :boolean
175
+ required :data, :null
176
+ required :error, ApiError
177
+ end
178
+
179
+ AsnEstimatedCapacity = Internal::Schema.define do
180
+ required :lower_gbps, :float
181
+ optional :upper_gbps, :float
182
+ required :label, :string
183
+ end
184
+
185
+ AsnExchangePort = Internal::Schema.define do
186
+ required :capacity_gbps, :float
187
+ optional :operational, :boolean
188
+ optional :rs_peer, :boolean
189
+ end
190
+
191
+ AsnExchange = Internal::Schema.define do
192
+ required :name, :string
193
+ optional :country_code, :string, key: "countryCode"
194
+ required :type, :string
195
+ required :ports, [AsnExchangePort]
196
+ end
197
+
198
+ AsnConnectivity = Internal::Schema.define do
199
+ required :declared_traffic, :string
200
+ optional :exchanges_total, :integer
201
+ required :estimated_capacity, AsnEstimatedCapacity
202
+ required :exchanges, [AsnExchange]
203
+ end
204
+
205
+ Blocklist = Internal::Schema.define do
206
+ required :name, :string
207
+ required :site, :string
208
+ required :type, :string
209
+ end
210
+
211
+ Price = Internal::Schema.define do
212
+ required :product, :string
213
+ required :name, :string
214
+ required :unit_micros, :float, key: "unitMicros"
215
+ end
216
+
217
+ Catalog = Internal::Schema.define do
218
+ required :currency, :string
219
+ required :prices, [Price]
220
+ required :purchase_email, :string, key: "purchaseEmail"
221
+ required :available, :boolean
222
+ end
223
+
224
+ CatalogResponse = Internal::Schema.define do
225
+ required :status, :boolean
226
+ required :data, Catalog
227
+ end
228
+
229
+ Company = Internal::Schema.define do
230
+ required :name, :string, null: true
231
+ required :address, :string, null: true
232
+ required :domain, :string, null: true
233
+ required :phone, :string, null: true
234
+ required :type, :string, null: true
235
+ required :network, :string, null: true
236
+ required :country, :string, null: true
237
+ optional :source, :string
238
+ end
239
+
240
+ CpeObservation = Internal::Schema.define do
241
+ required :cpe, :string
242
+ required :part, :string
243
+ required :vendor, :string
244
+ required :product, :string
245
+ required :version, :string, null: true
246
+ end
247
+
248
+ Currency = Internal::Schema.define do
249
+ required :name, :string
250
+ required :code, :string
251
+ required :symbol, :string
252
+ required :native, :string
253
+ required :plural, :string
254
+ end
255
+
256
+ DnsHostnameEvidence = Internal::Schema.define do
257
+ required :hostname, :string
258
+ required :kinds, [:string]
259
+ required :sources, [:string]
260
+ required :forward_confirmed, :boolean
261
+ required :first_seen, :string, null: true
262
+ required :last_seen, :string, null: true
263
+ end
264
+
265
+ DnsPtrEvidence = Internal::Schema.define do
266
+ required :hostname, :string
267
+ required :sources, [:string]
268
+ required :forward_confirmed, :boolean
269
+ required :first_seen, :string, null: true
270
+ required :last_seen, :string, null: true
271
+ end
272
+
273
+ DnsRecords = Internal::Schema.define do
274
+ required :ptr, [:string]
275
+ required :ptr_evidence, [DnsPtrEvidence]
276
+ required :hostnames, [DnsHostnameEvidence]
277
+ required :sources, [:string]
278
+ required :snapshot_id, :string, null: true
279
+ required :updated_at, :string, null: true
280
+ end
281
+
282
+ GeoIpAs = Internal::Schema.define do
283
+ required :asn, :string
284
+ required :name, :string
285
+ optional :name_en, :string
286
+ optional :country_code, :string, key: "countryCode"
287
+ required :domain, :string
288
+ end
289
+
290
+ Geolocation = Internal::Schema.define do
291
+ required :city, :string
292
+ required :region, :string
293
+ required :district, :string
294
+ required :region_code, :string
295
+ required :adcode, :string
296
+ required :country, :string
297
+ required :country_code, :string
298
+ required :continent, :string
299
+ required :continent_code, :string
300
+ required :latitude, :float, null: true
301
+ required :longitude, :float, null: true
302
+ required :timezone, :string
303
+ required :postal_code, :string
304
+ required :radius, :float, null: true
305
+ optional :area_code, :string
306
+ optional :plus_code, :string
307
+ optional :country_en, :string
308
+ optional :country_zh, :string
309
+ optional :region_en, :string
310
+ optional :region_zh, :string
311
+ optional :city_en, :string
312
+ optional :city_zh, :string
313
+ optional :district_en, :string
314
+ optional :district_zh, :string
315
+ end
316
+
317
+ TimeZone = Internal::Schema.define do
318
+ required :name, :string
319
+ required :abbr, :string
320
+ required :offset, :string
321
+ required :is_dst, :boolean
322
+ required :current_time, :string
323
+ end
324
+
325
+ GeoIpData = Internal::Schema.define do
326
+ required :as, GeoIpAs
327
+ required :ip, :string
328
+ required :geo, Geolocation
329
+ required :netmask, :string
330
+ required :prefix_length, :integer, null: true
331
+ required :is_bogon, :boolean
332
+ optional :currency, Currency
333
+ optional :time_zone, TimeZone
334
+ optional :calling_code, :string
335
+ end
336
+
337
+ GeoIpResponse = Internal::Schema.define do
338
+ required :status, :boolean
339
+ required :data, GeoIpData
340
+ end
341
+
342
+ IntelligenceAs = Internal::Schema.define do
343
+ required :asn, :string
344
+ required :name, :string
345
+ optional :name_en, :string
346
+ optional :country_code, :string, key: "countryCode"
347
+ required :domain, :string
348
+ required :type, :string
349
+ optional :as_class, :string, key: "class"
350
+ optional :tags, [:string]
351
+ optional :connectivity, AsnConnectivity
352
+ end
353
+
354
+ MobileCarrier = Internal::Schema.define do
355
+ required :mcc, :string
356
+ required :mnc, :string
357
+ required :brand, :string
358
+ end
359
+
360
+ NetworkClassEvidence = Internal::Schema.define do
361
+ required :network_class, :string, key: "class"
362
+ required :source, :string
363
+ required :scope, :string
364
+ required :value, :string
365
+ end
366
+
367
+ NetworkClassification = Internal::Schema.define do
368
+ required :primary, :string
369
+ required :confidence, :string
370
+ required :source, :string
371
+ required :conflicts, [:string]
372
+ required :evidence, [NetworkClassEvidence]
373
+ end
374
+
375
+ NetworkInfo = Internal::Schema.define do
376
+ required :connection_type, :string
377
+ required :usage_type, :string
378
+ optional :address_type, :string
379
+ required :net_speed, :string
380
+ required :tags, [:string]
381
+ end
382
+
383
+ PtrOperator = Internal::Schema.define do
384
+ required :name, :string
385
+ required :asn, :string
386
+ required :suffix, :string
387
+ end
388
+
389
+ PtrHint = Internal::Schema.define do
390
+ required :value, :string
391
+ required :kind, :string
392
+ end
393
+
394
+ PtrMetroLocation = Internal::Schema.define do
395
+ required :city, :string
396
+ required :region, :string, null: true
397
+ required :region_code, :string, null: true
398
+ required :country, :string
399
+ required :country_code, :string
400
+ required :latitude, :float
401
+ required :longitude, :float
402
+ required :precision, :string
403
+ end
404
+
405
+ PtrConfidence = Internal::Schema.define do
406
+ required :level, :string
407
+ required :score, :float
408
+ end
409
+
410
+ PtrEvidenceSource = Internal::Schema.define do
411
+ required :dataset, :string
412
+ required :version, :string
413
+ end
414
+
415
+ PtrEvidence = Internal::Schema.define do
416
+ required :rule_id, :string
417
+ required :ruleset_version, :string
418
+ required :sources, [PtrEvidenceSource]
419
+ end
420
+
421
+ module PtrIntelligence; end
422
+
423
+ PtrLocatedIntelligence = Internal::Schema.define(PtrIntelligence) do
424
+ required :hostname, :string
425
+ required :status, :string
426
+ required :operator, PtrOperator
427
+ required :hint, PtrHint
428
+ required :location, PtrMetroLocation
429
+ required :confidence, PtrConfidence
430
+ required :evidence, PtrEvidence
431
+ end
432
+
433
+ PtrAsnMismatchIntelligence = Internal::Schema.define(PtrIntelligence) do
434
+ required :hostname, :string
435
+ required :status, :string
436
+ required :operator, PtrOperator
437
+ required :observed_asn, :string
438
+ required :evidence, PtrEvidence
439
+ end
440
+
441
+ PtrUnmatchedIntelligence = Internal::Schema.define(PtrIntelligence) do
442
+ required :hostname, :string
443
+ required :status, :string
444
+ end
445
+
446
+ PtrOtherIntelligence = Internal::Schema.define(PtrIntelligence) do
447
+ required :hostname, :string
448
+ required :status, :string
449
+ end
450
+
451
+ Internal::Schema.union(
452
+ PtrIntelligence,
453
+ tag: "status",
454
+ variants: {
455
+ "located" => PtrLocatedIntelligence,
456
+ "asn_mismatch" => PtrAsnMismatchIntelligence,
457
+ "unmatched" => PtrUnmatchedIntelligence
458
+ },
459
+ fallback: PtrOtherIntelligence
460
+ )
461
+
462
+ ResourceTransfer = Internal::Schema.define do
463
+ required :transfer_time, :string
464
+ required :transfer_type, :string
465
+ required :source_resource, :string
466
+ required :recipient_resource, :string
467
+ required :source_registry, :string
468
+ required :recipient_registry, :string
469
+ required :source_holder, :string
470
+ required :recipient_holder, :string
471
+ end
472
+
473
+ RpkiRtr = Internal::Schema.define do
474
+ required :source, :string
475
+ optional :server, :string
476
+ required :last_updated, :integer, key: "lastUpdated"
477
+ end
478
+
479
+ RpkiValidator = Internal::Schema.define do
480
+ required :source, :string
481
+ required :engine, :string
482
+ required :last_updated, :integer, key: "lastUpdated"
483
+ end
484
+
485
+ RpkiInfo = Internal::Schema.define do
486
+ required :status, :string
487
+ optional :source, :string
488
+ optional :route_source, :string
489
+ optional :origin_asn, :string
490
+ optional :route_prefix, :string
491
+ optional :roa_prefix, :string
492
+ optional :roa_asn, :string
493
+ optional :max_length, :integer
494
+ optional :ta, :string
495
+ optional :rtr, RpkiRtr
496
+ optional :validator, RpkiValidator
497
+ end
498
+
499
+ SegmentProbe = Internal::Schema.define do
500
+ required :ip, :string
501
+ required :ports, [:integer]
502
+ required :tags, [:string]
503
+ end
504
+
505
+ LiveIntelligence = Internal::Schema.define do
506
+ required :ptr, [PtrIntelligence]
507
+ required :nameservers, [:string]
508
+ required :cpes, [CpeObservation]
509
+ required :tags, [:string]
510
+ required :revoked_tags, [:string]
511
+ required :usage_type, :string, null: true
512
+ optional :rpki, RpkiInfo
513
+ optional :abuse, AbuseReports
514
+ optional :transfers, [ResourceTransfer]
515
+ optional :segment_probe, SegmentProbe
516
+ end
517
+
518
+ ThreatScores = Internal::Schema.define do
519
+ required :vpn_score, :float, null: true
520
+ required :proxy_score, :float, null: true
521
+ required :threat_score, :float, null: true
522
+ required :trust_score, :float, null: true
523
+ end
524
+
525
+ ThreatInfo = Internal::Schema.define do
526
+ required :is_tor, :boolean, null: true
527
+ required :is_vpn, :boolean, null: true
528
+ required :is_icloud_relay, :boolean, null: true
529
+ required :is_cloudflare_warp, :boolean, null: true
530
+ required :is_proxy, :boolean, null: true
531
+ required :is_datacenter, :boolean, null: true
532
+ required :is_anonymous, :boolean, null: true
533
+ required :is_known_attacker, :boolean, null: true
534
+ required :is_known_abuser, :boolean, null: true
535
+ required :is_threat, :boolean, null: true
536
+ required :is_bogon, :boolean
537
+ required :blocklists, [Blocklist]
538
+ required :blocklist_count, :integer
539
+ required :scores, ThreatScores
540
+ optional :anonymizer_exemptions, [:string]
541
+ end
542
+
543
+ IntelligenceData = Internal::Schema.define do
544
+ required :as, IntelligenceAs
545
+ required :intelligence, LiveIntelligence
546
+ required :ip, :string
547
+ optional :network, NetworkInfo
548
+ required :network_class, NetworkClassification
549
+ optional :mobile, MobileCarrier
550
+ optional :threat, ThreatInfo
551
+ optional :rpki, RpkiInfo
552
+ optional :company, Company
553
+ optional :abuse, AbuseContact
554
+ optional :dns, DnsRecords
555
+ required :is_bogon, :boolean
556
+ required :is_anycast, :boolean, null: true
557
+ required :is_mobile, :boolean, null: true
558
+ required :is_hosting, :boolean, null: true
559
+ required :is_satellite, :boolean, null: true
560
+ end
561
+
562
+ IntelligenceResponse = Internal::Schema.define do
563
+ required :status, :boolean
564
+ required :data, IntelligenceData
565
+ end
566
+
567
+ LookupRequest = Internal::Schema.define do
568
+ required :ip, :string
569
+ end
570
+ end
571
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IPMax
4
+ VERSION = "0.1.0"
5
+ end
data/lib/ipmax.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ipmax/version"
4
+ require_relative "ipmax/errors"
5
+ require_relative "ipmax/internal/schema"
6
+ require_relative "ipmax/internal/lru_cache"
7
+ require_relative "ipmax/models"
8
+ require_relative "ipmax/client"
9
+
10
+ module IPMax
11
+ private_constant :Internal
12
+ end