internetdata 2.14.0 → 2.14.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4970702debf09c79f00493d0ff6a59b21123adc8910c20b1e8eccf84a9426d9
4
- data.tar.gz: d0129f3c6b45bf11580de092a24252bcdcb6ba6a7f945c14931fe290d801afbf
3
+ metadata.gz: ea13c3d6065537652f90e6822f04fc01e280feddb4cbb29c800387a491933e0d
4
+ data.tar.gz: baa7ad7ecf3543c5fa07e6a4de82c7d19099cb1d3a22dfa54bf6d49d5cf9ed0d
5
5
  SHA512:
6
- metadata.gz: a222b7919d2d2a74b6827647af4647d9855c146a8a7c8114c252a1ce1da549ddb1ef0327596ddbec43a0810990d04622107dd27a8ff8d29631158c8f0e9d0d1e
7
- data.tar.gz: 01e77b6e521bd326582ccd65320d68671aa1219c87f5a907f86eca85f60f90cf26ed518bfecf70d7527f1192f97191422b4bfa6baa208b4955fd790a30a2f9d0
6
+ metadata.gz: fd2eb6fbbd752fb717994a6a1153106e29fba0c0adb6070d40752ba9b05d9059867c32a6a156b66f59cd30ecc993c3a71291f1ff3d9f035ad112d9157c17f372
7
+ data.tar.gz: 8f0ec231513b532c6f09824a8f92937f4750d109711c0419ebeefed67b0cfc71af1dc5a31369626f50ed83f46f2fe8ae39776e87a7982f062b445afb5bca47ce
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  The official Ruby client library for the [InternetData](https://internetdata.io) API.
7
7
 
8
- InternetData publishes IP and ASN databases: geolocation, anonymity, ownership and network data, as gzipped CSV and as MMDB. This library looks an IP address, an AS or a domain up in all of them at once, and downloads the databases your organization is licensed for.
8
+ It tells you what every InternetData database says about an IP address, an AS or a domain: where it is, who runs it, whether it is a VPN, proxy, Tor node or hosting server, and what it serves. It also downloads the databases your organization is licensed for.
9
9
 
10
10
  ## Getting Started
11
11
 
@@ -19,7 +19,7 @@ Or add it to your Gemfile:
19
19
  gem 'internetdata'
20
20
  ```
21
21
 
22
- Requires Ruby 3.3 or newer.
22
+ Requires Ruby 3.3 or newer, and libcurl at runtime, which the `curl` package brings on Debian and Alpine.
23
23
 
24
24
  ## Usage
25
25
 
@@ -270,7 +270,7 @@ raise 'no API key was picked' if token.apikey.nil?
270
270
  keyed = InternetData::Client.new(api_key: token.apikey)
271
271
  ```
272
272
 
273
- `poll_device_token` raises `InternetData::OauthAccessDeniedError` when the person refuses and `InternetData::OauthExpiredTokenError` when the code expires first. Client IDs are issued on request from support@internetdata.io, and `client.oauth.revoke('your-client-id', token.refresh_token)` signs the machine out.
273
+ `poll_device_token` raises `InternetData::OauthAccessDeniedError` when the person refuses and `InternetData::OauthExpiredTokenError` when the code expires first. `client.oauth.revoke('your-client-id', token.refresh_token)` signs the machine out. Only a client we registered, such as our CLI, can use the device flow: an app of your own signs people in with the authorization code flow below.
274
274
 
275
275
  ### Sign in with OAuth (authorization code)
276
276
 
@@ -9,19 +9,37 @@ module InternetData
9
9
  # different plans and entitled to different fields, so a shared cache would
10
10
  # serve one of them the other's shape. Errors are never stored and bogons
11
11
  # never reach it.
12
+ #
13
+ # A reduced answer, a spent trial's or a reached cap's, ends with a new UTC day
14
+ # or a raised cap, so it stays a minute at most rather than the TTL. It is
15
+ # still cached, or a busy process would send every repeat to the API.
12
16
  class Cache
17
+ # The longest a spent trial's or a reached cap's answer is held, in seconds.
18
+ REDUCED_TTL = 60
19
+
13
20
  def initialize(max_size:, ttl:)
14
21
  raise ArgumentError, 'cache_max_size must be positive' unless max_size.to_i.positive?
15
22
 
23
+ @ttl = ttl
16
24
  @store = LruRedux::TTL::ThreadSafeCache.new(max_size.to_i, ttl)
17
25
  end
18
26
 
19
27
  def get(key)
20
- @store[key]
28
+ value, expires = @store[key]
29
+ return nil if expires.nil?
30
+ return value if now < expires
31
+
32
+ @store.delete(key)
33
+ nil
21
34
  end
22
35
 
23
36
  def set(key, value)
24
- @store[key] = value
37
+ @store[key] = [value, now + life_of(value)]
38
+ end
39
+
40
+ # When the answer held for `key` goes stale, on the monotonic clock, or nil.
41
+ def expiry(key)
42
+ @store[key]&.last
25
43
  end
26
44
 
27
45
  def clear
@@ -31,5 +49,16 @@ module InternetData
31
49
  def size
32
50
  @store.count
33
51
  end
52
+
53
+ private
54
+
55
+ def life_of(value)
56
+ reduced = value.respond_to?(:trial_expired?) && (value.trial_expired? || value.cap_reached?)
57
+ reduced ? [@ttl, REDUCED_TTL].min : @ttl
58
+ end
59
+
60
+ def now
61
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
62
+ end
34
63
  end
35
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InternetData
4
- VERSION = '2.14.0'
4
+ VERSION = '2.14.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: internetdata
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.14.0
4
+ version: 2.14.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mslm Dev