internetdata 2.8.8 → 2.9.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/README.md +8 -0
- data/lib/internetdata/database_api.rb +29 -8
- 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: 783a1de4060fb26d882a1c31aa946d6335be9877da416f0b95712830b5af46b0
|
|
4
|
+
data.tar.gz: c7eca2b3d6a11c1e5e96b285845458077189645fbdb8ebb28eb63805f5726d75
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0995aa306107ade8ade8f92244a173dda410f2ea4bb46f4a8d06f0f9c85f3f51e7e8fb5e2661974c411dcdb572440fc71c3111cc84d1e3f5abc6b4c506e01eae'
|
|
7
|
+
data.tar.gz: 7c032b9d82262035aefe193f3f67dbd82e012771e0a65a55b2bcffea594595a38311cd1c9a27c65e26e2fa24b6ac7ca879555e2a743546355027901601f2f87c
|
data/README.md
CHANGED
|
@@ -75,6 +75,14 @@ bytes = client.database.download_bytes('bogon_asn_v1', 'csvgz')
|
|
|
75
75
|
|
|
76
76
|
`download_bytes` holds the whole file in memory and the catalog spans seven orders of magnitude, from a few hundred bytes to over 5 GiB, so use `download` for anything you have not checked with `metadata` first.
|
|
77
77
|
|
|
78
|
+
Each of the three downloads the build that is live unless you name one. A `database.updated` webhook names the build it announces and carries its `sha256`, so a receiver that downloads after the next publish asks for that build to get the file the hash is of:
|
|
79
|
+
|
|
80
|
+
```ruby
|
|
81
|
+
client.database.download('vpn_ip_v1', 'mmdb', './vpn_ip_v1.mmdb', build: event['data']['build'])
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
A build is kept 7 days. Past that the call raises `bad_request` with the message `BUILD_GONE`, and downloading without `build:` fetches the live one. A name that is not a build's shape (`20261105.0t53s5`) raises `ArgumentError` before anything is sent.
|
|
85
|
+
|
|
78
86
|
### Verifying what you got
|
|
79
87
|
|
|
80
88
|
```ruby
|
|
@@ -73,12 +73,18 @@ module InternetData
|
|
|
73
73
|
# link authorizes the START of a transfer, so one already running is not
|
|
74
74
|
# interrupted when it lapses.
|
|
75
75
|
#
|
|
76
|
+
# @param build [String, nil] one build of the database, as a
|
|
77
|
+
# `database.updated` webhook names it (`20261105.0t53s5`), so the file is
|
|
78
|
+
# the one whose `sha256` the webhook carries. nil or empty, the default, is
|
|
79
|
+
# the build that is live. A build is kept 7 days; past that the call raises
|
|
80
|
+
# `bad_request` with the message `BUILD_GONE`.
|
|
76
81
|
# @param timeout [Numeric, nil] seconds this attempt may take, for THIS call
|
|
77
82
|
# only. It bounds the request that MINTS the link, which is an ordinary
|
|
78
83
|
# JSON call, and says nothing about the transfer you then run with it.
|
|
79
|
-
def download_url(id, format, timeout: nil)
|
|
84
|
+
def download_url(id, format, build: nil, timeout: nil)
|
|
80
85
|
check_format!(format)
|
|
81
|
-
|
|
86
|
+
build = checked_build(build)
|
|
87
|
+
call { redirect_location(id, format, build, timeout) }
|
|
82
88
|
end
|
|
83
89
|
|
|
84
90
|
# Download one database file to `path`, and return the bytes written.
|
|
@@ -88,10 +94,13 @@ module InternetData
|
|
|
88
94
|
# whole database, and a refresh that fails does not destroy the copy already
|
|
89
95
|
# there. Nothing beyond one chunk is ever held in memory, whatever the
|
|
90
96
|
# database weighs.
|
|
91
|
-
|
|
97
|
+
#
|
|
98
|
+
# @param build [String, nil] one build of the database, as `download_url`
|
|
99
|
+
# takes it.
|
|
100
|
+
def download(id, format, path, build: nil)
|
|
92
101
|
partial = "#{path}.part"
|
|
93
102
|
begin
|
|
94
|
-
url = download_url(id, format)
|
|
103
|
+
url = download_url(id, format, build: build)
|
|
95
104
|
written = File.open(partial, 'wb') { |file| transfer(url) { |chunk| file.write(chunk) } }
|
|
96
105
|
File.rename(partial, path)
|
|
97
106
|
rescue StandardError
|
|
@@ -108,8 +117,11 @@ module InternetData
|
|
|
108
117
|
# published database is over 5 GiB. Reach for it at the small end, where the
|
|
109
118
|
# bytes go straight into a parser, and use {#download} for anything you have
|
|
110
119
|
# not measured with {#metadata}.
|
|
111
|
-
|
|
112
|
-
|
|
120
|
+
#
|
|
121
|
+
# @param build [String, nil] one build of the database, as `download_url`
|
|
122
|
+
# takes it.
|
|
123
|
+
def download_bytes(id, format, build: nil)
|
|
124
|
+
url = download_url(id, format, build: build)
|
|
113
125
|
bytes = String.new(encoding: Encoding::BINARY)
|
|
114
126
|
transfer(url) { |chunk| bytes << chunk }
|
|
115
127
|
bytes
|
|
@@ -192,8 +204,17 @@ module InternetData
|
|
|
192
204
|
"invalid value for \"format\", must be one of #{DatabaseFormat.all_vars}"
|
|
193
205
|
end
|
|
194
206
|
|
|
195
|
-
|
|
196
|
-
|
|
207
|
+
# nil for an empty name, so a value read from an unset setting downloads the
|
|
208
|
+
# live build.
|
|
209
|
+
def checked_build(build)
|
|
210
|
+
return nil if build.nil? || build == ''
|
|
211
|
+
raise ArgumentError, "build must be a String, not #{build.inspect}" unless build.is_a?(String)
|
|
212
|
+
|
|
213
|
+
build
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def redirect_location(id, format, build, timeout)
|
|
217
|
+
_, status, = @api.download_database_v2_with_http_info(id, format, build: build, timeout: timeout)
|
|
197
218
|
raise Error.new(:server_error, 'expected a redirect to object storage', status: status)
|
|
198
219
|
rescue ApiError => e
|
|
199
220
|
raise unless e.code == 302
|
data/lib/internetdata/version.rb
CHANGED