protocol-websocket 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c466ba64c434d16b197dacfb48341ab14eca48ba5aefde4cf06df4f10be84fc
4
- data.tar.gz: 3d470e57b3c94936ec31adce97e829550344e6345de423f0d3c51915d951d782
3
+ metadata.gz: 0ca30621d2f489b08f475047f539d2fe048661dbe2b109a8d0ef441c6e95ed37
4
+ data.tar.gz: fe325e6b9041103c704cf912f73f3838c2e9d50af6368b2db54e280906600aa4
5
5
  SHA512:
6
- metadata.gz: 271a7a12c932857ea8887e67d7303a008852cc700e2d3bea0cbf96a6f30c53b8cae442f62877f4ad89c215dfb5bae81c0948da6b3cd5c267304dc368d795e542
7
- data.tar.gz: 826444b74fd01885c66389a1c08b8b2cb99617662c3e364453d4d1572fa0237447d70d196fc867bde6231bc11efd6b47c874619bafe1efa800bcc1304a055329
6
+ metadata.gz: 35a0841efafc3a3b1fb98cbfdccff848a51262cf3e493d78cb95c4f300a1ced40779837d51e31edfd5d2cc3626b4ad22fd9f1066bcedfd4b9d8d460d44e9ddf4
7
+ data.tar.gz: 1528871ed4e31683e9334eb91096d7ad6cf592d60020bd151e70e93324d727067dfc2a62c8ec8471ba3f3f56e289cc95890f7a6d89e32afce62c2a5fd55506fc
checksums.yaml.gz.sig CHANGED
@@ -1,3 +1,3 @@
1
- ��\`��W��y0!�l���i�Xu�����R|
2
- #��v@���]�x�i�����G0#/öV�tC��,�|K�����ˈ�Xb3B7Dlk� b{�tV
3
- z!�%��BY��] �~!�q@P�����{oc������EsACf_�ѻ>��t�6� ?𯭴�v��E S����`��F�4�5,|q�ԃ�,[U+,
1
+ [�uy�jZ�L!=�5C���14���r ��{���i���ij��1��I��|�żKU��(���][H����q\��yB�C�3J�3�*���Lf�rEc��oa�$qVY;PWcG^M'^*c��(�4�Fy�����G��q1�o��Ǵ��Z���i�b��S
2
+ �&{�\S�s^C��1�<S�GRbxD
3
+ 3OEI}��"�ͿՓ�}w�Ɖ0�s#�-f��Q�Y��� $~ʲa����/I��˩&s���t���&��E�,#�kzD�*<�
@@ -212,6 +212,7 @@ module Protocol
212
212
  # Write a message to the connection.
213
213
  # @parameter message [Message] The message to send.
214
214
  def write(message, **options)
215
+ # This is a compatibility shim for the previous implementation. We may want to eventually deprecate this use case... or maybe it's convenient enough to leave it around.
215
216
  if message.is_a?(String)
216
217
  if message.encoding == Encoding::UTF_8
217
218
  return send_text(message, **options)
@@ -0,0 +1,47 @@
1
+ # Copyright, 2022, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'json'
22
+
23
+ require_relative 'message'
24
+
25
+ module Protocol
26
+ module WebSocket
27
+ class JSONMessage < TextMessage
28
+ def self.wrap(message)
29
+ if message.is_a?(TextMessage)
30
+ self.new(message.buffer)
31
+ end
32
+ end
33
+
34
+ def self.generate(object)
35
+ self.new(JSON.generate(object))
36
+ end
37
+
38
+ def parse(symbolize_names: true, **options)
39
+ JSON.parse(@buffer, symbolize_names: symbolize_names, **options)
40
+ end
41
+
42
+ def to_h
43
+ parse.to_h
44
+ end
45
+ end
46
+ end
47
+ end
@@ -33,8 +33,9 @@ module Protocol
33
33
  @buffer.bytesize
34
34
  end
35
35
 
36
+ # This can be helpful for writing tests.
36
37
  def == other
37
- @buffer == other
38
+ @buffer == other.to_str
38
39
  end
39
40
 
40
41
  def to_str
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Protocol
22
22
  module WebSocket
23
- VERSION = "0.9.0"
23
+ VERSION = "0.9.1"
24
24
  end
25
25
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-websocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -136,6 +136,7 @@ files:
136
136
  - lib/protocol/websocket/frame.rb
137
137
  - lib/protocol/websocket/framer.rb
138
138
  - lib/protocol/websocket/headers.rb
139
+ - lib/protocol/websocket/json_message.rb
139
140
  - lib/protocol/websocket/message.rb
140
141
  - lib/protocol/websocket/ping_frame.rb
141
142
  - lib/protocol/websocket/pong_frame.rb
metadata.gz.sig CHANGED
Binary file