ably 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/check.yml +1 -1
  3. data/CHANGELOG.md +17 -0
  4. data/README.md +24 -7
  5. data/SPEC.md +1722 -853
  6. data/ably.gemspec +1 -1
  7. data/lib/ably/auth.rb +19 -11
  8. data/lib/ably/models/protocol_message.rb +5 -26
  9. data/lib/ably/modules/safe_deferrable.rb +2 -2
  10. data/lib/ably/modules/state_emitter.rb +1 -1
  11. data/lib/ably/realtime/auth.rb +4 -0
  12. data/lib/ably/realtime/channel/channel_manager.rb +51 -48
  13. data/lib/ably/realtime/channel/channel_properties.rb +9 -0
  14. data/lib/ably/realtime/channel/channel_state_machine.rb +2 -0
  15. data/lib/ably/realtime/channel.rb +4 -3
  16. data/lib/ably/realtime/channels.rb +20 -0
  17. data/lib/ably/realtime/client/incoming_message_dispatcher.rb +14 -13
  18. data/lib/ably/realtime/client.rb +14 -6
  19. data/lib/ably/realtime/connection/connection_manager.rb +21 -22
  20. data/lib/ably/realtime/connection.rb +77 -109
  21. data/lib/ably/realtime/presence/members_map.rb +41 -92
  22. data/lib/ably/realtime/presence/presence_manager.rb +12 -17
  23. data/lib/ably/realtime/presence.rb +15 -6
  24. data/lib/ably/realtime/push.rb +0 -27
  25. data/lib/ably/realtime/recovery_key_context.rb +36 -0
  26. data/lib/ably/rest/client.rb +4 -6
  27. data/lib/ably/rest/push/admin.rb +1 -1
  28. data/lib/ably/rest/push.rb +0 -19
  29. data/lib/ably/util/ably_extensions.rb +29 -0
  30. data/lib/ably/util/crypto.rb +2 -2
  31. data/lib/ably/util/safe_deferrable.rb +1 -1
  32. data/lib/ably/version.rb +5 -7
  33. data/spec/acceptance/realtime/channel_history_spec.rb +8 -12
  34. data/spec/acceptance/realtime/channel_spec.rb +474 -300
  35. data/spec/acceptance/realtime/client_spec.rb +1 -1
  36. data/spec/acceptance/realtime/connection_failures_spec.rb +8 -25
  37. data/spec/acceptance/realtime/connection_spec.rb +28 -120
  38. data/spec/acceptance/realtime/message_spec.rb +23 -52
  39. data/spec/acceptance/realtime/presence_spec.rb +123 -92
  40. data/spec/acceptance/rest/channel_spec.rb +2 -2
  41. data/spec/acceptance/rest/client_spec.rb +9 -2
  42. data/spec/acceptance/rest/message_spec.rb +8 -11
  43. data/spec/acceptance/rest/push_admin_spec.rb +20 -15
  44. data/spec/shared/client_initializer_behaviour.rb +1 -1
  45. data/spec/support/markdown_spec_formatter.rb +1 -1
  46. data/spec/unit/models/protocol_message_spec.rb +0 -78
  47. data/spec/unit/models/token_details_spec.rb +4 -2
  48. data/spec/unit/realtime/channels_spec.rb +1 -1
  49. data/spec/unit/realtime/connection_spec.rb +0 -30
  50. data/spec/unit/realtime/recovery_key_context_spec.rb +36 -0
  51. data/spec/unit/util/crypto_spec.rb +15 -15
  52. metadata +9 -9
  53. data/spec/acceptance/realtime/push_spec.rb +0 -27
  54. data/spec/acceptance/rest/push_spec.rb +0 -25
@@ -20,33 +20,6 @@ module Ably
20
20
  def admin
21
21
  @admin ||= Admin.new(self)
22
22
  end
23
-
24
- # Activates the device for push notifications with FCM or APNS, obtaining a unique identifier from them.
25
- # Subsequently registers the device with Ably and stores the deviceIdentityToken in local storage.
26
- #
27
- # @spec RSH2a
28
- #
29
- # @note This is unsupported in the Ruby library
30
- #
31
- def activate(*arg)
32
- raise_unsupported
33
- end
34
-
35
- # Deactivates the device from receiving push notifications with Ably and FCM or APNS.
36
- #
37
- # @spec RSH2b
38
- #
39
- # @note This is unsupported in the Ruby library
40
- #
41
- def deactivate(*arg)
42
- raise_unsupported
43
- end
44
-
45
- private
46
-
47
- def raise_unsupported
48
- raise Ably::Exceptions::PushNotificationsNotSupported, 'This device does not support receiving or subscribing to push notifications. All PushChannel methods are unavailable'
49
- end
50
23
  end
51
24
  end
52
25
  end
@@ -0,0 +1,36 @@
1
+ require 'json'
2
+ # frozen_string_literal: true
3
+
4
+ module Ably
5
+ module Realtime
6
+ class RecoveryKeyContext
7
+ attr_reader :connection_key
8
+ attr_reader :msg_serial
9
+ attr_reader :channel_serials
10
+
11
+ def initialize(connection_key, msg_serial, channel_serials)
12
+ @connection_key = connection_key
13
+ @msg_serial = msg_serial
14
+ @channel_serials = channel_serials
15
+ if @channel_serials.nil?
16
+ @channel_serials = {}
17
+ end
18
+ end
19
+
20
+ def to_json
21
+ { 'connection_key' => @connection_key, 'msg_serial' => @msg_serial, 'channel_serials' => @channel_serials }.to_json
22
+ end
23
+
24
+ def self.from_json(obj, logger = nil)
25
+ begin
26
+ data = JSON.load obj
27
+ self.new data['connection_key'], data['msg_serial'], data['channel_serials']
28
+ rescue => e
29
+ logger.warn "unable to decode recovery key, found error #{e}" unless logger.nil?
30
+ return nil
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -16,6 +16,7 @@ module Ably
16
16
  include Ably::Modules::Conversions
17
17
  include Ably::Modules::HttpHelpers
18
18
  extend Forwardable
19
+ using Ably::Util::AblyExtensions
19
20
 
20
21
  # Default Ably domain for REST
21
22
  DOMAIN = 'rest.ably.io'
@@ -186,7 +187,7 @@ module Ably
186
187
 
187
188
  @agent = options.delete(:agent) || Ably::AGENT
188
189
  @realtime_client = options.delete(:realtime_client)
189
- @tls = options.delete(:tls) == false ? false : true
190
+ @tls = options.delete_with_default(:tls, true)
190
191
  @environment = options.delete(:environment) # nil is production
191
192
  @environment = nil if [:production, 'production'].include?(@environment)
192
193
  @protocol = options.delete(:protocol) || :msgpack
@@ -200,10 +201,7 @@ module Ably
200
201
  @log_retries_as_info = options.delete(:log_retries_as_info)
201
202
  @max_message_size = options.delete(:max_message_size) || MAX_MESSAGE_SIZE
202
203
  @max_frame_size = options.delete(:max_frame_size) || MAX_FRAME_SIZE
203
-
204
- if (@idempotent_rest_publishing = options.delete(:idempotent_rest_publishing)).nil?
205
- @idempotent_rest_publishing = Ably::PROTOCOL_VERSION.to_f > 1.1
206
- end
204
+ @idempotent_rest_publishing = options.delete_with_default(:idempotent_rest_publishing, true)
207
205
 
208
206
  if options[:fallback_hosts_use_default] && options[:fallback_hosts]
209
207
  raise ArgumentError, "fallback_hosts_use_default cannot be set to try when fallback_hosts is also provided"
@@ -599,7 +597,7 @@ module Ably
599
597
  end
600
598
  unless options[:send_auth_header] == false
601
599
  request.headers[:authorization] = auth.auth_header
602
-
600
+ # RSA7e2
603
601
  options[:headers].to_h.merge(auth.extra_auth_headers).map do |key, val|
604
602
  request.headers[key] = val
605
603
  end
@@ -21,7 +21,7 @@ module Ably::Rest
21
21
 
22
22
  # Publish a push message directly to a single recipient
23
23
  #
24
- # @param recipient [Hash] A recipient device, client_id or raw APNS/GCM target. Refer to push documentation
24
+ # @param recipient [Hash] A recipient device, client_id or raw APNS/FCM/web target. Refer to push documentation
25
25
  # @param data [Hash] The notification payload data and fields. Refer to push documentation
26
26
  #
27
27
  # @return [void]
@@ -20,25 +20,6 @@ module Ably
20
20
  def admin
21
21
  @admin ||= Admin.new(self)
22
22
  end
23
-
24
- # Activate this device for push notifications by registering with the push transport such as GCM/APNS
25
- #
26
- # @note This is unsupported in the Ruby library
27
- def activate(*arg)
28
- raise_unsupported
29
- end
30
-
31
- # Deactivate this device for push notifications by removing the registration with the push transport such as GCM/APNS
32
- #
33
- # @note This is unsupported in the Ruby library
34
- def deactivate(*arg)
35
- raise_unsupported
36
- end
37
-
38
- private
39
- def raise_unsupported
40
- raise Ably::Exceptions::PushNotificationsNotSupported, 'This device does not support receiving or subscribing to push notifications. All PushChannel methods are unavailable'
41
- end
42
23
  end
43
24
  end
44
25
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ably::Util
4
+ module AblyExtensions
5
+ refine Object do
6
+ def nil_or_empty?
7
+ self.nil? || self.empty?
8
+ end
9
+ end
10
+
11
+ refine Hash do
12
+ def fetch_with_default(key, default)
13
+ value = self.fetch(key, default)
14
+ if value.nil?
15
+ return default
16
+ end
17
+ return value
18
+ end
19
+
20
+ def delete_with_default(key, default)
21
+ value = self.delete(key)
22
+ if value.nil?
23
+ return default
24
+ end
25
+ return value
26
+ end
27
+ end
28
+ end
29
+ end
@@ -83,8 +83,8 @@ module Ably::Util
83
83
  cipher.key = key
84
84
  iv = encrypt_options[:iv] || fixed_iv || cipher.random_iv
85
85
  cipher.iv = iv
86
-
87
- iv << cipher.update(payload) << cipher.final
86
+ iv << cipher.update(payload) unless payload.empty?
87
+ iv << cipher.final
88
88
  end
89
89
 
90
90
  # Decrypt payload using configured Cipher
@@ -1,6 +1,6 @@
1
1
  module Ably::Util
2
2
  # SafeDeferrable class provides a Deferrable that is safe to use for for public interfaces
3
- # of this client library. Any exceptions raised in the success or failure callbacks are
3
+ # of this client library. Any exceptions raised in the success or failure callbacks are
4
4
  # caught and logged to the provided logger.
5
5
  #
6
6
  # An exception in a callback provided by a developer should not break this client library
data/lib/ably/version.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  module Ably
2
- VERSION = '1.2.5'
3
- PROTOCOL_VERSION = '1.2'
4
-
5
- # @api private
6
- def self.major_minor_version_numeric
7
- VERSION.gsub(/\.\d+$/, '').to_f
8
- end
2
+ VERSION = '1.2.6'
3
+ # The level of compatibility with the Ably service that this SDK supports.
4
+ # Also referred to as the 'wire protocol version'.
5
+ # spec : CSV2
6
+ PROTOCOL_VERSION = '2'
9
7
  end
@@ -184,26 +184,22 @@ describe Ably::Realtime::Channel, '#history', :event_machine do
184
184
  end
185
185
 
186
186
  context 'when channel receives update event after an attachment' do
187
+ old_attach_serial = ""
188
+ new_attach_serial = "xxxx-xxxx-1"
187
189
  before do
188
190
  channel.on(:attached) do
189
- channel.publish(event, message_after_attach) do
190
- subsequent_serial = channel.properties.attach_serial.dup.tap { |serial| serial[-1] = '1' }
191
- attached_message = Ably::Models::ProtocolMessage.new(action: 11, channel: channel_name, flags: 0, channel_serial: subsequent_serial)
192
- client.connection.__incoming_protocol_msgbus__.publish :protocol_message, attached_message
193
- end
191
+ old_attach_serial = channel.properties.attach_serial
192
+ attached_message = Ably::Models::ProtocolMessage.new(action: 11, channel: channel_name, flags: 0, channel_serial: new_attach_serial)
193
+ client.connection.__incoming_protocol_msgbus__.publish :protocol_message, attached_message
194
194
  end
195
195
  end
196
196
 
197
197
  it 'updates attach_serial' do
198
- rest_channel.publish event, message_before_attach
199
-
200
198
  channel.on(:update) do
201
- channel.history(until_attach: true) do |messages|
202
- expect(messages.items.count).to eql(2)
203
- stop_reactor
204
- end
199
+ expect(channel.properties.attach_serial).not_to eq(old_attach_serial)
200
+ expect(channel.properties.attach_serial).to eq(new_attach_serial)
201
+ stop_reactor
205
202
  end
206
-
207
203
  channel.attach
208
204
  end
209
205
  end