internetdata 2.14.1 → 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 +4 -4
- data/README.md +3 -3
- data/lib/internetdata/cache.rb +31 -2
- data/lib/internetdata/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ea13c3d6065537652f90e6822f04fc01e280feddb4cbb29c800387a491933e0d
|
|
4
|
+
data.tar.gz: baa7ad7ecf3543c5fa07e6a4de82c7d19099cb1d3a22dfa54bf6d49d5cf9ed0d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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.
|
|
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
|
|
data/lib/internetdata/cache.rb
CHANGED
|
@@ -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
|
data/lib/internetdata/version.rb
CHANGED