e621stream 0.0.4 → 0.0.5

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: '058c7ea74d261c3f1012be05f6b7d200551d54bfd197a48a8222b235848866e1'
4
- data.tar.gz: f6b4f2e3065eb0b58a09e5df28f561e77e0b9ed49d202506a8684e5f73bb24d0
3
+ metadata.gz: '08ef4491a9583e9ec39053e925526b63b55e93832dcdd3a7d72abe30f3328f1a'
4
+ data.tar.gz: b068046e0a4e360846adbdd1ef8ea31ca0dde651dbee9047f2947f133d59a866
5
5
  SHA512:
6
- metadata.gz: 64620623caeb76829554793a7a7096fd2963702cb47de459634932d71c8d7c0735972c9111b8ab7baccded276978b7bb391c492a0097bf83f75cc24d61d2b726
7
- data.tar.gz: 5a9a4c6718aa17e1cb918e995758ff68794ad824b2e65c72e727f42add2a1e39ab1555ad3dc5efcbad4449d65593fe8e9d75abdc250ec750e5c2cd5b7a08757e
6
+ metadata.gz: cd1cd57370807d2e3d268022fe2b4720288698de0543199a3dc0dcada3475750823192caa359b4f5013e90d7f97d4622837bb0a22ad723eb62467cc59b9e975a
7
+ data.tar.gz: 6cc7e3d99f09660f6bbe41802eec4ee2f50e90d891433cd43c4bd8e735ecf40f66e0a4b203bf5eed64289deaf1b4ef04de108bfdbd9ee165bee01dda2f3aa906
data/README.md CHANGED
@@ -30,7 +30,7 @@ Instead of `username:` & `api_key:`, you can pass `token:` with a token from [/a
30
30
 
31
31
  It reconnects when the connection drops (`reconnect: false` turns that off), and picks up from `client.cursor`. Pass `cursor:` to replay from an event id or ms timestamp. `url:` is the site (`https://e621.stream`), the websocket url comes from its `/info`, or pass a `ws://`/`wss://` url to connect to it directly. `client.subscribe([...])` changes subscriptions. Private events like `dmail.create` have to be subscribed to by name.
32
32
 
33
- `client.snapshots(resource, ids) { |snapshots| ... }` gets what was last seen of up to 100 records (see [Snapshots](https://e621.stream/snapshots/)), by id, nil for ones that aren't known. Only after `:ready`, and the block is dropped if the connection closes first.
33
+ `client.snapshots(resource, ids) { |snapshots| ... }` gets what was last seen of up to 1000 records (see [Snapshots](https://e621.stream/snapshots/)), by id, nil for ones that aren't known. Only after `:ready`, and the block is dropped if the connection closes first.
34
34
 
35
35
  ```ruby
36
36
  client.on(:ready) do
@@ -87,7 +87,8 @@ module E621Stream
87
87
  @last_error = T.let(nil, T.nilable(StreamError))
88
88
  @ready = T.let(false, T::Boolean)
89
89
  @nonce = T.let(0, Integer)
90
- @pending_snapshots = T.let({}, T::Hash[String, SnapshotCallback])
90
+ # the callback and what's been received so far, big requests come back in chunks
91
+ @pending_snapshots = T.let({}, T::Hash[String, [SnapshotCallback, Snapshots]])
91
92
  end
92
93
 
93
94
  # Listens for an event type (like "post.create"), or one of :dispatch (every event), :ready, :replay_complete,
@@ -129,7 +130,7 @@ module E621Stream
129
130
  send_message({ op: "subscribe", d: { subscriptions: subscriptions } })
130
131
  end
131
132
 
132
- # Looks up what was last seen of up to 100 records, see https://e621.stream/snapshots/. The block gets them by id,
133
+ # Looks up what was last seen of up to 1000 records, see https://e621.stream/snapshots/. The block gets them by id,
133
134
  # nil for ones that aren't known. It isn't called if the connection closes first.
134
135
  #
135
136
  # client.on(:ready) { client.snapshots("post", [1, 2]) { |posts| p(posts[1]&.dig("tags", "general")) } }
@@ -138,7 +139,7 @@ module E621Stream
138
139
  raise("not ready") unless @ready
139
140
 
140
141
  nonce = (@nonce += 1).to_s
141
- @pending_snapshots[nonce] = block
142
+ @pending_snapshots[nonce] = [block, {}]
142
143
  send_message({ op: "snapshot", d: { resource: resource, ids: ids, nonce: nonce } })
143
144
  end
144
145
 
@@ -221,7 +222,15 @@ module E621Stream
221
222
  when "subscribed"
222
223
  emit("subscribed", data["subscriptions"])
223
224
  when "snapshot"
224
- @pending_snapshots.delete(data["nonce"])&.call(data["snapshots"].to_h { |id, snapshot| [id.to_i, snapshot] })
225
+ pending = @pending_snapshots[data["nonce"]]
226
+ return unless pending
227
+
228
+ data["snapshots"].each { |id, snapshot| pending[1][id.to_i] = snapshot }
229
+ # older servers don't send done
230
+ return if data["done"] == false
231
+
232
+ @pending_snapshots.delete(data["nonce"])
233
+ pending[0].call(pending[1])
225
234
  when "error"
226
235
  @last_error = StreamError.new(data["code"], data["message"])
227
236
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module E621Stream
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: e621stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donovan_DMC