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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6157ddaca572a6fdbec4f07bb91cdcecd4d21bc888a8641e7961411f6e164ea5
4
- data.tar.gz: 1fd6bb9d10a79748fb42f053950f3fd4dbe64aaae36b2c9d6c3ab88bf9981594
3
+ metadata.gz: 783a1de4060fb26d882a1c31aa946d6335be9877da416f0b95712830b5af46b0
4
+ data.tar.gz: c7eca2b3d6a11c1e5e96b285845458077189645fbdb8ebb28eb63805f5726d75
5
5
  SHA512:
6
- metadata.gz: 283bda9e8965585d5e110427a3fff75b2e85c437f5f11e2c0eb3fd956adf3d31b8cfb2561ba3c719d339f9e2c11605df54f8c49b67f341e3ba4a4ead8c38474c
7
- data.tar.gz: 17ee516cbafe10ee08649833d59813c3e1f81c1650c950c99c17ac5bedfeaa18972d09c234eacdc1a26fb71a00301bfe686602146fda17c498362784bf397e92
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
- call { redirect_location(id, format, timeout) }
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
- def download(id, format, path)
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
- def download_bytes(id, format)
112
- url = download_url(id, format)
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
- def redirect_location(id, format, timeout)
196
- _, status, = @api.download_database_v2_with_http_info(id, format, timeout: timeout)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InternetData
4
- VERSION = '2.8.8'
4
+ VERSION = '2.9.0'
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.8.8
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mslm Dev