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 +4 -4
- data/README.md +1 -1
- data/lib/e621stream/client.rb +13 -4
- data/lib/e621stream/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: '08ef4491a9583e9ec39053e925526b63b55e93832dcdd3a7d72abe30f3328f1a'
|
|
4
|
+
data.tar.gz: b068046e0a4e360846adbdd1ef8ea31ca0dde651dbee9047f2947f133d59a866
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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
|
data/lib/e621stream/client.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
|
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
|
data/lib/e621stream/version.rb
CHANGED