sockudo 1.0.0 → 2.0.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 +25 -3
- data/lib/sockudo/channel.rb +79 -7
- data/lib/sockudo/client.rb +293 -79
- data/lib/sockudo/request.rb +72 -37
- data/lib/sockudo/resource.rb +11 -5
- data/lib/sockudo/utils.rb +5 -3
- data/lib/sockudo/version.rb +3 -1
- data/lib/sockudo/webhook.rb +24 -24
- data/lib/sockudo.rb +20 -4
- metadata +61 -35
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: df118e329c06d4ea98bd91c7c8bd83acb02d71e298b7ab9ae221951dfb13e5cc
|
|
4
|
+
data.tar.gz: 68c93f6cb05098c675aa8d5f2fef62073dbb8b3494084f49fc7e7cc4e1969cd7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0fddc588e36a86757e096fa8fa632cdd250e581dc566b9d0b386ddb31d34fca047f132b49cdc341876da20227c57fb51e52879afef60612707156fb00fb73012
|
|
7
|
+
data.tar.gz: f2b7d1566c2f14b01b5b43071f0093b4bd50d0efa79a4b2f9426111eb3802de773e8aa03ff8ee2f0aad618b0e5b52b4a8a84b4d9524646496d8e42530f0b5a52
|
data/README.md
CHANGED
|
@@ -15,10 +15,12 @@ Add to your Gemfile:
|
|
|
15
15
|
gem 'sockudo'
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
Then run `bundle install
|
|
18
|
+
Then run `bundle install`.
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
For local monorepo development, use:
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
gem 'sockudo', path: '../sockudo/server-sdks/sockudo-http-ruby'
|
|
22
24
|
```
|
|
23
25
|
|
|
24
26
|
## Getting Started
|
|
@@ -200,6 +202,26 @@ user_count = info[:user_count]
|
|
|
200
202
|
# List channels (optionally filtered)
|
|
201
203
|
result = sockudo.channels(filter_by_prefix: 'presence-')
|
|
202
204
|
|
|
205
|
+
# Read channel history with newest-first pagination
|
|
206
|
+
page = sockudo.channel_history('my-channel', limit: 50, direction: 'newest_first')
|
|
207
|
+
next_cursor = page[:next_cursor]
|
|
208
|
+
|
|
209
|
+
# Continue pagination with an opaque cursor
|
|
210
|
+
page_2 = sockudo.channel_history('my-channel', cursor: next_cursor)
|
|
211
|
+
|
|
212
|
+
# Read presence history for a presence channel
|
|
213
|
+
presence_page = sockudo.channel_presence_history(
|
|
214
|
+
'presence-my-channel',
|
|
215
|
+
limit: 50,
|
|
216
|
+
direction: 'newest_first'
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
# Reconstruct effective members at a point in time
|
|
220
|
+
snapshot = sockudo.channel_presence_snapshot(
|
|
221
|
+
'presence-my-channel',
|
|
222
|
+
at_serial: 4
|
|
223
|
+
)
|
|
224
|
+
|
|
203
225
|
# Users in a presence channel
|
|
204
226
|
result = sockudo.channel_users('presence-my-channel')
|
|
205
227
|
```
|
data/lib/sockudo/channel.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'openssl'
|
|
2
4
|
require 'multi_json'
|
|
3
5
|
|
|
@@ -5,7 +7,8 @@ module Sockudo
|
|
|
5
7
|
# Delegates operations for a specific channel from a client
|
|
6
8
|
class Channel
|
|
7
9
|
attr_reader :name
|
|
8
|
-
|
|
10
|
+
|
|
11
|
+
INVALID_CHANNEL_REGEX = /[^A-Za-z0-9_\-=@,.;:]/.freeze
|
|
9
12
|
|
|
10
13
|
def initialize(_, name, client = Sockudo)
|
|
11
14
|
if Sockudo::Channel::INVALID_CHANNEL_REGEX.match(name)
|
|
@@ -13,6 +16,7 @@ module Sockudo
|
|
|
13
16
|
elsif name.length > 200
|
|
14
17
|
raise Sockudo::Error, "Channel name too long (limit 164 characters) '#{name}'"
|
|
15
18
|
end
|
|
19
|
+
|
|
16
20
|
@name = name
|
|
17
21
|
@client = client
|
|
18
22
|
end
|
|
@@ -95,7 +99,77 @@ module Sockudo
|
|
|
95
99
|
# @raise [Sockudo::HTTPError] on any error raised inside http client - the original error is available in the original_error attribute
|
|
96
100
|
#
|
|
97
101
|
def info(attributes = [])
|
|
98
|
-
@client.channel_info(name, :
|
|
102
|
+
@client.channel_info(name, info: attributes.join(','))
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Request durable history for this channel.
|
|
106
|
+
#
|
|
107
|
+
# @param params [Hash] History API query params. Supported keys include:
|
|
108
|
+
# :limit, :direction, :cursor, :start_serial, :end_serial, :start_time_ms, :end_time_ms
|
|
109
|
+
# @return [Hash] History page payload for this channel
|
|
110
|
+
#
|
|
111
|
+
def history(params = {})
|
|
112
|
+
@client.channel_history(name, params)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Request presence history for a presence channel.
|
|
116
|
+
#
|
|
117
|
+
# @param params [Hash] Presence history API query params. Supported keys include:
|
|
118
|
+
# :limit, :direction, :cursor, :start_serial, :end_serial, :start_time_ms, :end_time_ms
|
|
119
|
+
# @return [Hash] Presence history page payload for this channel
|
|
120
|
+
#
|
|
121
|
+
def presence_history(params = {})
|
|
122
|
+
@client.channel_presence_history(name, params)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Request a reconstructed presence snapshot for a presence channel.
|
|
126
|
+
#
|
|
127
|
+
# @param params [Hash] Snapshot API query params. Supported keys include:
|
|
128
|
+
# :at_time_ms, :at_serial
|
|
129
|
+
# @return [Hash] Presence snapshot payload for this channel
|
|
130
|
+
#
|
|
131
|
+
def presence_snapshot(params = {})
|
|
132
|
+
@client.channel_presence_snapshot(name, params)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Fetch the latest visible version of a mutable message.
|
|
136
|
+
def get_message(message_serial)
|
|
137
|
+
@client.get_message(name, message_serial)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Fetch preserved versions of a mutable message.
|
|
141
|
+
def get_message_versions(message_serial, params = {})
|
|
142
|
+
@client.get_message_versions(name, message_serial, params)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Apply a mutable-message update.
|
|
146
|
+
def update_message(message_serial, params = {})
|
|
147
|
+
@client.update_message(name, message_serial, params)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Apply a mutable-message delete.
|
|
151
|
+
def delete_message(message_serial, params = {})
|
|
152
|
+
@client.delete_message(name, message_serial, params)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Apply a mutable-message append.
|
|
156
|
+
def append_message(message_serial, params = {})
|
|
157
|
+
@client.append_message(name, message_serial, params)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Publish an annotation for a versioned message.
|
|
161
|
+
def publish_annotation(message_serial, params = {})
|
|
162
|
+
@client.publish_annotation(name, message_serial, params)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Delete an annotation from a versioned message.
|
|
166
|
+
def delete_annotation(message_serial, annotation_serial, params = {})
|
|
167
|
+
@client.delete_annotation(name, message_serial, annotation_serial, params)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# List raw annotation events for a versioned message.
|
|
171
|
+
def list_annotations(message_serial, params = {})
|
|
172
|
+
@client.list_annotations(name, message_serial, params)
|
|
99
173
|
end
|
|
100
174
|
|
|
101
175
|
# Request users for a presence channel
|
|
@@ -126,7 +200,7 @@ module Sockudo
|
|
|
126
200
|
# @raise [Sockudo::Error] if socket_id or custom_string invalid
|
|
127
201
|
#
|
|
128
202
|
def authentication_string(socket_id, custom_string = nil)
|
|
129
|
-
string_to_sign = [socket_id, name, custom_string].compact.
|
|
203
|
+
string_to_sign = [socket_id, name, custom_string].compact.join(':')
|
|
130
204
|
|
|
131
205
|
_authentication_string(socket_id, string_to_sign, @client.authentication_token, custom_string)
|
|
132
206
|
end
|
|
@@ -158,7 +232,7 @@ module Sockudo
|
|
|
158
232
|
def authenticate(socket_id, custom_data = nil)
|
|
159
233
|
custom_data = MultiJson.encode(custom_data) if custom_data
|
|
160
234
|
auth = authentication_string(socket_id, custom_data)
|
|
161
|
-
r = {:auth
|
|
235
|
+
r = { auth: auth }
|
|
162
236
|
r[:channel_data] = custom_data if custom_data
|
|
163
237
|
r
|
|
164
238
|
end
|
|
@@ -167,13 +241,11 @@ module Sockudo
|
|
|
167
241
|
return unless encryption_master_key
|
|
168
242
|
|
|
169
243
|
secret_string = @name + encryption_master_key
|
|
170
|
-
digest = OpenSSL::Digest
|
|
244
|
+
digest = OpenSSL::Digest.new('SHA256')
|
|
171
245
|
digest << secret_string
|
|
172
246
|
digest.digest
|
|
173
247
|
end
|
|
174
248
|
|
|
175
|
-
private
|
|
176
|
-
|
|
177
249
|
include Sockudo::Utils
|
|
178
250
|
end
|
|
179
251
|
end
|