ably-pubsub-core 0.0.1.pre → 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.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ably/auth.rb +5 -5
  3. data/lib/ably/exceptions.rb +5 -0
  4. data/lib/ably/internal.rb +115 -0
  5. data/lib/ably/logger.rb +3 -3
  6. data/lib/ably/models/channel_details.rb +1 -1
  7. data/lib/ably/models/channel_metrics.rb +1 -1
  8. data/lib/ably/models/channel_occupancy.rb +1 -1
  9. data/lib/ably/models/channel_state_change.rb +7 -7
  10. data/lib/ably/models/channel_status.rb +1 -1
  11. data/lib/ably/models/cipher_params.rb +1 -1
  12. data/lib/ably/models/connection_details.rb +2 -2
  13. data/lib/ably/models/connection_state_change.rb +6 -6
  14. data/lib/ably/models/http_paginated_response.rb +3 -3
  15. data/lib/ably/models/message.rb +69 -2
  16. data/lib/ably/models/message_operation.rb +53 -0
  17. data/lib/ably/models/paginated_result.rb +2 -2
  18. data/lib/ably/models/presence_message.rb +1 -1
  19. data/lib/ably/models/protocol_message.rb +14 -1
  20. data/lib/ably/models/publish_result.rb +32 -0
  21. data/lib/ably/models/stats.rb +41 -84
  22. data/lib/ably/models/update_delete_result.rb +32 -0
  23. data/lib/ably/modules/ably.rb +13 -12
  24. data/lib/ably/modules/channels_collection.rb +1 -1
  25. data/lib/ably/modules/http_helpers.rb +11 -11
  26. data/lib/ably/{rest → pubsub/http}/channel/push_channel.rb +3 -3
  27. data/lib/ably/pubsub/http/channel.rb +284 -0
  28. data/lib/ably/pubsub/http/channels.rb +49 -0
  29. data/lib/ably/pubsub/http/client.rb +738 -0
  30. data/lib/ably/pubsub/http/middleware/encoder.rb +51 -0
  31. data/lib/ably/pubsub/http/middleware/exceptions.rb +55 -0
  32. data/lib/ably/pubsub/http/middleware/external_exceptions.rb +26 -0
  33. data/lib/ably/pubsub/http/middleware/fail_if_unsupported_mime_type.rb +24 -0
  34. data/lib/ably/pubsub/http/middleware/logger.rb +60 -0
  35. data/lib/ably/pubsub/http/middleware/parse_json.rb +29 -0
  36. data/lib/ably/pubsub/http/middleware/parse_message_pack.rb +45 -0
  37. data/lib/ably/pubsub/http/presence.rb +117 -0
  38. data/lib/ably/{rest → pubsub/http}/push/admin.rb +5 -5
  39. data/lib/ably/{rest → pubsub/http}/push/channel_subscriptions.rb +1 -1
  40. data/lib/ably/{rest → pubsub/http}/push/device_registrations.rb +1 -1
  41. data/lib/ably/pubsub/http/push.rb +27 -0
  42. data/lib/ably/pubsub/http.rb +38 -0
  43. data/lib/ably/pubsub/realtime/auth.rb +285 -0
  44. data/lib/ably/{realtime → pubsub/realtime}/channel/channel_manager.rb +2 -2
  45. data/lib/ably/{realtime → pubsub/realtime}/channel/channel_properties.rb +5 -5
  46. data/lib/ably/{realtime → pubsub/realtime}/channel/channel_state_machine.rb +2 -2
  47. data/lib/ably/{realtime → pubsub/realtime}/channel/publisher.rb +9 -4
  48. data/lib/ably/{realtime → pubsub/realtime}/channel/push_channel.rb +2 -2
  49. data/lib/ably/pubsub/realtime/channel.rb +545 -0
  50. data/lib/ably/pubsub/realtime/channels.rb +92 -0
  51. data/lib/ably/{realtime → pubsub/realtime}/client/incoming_message_dispatcher.rb +43 -8
  52. data/lib/ably/{realtime → pubsub/realtime}/client/outgoing_message_dispatcher.rb +2 -2
  53. data/lib/ably/pubsub/realtime/client.rb +372 -0
  54. data/lib/ably/{realtime → pubsub/realtime}/connection/connection_manager.rb +6 -6
  55. data/lib/ably/{realtime → pubsub/realtime}/connection/connection_state_machine.rb +2 -2
  56. data/lib/ably/{realtime → pubsub/realtime}/connection/websocket_transport.rb +1 -1
  57. data/lib/ably/pubsub/realtime/connection.rb +724 -0
  58. data/lib/ably/{realtime → pubsub/realtime}/models/nil_channel.rb +3 -3
  59. data/lib/ably/{realtime → pubsub/realtime}/presence/members_map.rb +2 -2
  60. data/lib/ably/{realtime → pubsub/realtime}/presence/presence_manager.rb +3 -3
  61. data/lib/ably/{realtime → pubsub/realtime}/presence/presence_state_machine.rb +2 -2
  62. data/lib/ably/{realtime → pubsub/realtime}/presence.rb +23 -23
  63. data/lib/ably/{realtime → pubsub/realtime}/push/admin.rb +8 -8
  64. data/lib/ably/{realtime → pubsub/realtime}/push/channel_subscriptions.rb +6 -6
  65. data/lib/ably/{realtime → pubsub/realtime}/push/device_registrations.rb +6 -6
  66. data/lib/ably/pubsub/realtime/push.rb +27 -0
  67. data/lib/ably/pubsub/realtime/recovery_key_context.rb +38 -0
  68. data/lib/ably/pubsub/realtime.rb +58 -0
  69. data/lib/ably/pubsub.rb +11 -0
  70. data/lib/ably/version.rb +2 -2
  71. data/lib/ably.rb +6 -2
  72. metadata +50 -46
  73. data/lib/ably/models/stats_types.rb +0 -107
  74. data/lib/ably/realtime/auth.rb +0 -283
  75. data/lib/ably/realtime/channel.rb +0 -440
  76. data/lib/ably/realtime/channels.rb +0 -71
  77. data/lib/ably/realtime/client.rb +0 -363
  78. data/lib/ably/realtime/connection.rb +0 -738
  79. data/lib/ably/realtime/push.rb +0 -25
  80. data/lib/ably/realtime/recovery_key_context.rb +0 -36
  81. data/lib/ably/realtime.rb +0 -60
  82. data/lib/ably/rest/channel.rb +0 -194
  83. data/lib/ably/rest/channels.rb +0 -47
  84. data/lib/ably/rest/client.rb +0 -727
  85. data/lib/ably/rest/middleware/encoder.rb +0 -49
  86. data/lib/ably/rest/middleware/exceptions.rb +0 -53
  87. data/lib/ably/rest/middleware/external_exceptions.rb +0 -24
  88. data/lib/ably/rest/middleware/fail_if_unsupported_mime_type.rb +0 -22
  89. data/lib/ably/rest/middleware/logger.rb +0 -58
  90. data/lib/ably/rest/middleware/parse_json.rb +0 -27
  91. data/lib/ably/rest/middleware/parse_message_pack.rb +0 -43
  92. data/lib/ably/rest/presence.rb +0 -113
  93. data/lib/ably/rest/push.rb +0 -25
  94. data/lib/ably/rest.rb +0 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfde17dfbe0fdf4231002551f59c0640790f5dbc9c9ffbae01494cd96289136c
4
- data.tar.gz: aaaa739481288c462335970bbb82b6244fd28d93fd6f9d65f35bb2f1c9c753e8
3
+ metadata.gz: 56f7d1d6dadea1c1ac1f9c4b71d0cd24ed32377413656387cb0caaab28f24675
4
+ data.tar.gz: bc390317b2eb7d61889163f263338b47acde921f51273918f782560475e1a8ec
5
5
  SHA512:
6
- metadata.gz: 0f16bb38d800bae45523d42c8fad9eba0fda282d4c4f199b907ded1bc7ce08c4d4a2efd0c1b8375c8d92b9db6be7439189cb68e61cde72bcc66be7f9ae4d8a10
7
- data.tar.gz: 96e428f0903e4411d14073130dac860501c51d58bc0b2a684a9a2b68a5a4e7fccb451412bdbb2b55aed76b358ea95ba4456c1558ae3922ed6b1b0c6e77a7bdae
6
+ metadata.gz: 7e962e44c31361de7d343cd88013a9be3bc772c944a80af3372ec387965ae17cd133c11ca66fe1bc81f0d2d9fd2eb8ac7a424b5d6ffec394c6a89ee21b204a0b
7
+ data.tar.gz: 7ed83f9bcf06222c7a204728e113e5c6406d79ac9841c2ee2c742157e9c2388b748eef4a6f43a06e861af269a531b8b88a7d35b5c4531ab0e8336cfc1d0421d1
data/lib/ably/auth.rb CHANGED
@@ -2,7 +2,7 @@ require 'json'
2
2
  require 'faraday'
3
3
  require 'securerandom'
4
4
 
5
- require 'ably/rest/middleware/external_exceptions'
5
+ require 'ably/pubsub/http/middleware/external_exceptions'
6
6
 
7
7
  module Ably
8
8
  # Creates Ably {Ably::Models::TokenRequest} objects and obtains Ably Tokens from Ably to subsequently issue to less trusted clients.
@@ -45,7 +45,7 @@ module Ably
45
45
 
46
46
  # Creates an Auth object
47
47
  #
48
- # @param [Ably::Rest::Client] client {Ably::Rest::Client} this Auth object uses
48
+ # @param [Ably::PubSub::Http::Client] client {Ably::PubSub::Http::Client} this Auth object uses
49
49
  # @param [Hash] token_params the token params used as a default for future token requests
50
50
  # @param [Hash] auth_options the authentication options used as a default future token requests
51
51
  # @option (see #request_token)
@@ -123,7 +123,7 @@ module Ably
123
123
  #
124
124
  # @example
125
125
  # # will issue a simple token request using basic auth
126
- # client = Ably::Rest::Client.new(key: 'key.id:secret')
126
+ # client = Ably::PubSub::Server.create_http_client(key: 'key.id:secret')
127
127
  # token_details = client.auth.authorize
128
128
  #
129
129
  # # will use token request from block to authorize if not already authorized
@@ -214,7 +214,7 @@ module Ably
214
214
  #
215
215
  # @example
216
216
  # # simple token request using basic auth
217
- # client = Ably::Rest::Client.new(key: 'key.id:secret')
217
+ # client = Ably::PubSub::Server.create_http_client(key: 'key.id:secret')
218
218
  # token_details = client.auth.request_token
219
219
  #
220
220
  # # token request with token params
@@ -759,7 +759,7 @@ module Ably
759
759
  setup_outgoing_middleware builder
760
760
 
761
761
  # Raise exceptions if response code is invalid
762
- builder.use Ably::Rest::Middleware::ExternalExceptions
762
+ builder.use Ably::PubSub::Http::Middleware::ExternalExceptions
763
763
 
764
764
  setup_incoming_middleware builder, logger
765
765
 
@@ -165,5 +165,10 @@ module Ably
165
165
  class InvalidTokenRequest < BaseAblyException; end
166
166
 
167
167
  class PushNotificationsNotSupported < BaseAblyException; end
168
+
169
+ # A client class was constructed directly rather than through the factory function of
170
+ # an Ably per-side package. The package a client is created from is what declares the
171
+ # client's side to the platform, so a directly constructed client declares none.
172
+ class DirectConstructionNotSupported < BaseAblyException; end
168
173
  end
169
174
  end
@@ -0,0 +1,115 @@
1
+ module Ably
2
+ # Construction entry points for Ably's own per-side packages: +ably-pubsub-server+, and
3
+ # any future device-side package, plus endpoint resolution shared by the clients.
4
+ #
5
+ # Applications must not use this module. It carries no compatibility guarantee and may
6
+ # change in any release, including a patch. Use the factory functions of the package you
7
+ # installed — see {Ably::PubSub::Server} in the +ably-pubsub-server+ gem.
8
+ #
9
+ # The client classes refuse direct construction ({Ably::PubSub::Http::Client.new} and
10
+ # {Ably::PubSub::Realtime::Client.new} raise {Ably::Exceptions::DirectConstructionNotSupported}),
11
+ # because the package a client is created from is what declares the client's side to the
12
+ # platform and a directly constructed client declares none. These entry points are how a
13
+ # per-side package constructs the client it has stamped its side onto.
14
+ module Internal
15
+ # Prefix of an +:endpoint+ value that selects a non-production routing policy, such as +nonprod:sandbox+
16
+ NONPROD_ENDPOINT_PREFIX = 'nonprod:'.freeze
17
+ NONPROD_ROOT_DOMAIN = 'ably-nonprod.net'.freeze
18
+ NONPROD_FALLBACK_DOMAIN = 'ably-realtime-nonprod.com'.freeze
19
+ private_constant :NONPROD_ENDPOINT_PREFIX, :NONPROD_ROOT_DOMAIN, :NONPROD_FALLBACK_DOMAIN
20
+
21
+ class << self
22
+ # Constructs an {Ably::PubSub::Http::Client}, bypassing the direct-construction refusal.
23
+ #
24
+ # @param options [Hash, String] as accepted by {Ably::PubSub::Http::Client#initialize}
25
+ # @return [Ably::PubSub::Http::Client]
26
+ # @api private
27
+ def create_http_client(options)
28
+ construct(Ably::PubSub::Http::Client, options)
29
+ end
30
+
31
+ # Constructs an {Ably::PubSub::Realtime::Client}, bypassing the direct-construction refusal.
32
+ #
33
+ # @param options [Hash, String] as accepted by {Ably::PubSub::Realtime::Client#initialize}
34
+ # @return [Ably::PubSub::Realtime::Client]
35
+ # @api private
36
+ def create_realtime_client(options)
37
+ construct(Ably::PubSub::Realtime::Client, options)
38
+ end
39
+
40
+ # Builds the error raised when a client is constructed directly. Shared so the
41
+ # refusals on the client classes and on the Ably::PubSub::Http /
42
+ # Ably::PubSub::Realtime convenience aliases all speak with one voice.
43
+ #
44
+ # @param subject [String] the unsupported call, e.g. +"Ably::PubSub::Http::Client.new"+
45
+ # @param factory [String] the supported call to use instead
46
+ # @return [Ably::Exceptions::DirectConstructionNotSupported]
47
+ # @api private
48
+ def direct_construction_error(subject, factory)
49
+ Ably::Exceptions::DirectConstructionNotSupported.new <<~MSG
50
+ #{subject} is not supported: Ably clients cannot be constructed directly.
51
+
52
+ Use the factory function of the Ably package you installed, for example:
53
+ #{factory} # ably-pubsub-server
54
+
55
+ The package a client is created from is what declares the client's side to the
56
+ platform. A directly constructed client declares none, so the platform cannot
57
+ classify it for MAU billing.
58
+ MSG
59
+ end
60
+
61
+ # Returns the primary domain for the given +:endpoint+ client option value
62
+ #
63
+ # @spec REC1b2, REC1b3, REC1b4
64
+ # @param endpoint [String] a routing policy name such as +main+, a +nonprod:[id]+ routing policy, or a hostname
65
+ # @return [String]
66
+ # @api private
67
+ def primary_domain(endpoint)
68
+ return endpoint if hostname_endpoint?(endpoint)
69
+
70
+ if nonprod_endpoint?(endpoint)
71
+ "#{nonprod_endpoint_id(endpoint)}.realtime.#{NONPROD_ROOT_DOMAIN}"
72
+ else
73
+ "#{endpoint}.realtime.#{Ably::PROD_ROOT_DOMAIN}"
74
+ end
75
+ end
76
+
77
+ # Returns the default fallback domains for the given +:endpoint+ client option value
78
+ #
79
+ # @spec REC2c1, REC2c2, REC2c3, REC2c4
80
+ # @param endpoint [String] a routing policy name such as +main+, a +nonprod:[id]+ routing policy, or a hostname
81
+ # @return [Array<String>] empty when +endpoint+ is a hostname
82
+ # @api private
83
+ def fallback_domains(endpoint)
84
+ return [] if hostname_endpoint?(endpoint)
85
+
86
+ if nonprod_endpoint?(endpoint)
87
+ Ably::FALLBACK_IDS.map { |id| "#{nonprod_endpoint_id(endpoint)}.#{id}.fallback.#{NONPROD_FALLBACK_DOMAIN}" }
88
+ else
89
+ Ably::FALLBACK_IDS.map { |id| "#{endpoint}.#{id}.fallback.#{Ably::PROD_FALLBACK_DOMAIN}" }
90
+ end
91
+ end
92
+
93
+ private
94
+
95
+ # +allocate+ skips the class's overridden +new+, so +initialize+ has to be invoked
96
+ # explicitly. Every client instance in the library is built through here.
97
+ def construct(klass, options)
98
+ klass.allocate.tap { |client| client.send(:initialize, options) }
99
+ end
100
+
101
+ # @spec REC1b2
102
+ def hostname_endpoint?(endpoint)
103
+ endpoint.include?('.') || endpoint.include?('::') || endpoint == 'localhost'
104
+ end
105
+
106
+ def nonprod_endpoint?(endpoint)
107
+ endpoint.start_with?(NONPROD_ENDPOINT_PREFIX)
108
+ end
109
+
110
+ def nonprod_endpoint_id(endpoint)
111
+ endpoint.delete_prefix(NONPROD_ENDPOINT_PREFIX)
112
+ end
113
+ end
114
+ end
115
+ end
data/lib/ably/logger.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  module Ably
2
2
  # Logger unifies logging for #debug, #info, #warn, #error, and #fatal messages.
3
3
  # A new Ably client uses this Logger and sets the appropriate log level.
4
- # A custom Logger can be configured when instantiating the client, refer to the {Ably::Rest::Client} and {Ably::Realtime::Client} documentation
4
+ # A custom Logger can be configured when instantiating the client, refer to the {Ably::PubSub::Http::Client} and {Ably::PubSub::Realtime::Client} documentation
5
5
  #
6
6
  class Logger
7
7
  extend Forwardable
8
8
 
9
- # @param client [Ably::Rest::Client,Ably::Realtime::Client] Rest or Realtime Ably client
9
+ # @param client [Ably::PubSub::Http::Client,Ably::PubSub::Realtime::Client] Rest or Realtime Ably client
10
10
  # @param log_level [Integer] {http://www.ruby-doc.org/stdlib-3.1.1/libdoc/logger/rdoc/Logger.html Ruby Logger} log level
11
11
  # @param custom_logger [nil,Object] A custom logger can optionally be used instead of the,
12
12
  # however it must provide a {http://www.ruby-doc.org/stdlib-3.1.1/libdoc/logger/rdoc/Logger.html Ruby Logger} compatible interface.
@@ -83,7 +83,7 @@ module Ably
83
83
  end
84
84
 
85
85
  def realtime?
86
- defined?(Ably::Realtime::Client) && client.kind_of?(Ably::Realtime::Client)
86
+ defined?(Ably::PubSub::Realtime::Client) && client.kind_of?(Ably::PubSub::Realtime::Client)
87
87
  end
88
88
 
89
89
  def default_logger
@@ -14,7 +14,7 @@ module Ably::Models
14
14
  end
15
15
  end
16
16
 
17
- # Contains the details of a {Ably::Models::Rest::Channel} or {Ably::Models::Realtime::Channel} object
17
+ # Contains the details of a {Ably::PubSub::Http::Channel} or {Ably::PubSub::Realtime::Channel} object
18
18
  # such as its ID and {Ably::Models::ChannelStatus}.
19
19
  #
20
20
  class ChannelDetails
@@ -14,7 +14,7 @@ module Ably::Models
14
14
  end
15
15
  end
16
16
 
17
- # Contains the metrics associated with a {Ably::Models::Rest::Channel} or {Ably::Models::Realtime::Channel},
17
+ # Contains the metrics associated with a {Ably::PubSub::Http::Channel} or {Ably::PubSub::Realtime::Channel},
18
18
  # such as the number of publishers, subscribers and connections it has.
19
19
  #
20
20
  # @spec CHM1
@@ -14,7 +14,7 @@ module Ably::Models
14
14
  end
15
15
  end
16
16
 
17
- # Contains the metrics of a {Ably::Models::Rest::Channel} or {Ably::Models::Realtime::Channel} object.
17
+ # Contains the metrics of a {Ably::PubSub::Http::Channel} or {Ably::PubSub::Realtime::Channel} object.
18
18
  #
19
19
  # @spec CHO1
20
20
  #
@@ -1,5 +1,5 @@
1
1
  module Ably::Models
2
- # Contains state change information emitted by {Ably::Rest::Channel} and {Ably::Realtime::Channel} objects.
2
+ # Contains state change information emitted by {Ably::PubSub::Http::Channel} and {Ably::PubSub::Realtime::Channel} objects.
3
3
  #
4
4
  class ChannelStateChange
5
5
  include Ably::Modules::ModelCommon
@@ -21,31 +21,31 @@ module Ably::Models
21
21
  raise ArgumentError, e
22
22
  end
23
23
 
24
- # The new current {Ably::Realtime::Channel::STATE}.
24
+ # The new current {Ably::PubSub::Realtime::Channel::STATE}.
25
25
  #
26
26
  # @spec RTL2a, RTL2b
27
27
  #
28
- # @return [Ably::Realtime::Channel::STATE]
28
+ # @return [Ably::PubSub::Realtime::Channel::STATE]
29
29
  #
30
30
  def current
31
31
  @hash_object[:current]
32
32
  end
33
33
 
34
- # The previous state. For the {Ably::Realtime::Channel::EVENT}(:update) event, this is equal to the current {Ably::Realtime::Channel::STATE}.
34
+ # The previous state. For the {Ably::PubSub::Realtime::Channel::EVENT}(:update) event, this is equal to the current {Ably::PubSub::Realtime::Channel::STATE}.
35
35
  #
36
36
  # @spec RTL2a, RTL2b
37
37
  #
38
- # @return [Ably::Realtime::Channel::EVENT]
38
+ # @return [Ably::PubSub::Realtime::Channel::EVENT]
39
39
  #
40
40
  def previous
41
41
  @hash_object[:previous]
42
42
  end
43
43
 
44
- # The event that triggered this {Ably::Realtime::Channel::STATE} change.
44
+ # The event that triggered this {Ably::PubSub::Realtime::Channel::STATE} change.
45
45
  #
46
46
  # @spec TH5
47
47
  #
48
- # @return [Ably::Realtime::Channel::STATE]
48
+ # @return [Ably::PubSub::Realtime::Channel::STATE]
49
49
  #
50
50
  def event
51
51
  @hash_object[:event]
@@ -14,7 +14,7 @@ module Ably::Models
14
14
  end
15
15
  end
16
16
 
17
- # Contains the status of a {Ably::Models::Rest::Channel} or {Ably::Models::Realtime::Channel} object
17
+ # Contains the status of a {Ably::PubSub::Http::Channel} or {Ably::PubSub::Realtime::Channel} object
18
18
  # such as whether it is active and its {Ably::Models::ChannelOccupancy}.
19
19
  #
20
20
  # @spec CHS1
@@ -17,7 +17,7 @@ module Ably::Models
17
17
  end
18
18
  end
19
19
 
20
- # Sets the properties to configure encryption for a {Ably::Models::Rest::Channel} or {Ably::Models::Realtime::Channel} object.
20
+ # Sets the properties to configure encryption for a {Ably::PubSub::Http::Channel} or {Ably::PubSub::Realtime::Channel} object.
21
21
  #
22
22
  class CipherParams
23
23
  include Ably::Modules::ModelCommon
@@ -14,8 +14,8 @@ module Ably::Models
14
14
  end
15
15
  end
16
16
 
17
- # Contains any constraints a client should adhere to and provides additional metadata about a {Ably::Realtime::Connection},
18
- # such as if a request to {Ably::Realtime::Client#publish} a message that exceeds the maximum message size should be rejected immediately without communicating with Ably.
17
+ # Contains any constraints a client should adhere to and provides additional metadata about a {Ably::PubSub::Realtime::Connection},
18
+ # such as if a request to {Ably::PubSub::Realtime::Client#publish} a message that exceeds the maximum message size should be rejected immediately without communicating with Ably.
19
19
  #
20
20
  class ConnectionDetails
21
21
  include Ably::Modules::ModelCommon
@@ -1,5 +1,5 @@
1
1
  module Ably::Models
2
- # Contains {Ably::Models::ConnectionState} change information emitted by the {Ably::Realtime::Connection} object.
2
+ # Contains {Ably::Models::ConnectionState} change information emitted by the {Ably::PubSub::Realtime::Connection} object.
3
3
  #
4
4
  class ConnectionStateChange
5
5
  include Ably::Modules::ModelCommon
@@ -21,21 +21,21 @@ module Ably::Models
21
21
  raise ArgumentError, e
22
22
  end
23
23
 
24
- # The new {Ably::Realtime::Connection::STATE}.
24
+ # The new {Ably::PubSub::Realtime::Connection::STATE}.
25
25
  #
26
26
  # @spec TA2
27
27
  #
28
- # @return [Ably::Realtime::Connection::STATE]
28
+ # @return [Ably::PubSub::Realtime::Connection::STATE]
29
29
  #
30
30
  def current
31
31
  @hash_object[:current]
32
32
  end
33
33
 
34
- # The event that triggered this {Ably::Realtime::Connection::EVENT} change.
34
+ # The event that triggered this {Ably::PubSub::Realtime::Connection::EVENT} change.
35
35
  #
36
36
  # @spec TA5
37
37
  #
38
- # @return [Ably::Realtime::Connection::STATE]
38
+ # @return [Ably::PubSub::Realtime::Connection::STATE]
39
39
  #
40
40
  def event
41
41
  @hash_object[:event]
@@ -46,7 +46,7 @@ module Ably::Models
46
46
  #
47
47
  # @spec TA2
48
48
  #
49
- # @return [Ably::Realtime::Connection::STATE]
49
+ # @return [Ably::PubSub::Realtime::Connection::STATE]
50
50
  #
51
51
  def previous
52
52
  @hash_object[:previous]
@@ -1,13 +1,13 @@
1
1
  require 'ably/models/paginated_result'
2
2
 
3
3
  module Ably::Models
4
- # HTTP respones object from Rest#request object
4
+ # HTTP response object from Ably::PubSub::Http::Client#request
5
5
  # Wraps any Ably HTTP response that supports paging and provides methods to iterate through
6
6
  # the pages using {#first}, {#next}, {#has_next?} and {#last?}
7
7
 
8
8
  class HttpPaginatedResponse < PaginatedResult
9
9
  # Retrieve the first page of results.
10
- # When used as part of the {Ably::Realtime} library, it will return a {Ably::Util::SafeDeferrable} object,
10
+ # When used as part of the {Ably::PubSub::Realtime} library, it will return a {Ably::Util::SafeDeferrable} object,
11
11
  # and allows an optional success callback block to be provided.
12
12
  #
13
13
  # @return [HttpPaginatedResponse,Ably::Util::SafeDeferrable]
@@ -20,7 +20,7 @@ module Ably::Models
20
20
  end
21
21
 
22
22
  # Retrieve the next page of results.
23
- # When used as part of the {Ably::Realtime} library, it will return a {Ably::Util::SafeDeferrable} object,
23
+ # When used as part of the {Ably::PubSub::Realtime} library, it will return a {Ably::Util::SafeDeferrable} object,
24
24
  # and allows an optional success callback block to be provided.
25
25
  #
26
26
  # @return [HttpPaginatedResponse,Ably::Util::SafeDeferrable]
@@ -25,7 +25,21 @@ module Ably::Models
25
25
  include Ably::Modules::Conversions
26
26
  include Ably::Modules::Encodeable
27
27
  include Ably::Modules::ModelCommon
28
- include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime)
28
+ include Ably::Modules::SafeDeferrable if defined?(Ably::PubSub::Realtime)
29
+ extend Ably::Modules::Enum
30
+
31
+ # Describes the possible actions for a message.
32
+ #
33
+ # @spec TM5
34
+ #
35
+ ACTION = ruby_enum('ACTION',
36
+ :message_create, # 0
37
+ :message_update, # 1
38
+ :message_delete, # 2
39
+ :meta, # 3
40
+ :message_summary, # 4
41
+ :message_append, # 5
42
+ )
29
43
 
30
44
  # Statically register a default set of encoders for this class
31
45
  Ably::Models::MessageEncoders.register_default_encoders self
@@ -129,10 +143,63 @@ module Ably::Models
129
143
  end
130
144
  end
131
145
 
146
+ # The action type of this message.
147
+ #
148
+ # @spec TM2j
149
+ #
150
+ # @return [ACTION, nil]
151
+ #
152
+ def action
153
+ ACTION(attributes[:action]) if attributes[:action]
154
+ end
155
+
156
+ # An opaque string that uniquely identifies the message within a channel.
157
+ #
158
+ # @spec TM2r
159
+ #
160
+ # @return [String, nil]
161
+ #
162
+ def serial
163
+ attributes[:serial]
164
+ end
165
+
166
+ # Version information about this message.
167
+ #
168
+ # @spec TM2s
169
+ #
170
+ # @return [Hash, nil]
171
+ #
172
+ def version
173
+ attributes[:version]
174
+ end
175
+
176
+ # Timestamp of when the message was created.
177
+ #
178
+ # @return [Time, nil]
179
+ #
180
+ def created_at
181
+ as_time_from_epoch(attributes[:created_at]) if attributes[:created_at]
182
+ end
183
+
184
+ # Timestamp of when the message was last updated.
185
+ #
186
+ # @return [Time, nil]
187
+ #
188
+ def updated_at
189
+ as_time_from_epoch(attributes[:updated_at]) if attributes[:updated_at]
190
+ end
191
+
132
192
  def attributes
133
193
  @attributes
134
194
  end
135
195
 
196
+ # Return a JSON ready object from the underlying #attributes using Ably naming conventions for keys
197
+ def as_json(*args)
198
+ attributes.dup.tap do |message|
199
+ message['action'] = action.to_i if attributes[:action]
200
+ end.as_json.reject { |key, val| val.nil? }
201
+ end
202
+
136
203
  def to_json(*args)
137
204
  as_json(*args).tap do |message|
138
205
  decode_binary_data_before_to_json message
@@ -212,7 +279,7 @@ module Ably::Models
212
279
  end
213
280
 
214
281
  def set_attributes_object(new_attributes)
215
- @attributes = IdiomaticRubyWrapper(new_attributes.clone, stop_at: [:data, :extras])
282
+ @attributes = IdiomaticRubyWrapper(new_attributes.clone, stop_at: [:data, :extras, :version])
216
283
  end
217
284
 
218
285
  def logger
@@ -0,0 +1,53 @@
1
+ module Ably::Models
2
+ # Represents the operation metadata for update, delete, or append message operations.
3
+ #
4
+ # @spec MOP
5
+ #
6
+ class MessageOperation
7
+ include Ably::Modules::ModelCommon
8
+
9
+ # @param attributes [Hash]
10
+ # @option attributes [String] :client_id The client ID of the user performing the operation (MOP2a)
11
+ # @option attributes [String] :description An optional human-readable description of the operation (MOP2b)
12
+ # @option attributes [Hash] :metadata Arbitrary key-value metadata for the operation (MOP2c)
13
+ #
14
+ def initialize(attributes = {})
15
+ @hash_object = IdiomaticRubyWrapper(attributes || {}, stop_at: [:metadata])
16
+ @hash_object.freeze
17
+ end
18
+
19
+ # The client ID of the user performing the operation.
20
+ #
21
+ # @spec MOP2a
22
+ #
23
+ # @return [String, nil]
24
+ #
25
+ def client_id
26
+ attributes[:client_id]
27
+ end
28
+
29
+ # An optional human-readable description of the operation.
30
+ #
31
+ # @spec MOP2b
32
+ #
33
+ # @return [String, nil]
34
+ #
35
+ def description
36
+ attributes[:description]
37
+ end
38
+
39
+ # Arbitrary key-value metadata for the operation.
40
+ #
41
+ # @spec MOP2c
42
+ #
43
+ # @return [Hash, nil]
44
+ #
45
+ def metadata
46
+ attributes[:metadata]
47
+ end
48
+
49
+ def attributes
50
+ @hash_object
51
+ end
52
+ end
53
+ end
@@ -4,7 +4,7 @@ module Ably::Models
4
4
  # that indicates the relative queries available to the PaginatedResult object.
5
5
  #
6
6
  class PaginatedResult
7
- include Ably::Modules::AsyncWrapper if defined?(Ably::Realtime)
7
+ include Ably::Modules::AsyncWrapper if defined?(Ably::PubSub::Realtime)
8
8
 
9
9
  # Contains the current page of results; for example, an array of {Ably::Models::Message} or {Ably::Models::PresenceMessage} objects
10
10
  # for a channel history request.
@@ -59,7 +59,7 @@ module Ably::Models
59
59
 
60
60
  # Retrieve the next page of results.
61
61
  #
62
- # When used as part of the {Ably::Realtime} library, it will return a {Ably::Util::SafeDeferrable} object,
62
+ # When used as part of the {Ably::PubSub::Realtime} library, it will return a {Ably::Util::SafeDeferrable} object,
63
63
  # and allows an optional success callback block to be provided.
64
64
  #
65
65
  # @spec TG4
@@ -24,7 +24,7 @@ module Ably::Models
24
24
  include Ably::Modules::Conversions
25
25
  include Ably::Modules::Encodeable
26
26
  include Ably::Modules::ModelCommon
27
- include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime)
27
+ include Ably::Modules::SafeDeferrable if defined?(Ably::PubSub::Realtime)
28
28
  extend Ably::Modules::Enum
29
29
 
30
30
  # Describes the possible actions members in the presence set can emit.
@@ -36,7 +36,7 @@ module Ably::Models
36
36
  class ProtocolMessage
37
37
  include Ably::Modules::ModelCommon
38
38
  include Ably::Modules::Encodeable
39
- include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime)
39
+ include Ably::Modules::SafeDeferrable if defined?(Ably::PubSub::Realtime)
40
40
  extend Ably::Modules::Enum
41
41
 
42
42
  # Actions which are sent by the Ably Realtime API
@@ -171,6 +171,19 @@ module Ably::Models
171
171
  @params ||= attributes[:params].to_h
172
172
  end
173
173
 
174
+ # The res field from ACK protocol messages (protocol v5+), containing publish results.
175
+ # Each entry corresponds to an ACK'd ProtocolMessage and contains a serials array
176
+ # with one entry per message in that ProtocolMessage.
177
+ #
178
+ # @spec TR4s
179
+ #
180
+ # @return [Array, nil]
181
+ #
182
+ # @api private
183
+ def res
184
+ attributes[:res]
185
+ end
186
+
174
187
  def flags
175
188
  Integer(attributes[:flags])
176
189
  rescue TypeError
@@ -0,0 +1,32 @@
1
+ module Ably::Models
2
+ # Contains the result of a publish operation.
3
+ #
4
+ # @spec RSL1n
5
+ #
6
+ class PublishResult
7
+ include Ably::Modules::ModelCommon
8
+
9
+ # @param attributes [Hash]
10
+ # @option attributes [Array<String, nil>] :serials An array of nullable strings corresponding 1:1
11
+ # to the published messages. Each serial identifies the message on the channel.
12
+ #
13
+ def initialize(attributes = {})
14
+ @hash_object = IdiomaticRubyWrapper(attributes || {}, stop_at: [:serials])
15
+ @hash_object.freeze
16
+ end
17
+
18
+ # An array of serial strings (or nil entries), corresponding 1:1 to the published messages.
19
+ #
20
+ # @spec RSL1n
21
+ #
22
+ # @return [Array<String, nil>]
23
+ #
24
+ def serials
25
+ attributes[:serials] || []
26
+ end
27
+
28
+ def attributes
29
+ @hash_object
30
+ end
31
+ end
32
+ end