ably-rest 1.1.2 → 1.2.2

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 (111) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +1 -1
  4. data/MAINTAINERS.md +1 -0
  5. data/README.md +4 -2
  6. data/ably-rest.gemspec +15 -18
  7. data/lib/ably-rest.rb +2 -0
  8. data/lib/submodules/ably-ruby/.github/workflows/check.yml +50 -0
  9. data/lib/submodules/ably-ruby/CHANGELOG.md +200 -0
  10. data/lib/submodules/ably-ruby/COPYRIGHT +1 -0
  11. data/lib/submodules/ably-ruby/LICENSE +172 -11
  12. data/lib/submodules/ably-ruby/MAINTAINERS.md +1 -0
  13. data/lib/submodules/ably-ruby/README.md +24 -22
  14. data/lib/submodules/ably-ruby/SPEC.md +1020 -929
  15. data/lib/submodules/ably-ruby/UPDATING.md +30 -0
  16. data/lib/submodules/ably-ruby/ably.gemspec +16 -23
  17. data/lib/submodules/ably-ruby/lib/ably/agent.rb +3 -0
  18. data/lib/submodules/ably-ruby/lib/ably/auth.rb +20 -10
  19. data/lib/submodules/ably-ruby/lib/ably/exceptions.rb +8 -2
  20. data/lib/submodules/ably-ruby/lib/ably/logger.rb +4 -4
  21. data/lib/submodules/ably-ruby/lib/ably/models/channel_details.rb +59 -0
  22. data/lib/submodules/ably-ruby/lib/ably/models/channel_metrics.rb +84 -0
  23. data/lib/submodules/ably-ruby/lib/ably/models/channel_occupancy.rb +43 -0
  24. data/lib/submodules/ably-ruby/lib/ably/models/channel_options.rb +97 -0
  25. data/lib/submodules/ably-ruby/lib/ably/models/channel_status.rb +53 -0
  26. data/lib/submodules/ably-ruby/lib/ably/models/connection_details.rb +8 -0
  27. data/lib/submodules/ably-ruby/lib/ably/models/delta_extras.rb +29 -0
  28. data/lib/submodules/ably-ruby/lib/ably/models/device_details.rb +1 -1
  29. data/lib/submodules/ably-ruby/lib/ably/models/error_info.rb +6 -2
  30. data/lib/submodules/ably-ruby/lib/ably/models/idiomatic_ruby_wrapper.rb +4 -0
  31. data/lib/submodules/ably-ruby/lib/ably/models/message.rb +28 -3
  32. data/lib/submodules/ably-ruby/lib/ably/models/presence_message.rb +14 -0
  33. data/lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb +31 -14
  34. data/lib/submodules/ably-ruby/lib/ably/models/token_details.rb +7 -2
  35. data/lib/submodules/ably-ruby/lib/ably/models/token_request.rb +1 -1
  36. data/lib/submodules/ably-ruby/lib/ably/modules/ably.rb +11 -1
  37. data/lib/submodules/ably-ruby/lib/ably/modules/channels_collection.rb +22 -2
  38. data/lib/submodules/ably-ruby/lib/ably/modules/conversions.rb +34 -0
  39. data/lib/submodules/ably-ruby/lib/ably/realtime/auth.rb +2 -2
  40. data/lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_manager.rb +19 -7
  41. data/lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_properties.rb +24 -0
  42. data/lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_state_machine.rb +10 -1
  43. data/lib/submodules/ably-ruby/lib/ably/realtime/channel/publisher.rb +6 -0
  44. data/lib/submodules/ably-ruby/lib/ably/realtime/channel.rb +56 -28
  45. data/lib/submodules/ably-ruby/lib/ably/realtime/channels.rb +1 -1
  46. data/lib/submodules/ably-ruby/lib/ably/realtime/client/incoming_message_dispatcher.rb +14 -6
  47. data/lib/submodules/ably-ruby/lib/ably/realtime/client.rb +9 -0
  48. data/lib/submodules/ably-ruby/lib/ably/realtime/connection/connection_manager.rb +13 -4
  49. data/lib/submodules/ably-ruby/lib/ably/realtime/connection/connection_state_machine.rb +4 -0
  50. data/lib/submodules/ably-ruby/lib/ably/realtime/connection/websocket_transport.rb +67 -1
  51. data/lib/submodules/ably-ruby/lib/ably/realtime/connection.rb +6 -5
  52. data/lib/submodules/ably-ruby/lib/ably/realtime/presence.rb +0 -14
  53. data/lib/submodules/ably-ruby/lib/ably/rest/channel.rb +44 -29
  54. data/lib/submodules/ably-ruby/lib/ably/rest/client.rb +60 -29
  55. data/lib/submodules/ably-ruby/lib/ably/rest/middleware/encoder.rb +1 -1
  56. data/lib/submodules/ably-ruby/lib/ably/rest/middleware/exceptions.rb +1 -1
  57. data/lib/submodules/ably-ruby/lib/ably/rest/middleware/external_exceptions.rb +1 -1
  58. data/lib/submodules/ably-ruby/lib/ably/rest/middleware/fail_if_unsupported_mime_type.rb +5 -2
  59. data/lib/submodules/ably-ruby/lib/ably/rest/middleware/logger.rb +1 -1
  60. data/lib/submodules/ably-ruby/lib/ably/rest/middleware/parse_json.rb +1 -1
  61. data/lib/submodules/ably-ruby/lib/ably/rest/middleware/parse_message_pack.rb +1 -1
  62. data/lib/submodules/ably-ruby/lib/ably/util/crypto.rb +1 -1
  63. data/lib/submodules/ably-ruby/lib/ably/version.rb +2 -14
  64. data/lib/submodules/ably-ruby/lib/ably.rb +1 -0
  65. data/lib/submodules/ably-ruby/spec/acceptance/realtime/auth_spec.rb +4 -4
  66. data/lib/submodules/ably-ruby/spec/acceptance/realtime/channel_history_spec.rb +25 -0
  67. data/lib/submodules/ably-ruby/spec/acceptance/realtime/channel_spec.rb +476 -21
  68. data/lib/submodules/ably-ruby/spec/acceptance/realtime/channels_spec.rb +59 -7
  69. data/lib/submodules/ably-ruby/spec/acceptance/realtime/client_spec.rb +72 -16
  70. data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_failures_spec.rb +85 -13
  71. data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_spec.rb +301 -34
  72. data/lib/submodules/ably-ruby/spec/acceptance/realtime/message_spec.rb +77 -0
  73. data/lib/submodules/ably-ruby/spec/acceptance/realtime/presence_history_spec.rb +3 -59
  74. data/lib/submodules/ably-ruby/spec/acceptance/realtime/presence_spec.rb +84 -158
  75. data/lib/submodules/ably-ruby/spec/acceptance/realtime/push_admin_spec.rb +3 -19
  76. data/lib/submodules/ably-ruby/spec/acceptance/rest/auth_spec.rb +24 -75
  77. data/lib/submodules/ably-ruby/spec/acceptance/rest/base_spec.rb +8 -4
  78. data/lib/submodules/ably-ruby/spec/acceptance/rest/channel_spec.rb +141 -10
  79. data/lib/submodules/ably-ruby/spec/acceptance/rest/channels_spec.rb +23 -6
  80. data/lib/submodules/ably-ruby/spec/acceptance/rest/client_spec.rb +146 -47
  81. data/lib/submodules/ably-ruby/spec/acceptance/rest/message_spec.rb +61 -3
  82. data/lib/submodules/ably-ruby/spec/acceptance/rest/push_admin_spec.rb +3 -19
  83. data/lib/submodules/ably-ruby/spec/lib/unit/models/channel_options_spec.rb +52 -0
  84. data/lib/submodules/ably-ruby/spec/run_parallel_tests +2 -7
  85. data/lib/submodules/ably-ruby/spec/shared/client_initializer_behaviour.rb +131 -8
  86. data/lib/submodules/ably-ruby/spec/shared/model_behaviour.rb +1 -1
  87. data/lib/submodules/ably-ruby/spec/spec_helper.rb +12 -2
  88. data/lib/submodules/ably-ruby/spec/support/serialization_helper.rb +21 -0
  89. data/lib/submodules/ably-ruby/spec/support/test_app.rb +3 -3
  90. data/lib/submodules/ably-ruby/spec/unit/logger_spec.rb +6 -14
  91. data/lib/submodules/ably-ruby/spec/unit/models/channel_details_spec.rb +30 -0
  92. data/lib/submodules/ably-ruby/spec/unit/models/channel_metrics_spec.rb +42 -0
  93. data/lib/submodules/ably-ruby/spec/unit/models/channel_occupancy_spec.rb +17 -0
  94. data/lib/submodules/ably-ruby/spec/unit/models/channel_status_spec.rb +36 -0
  95. data/lib/submodules/ably-ruby/spec/unit/models/delta_extras_spec.rb +14 -0
  96. data/lib/submodules/ably-ruby/spec/unit/models/error_info_spec.rb +17 -1
  97. data/lib/submodules/ably-ruby/spec/unit/models/message_spec.rb +97 -0
  98. data/lib/submodules/ably-ruby/spec/unit/models/presence_message_spec.rb +49 -0
  99. data/lib/submodules/ably-ruby/spec/unit/models/protocol_message_spec.rb +125 -27
  100. data/lib/submodules/ably-ruby/spec/unit/models/token_details_spec.rb +14 -0
  101. data/lib/submodules/ably-ruby/spec/unit/realtime/channel_spec.rb +3 -2
  102. data/lib/submodules/ably-ruby/spec/unit/realtime/channels_spec.rb +53 -15
  103. data/lib/submodules/ably-ruby/spec/unit/realtime/client_spec.rb +19 -6
  104. data/lib/submodules/ably-ruby/spec/unit/realtime/incoming_message_dispatcher_spec.rb +38 -0
  105. data/lib/submodules/ably-ruby/spec/unit/rest/channel_spec.rb +44 -1
  106. data/lib/submodules/ably-ruby/spec/unit/rest/channels_spec.rb +81 -14
  107. data/lib/submodules/ably-ruby/spec/unit/rest/client_spec.rb +47 -0
  108. data/spec/spec_helper.rb +5 -0
  109. data/spec/unit/client_spec.rb +30 -0
  110. metadata +88 -25
  111. data/lib/submodules/ably-ruby/.travis.yml +0 -19
@@ -0,0 +1,30 @@
1
+ # Upgrade / Migration Guide
2
+
3
+ ## Version 1.1.8 to 1.2.0
4
+
5
+ ### Notable Changes
6
+ This release is all about channel options. Here is the full [changelog](https://github.com/ably/ably-ruby/blob/main/CHANGELOG.md)
7
+
8
+ * Channel options were extracted into a seperate model [ChannelOptions](https://github.com/ably/ably-ruby/blob/main/lib/ably/models/channel_options.rb). However it's still backward campatible with `Hash` and you don't need to do make any adjustments to your code
9
+
10
+ * The `ChannelOptions` class now supports `:params`, `:modes` and `:cipher` as options. Previously only `:cipher` was available
11
+
12
+ * The client `:idempotent_rest_publishing` option is `true` by default. Previously `:idempotent_rest_publishing` was `false` by default.
13
+
14
+ ### Breaking Changes
15
+
16
+ * Changing channel options with `Channels#get` is now deprecated in favor of explicit options change
17
+
18
+ 1. If channel state is attached or attaching an exception will be raised
19
+ 2. Otherwise the library will emit a warning
20
+
21
+ For example, the following code
22
+ ```
23
+ client.channels.get(channel_name, new_channel_options)
24
+ ```
25
+
26
+ Should be changed to:
27
+ ```
28
+ channel = client.channels.get(channel_name)
29
+ channel.options = new_channel_options
30
+ ```
@@ -20,38 +20,31 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency 'eventmachine', '~> 1.2.6'
22
22
  spec.add_runtime_dependency 'em-http-request', '~> 1.1'
23
- spec.add_runtime_dependency 'statesman', '~> 1.0.0'
24
- spec.add_runtime_dependency 'faraday', '~> 0.12'
25
- spec.add_runtime_dependency 'excon', '~> 0.55'
26
-
27
- if RUBY_VERSION.match(/^1\./)
28
- spec.add_runtime_dependency 'json', '< 2.0'
29
- else
30
- spec.add_runtime_dependency 'json'
31
- end
23
+ spec.add_runtime_dependency 'statesman', '~> 9.0'
24
+ spec.add_runtime_dependency 'faraday', '~> 2.2'
25
+ spec.add_runtime_dependency 'faraday-typhoeus', '~> 0.2.0'
26
+ spec.add_runtime_dependency 'typhoeus', '~> 1.4'
27
+ spec.add_runtime_dependency 'json'
32
28
  spec.add_runtime_dependency 'websocket-driver', '~> 0.7'
33
29
  spec.add_runtime_dependency 'msgpack', '>= 1.3.0'
34
30
  spec.add_runtime_dependency 'addressable', '>= 2.0.0'
35
31
 
36
- spec.add_development_dependency 'rake', '~> 11.3'
32
+ spec.add_development_dependency 'rake', '~> 13.0'
37
33
  spec.add_development_dependency 'redcarpet', '~> 3.3'
38
- spec.add_development_dependency 'rspec', '~> 3.3.0' # version lock, see config.around(:example, :event_machine) in event_machine_helper.rb
34
+ spec.add_development_dependency 'rspec', '~> 3.11.0'
35
+ spec.add_development_dependency 'rspec_junit_formatter', '~> 0.5.1'
39
36
  spec.add_development_dependency 'rspec-retry', '~> 0.6'
40
37
  spec.add_development_dependency 'yard', '~> 0.9'
41
38
  spec.add_development_dependency 'rspec-instafail', '~> 1.0'
42
39
  spec.add_development_dependency 'bundler', '>= 1.3.0'
40
+ spec.add_development_dependency 'webmock', '~> 3.11'
41
+ spec.add_development_dependency 'simplecov', '~> 0.21.2'
42
+ spec.add_development_dependency 'simplecov-lcov', '~> 0.8.0'
43
+ spec.add_development_dependency 'parallel_tests', '~> 3.8'
44
+ spec.add_development_dependency 'pry', '~> 0.14.1'
45
+ spec.add_development_dependency 'pry-byebug', '~> 3.8.0'
43
46
 
44
- if RUBY_VERSION.match(/^1\./)
45
- spec.add_development_dependency 'public_suffix', '~> 1.4.6' # Later versions do not support Ruby 1.9
46
- spec.add_development_dependency 'webmock', '2.2'
47
- spec.add_development_dependency 'parallel_tests', '~> 2.9.0'
48
- else
49
- spec.add_development_dependency 'webmock', '~> 2.2'
50
- spec.add_development_dependency 'coveralls'
51
- spec.add_development_dependency 'parallel_tests', '~> 2.22'
52
- if !RUBY_VERSION.match(/^2\.[0123]/)
53
- spec.add_development_dependency 'pry'
54
- spec.add_development_dependency 'pry-byebug'
55
- end
47
+ if RUBY_VERSION.match(/^3\./)
48
+ spec.add_development_dependency 'webrick', '~> 1.7.0'
56
49
  end
57
50
  end
@@ -0,0 +1,3 @@
1
+ module Ably
2
+ AGENT = "ably-ruby/#{Ably::VERSION} ruby/#{RUBY_VERSION}"
3
+ end
@@ -5,9 +5,9 @@ require 'securerandom'
5
5
  require 'ably/rest/middleware/external_exceptions'
6
6
 
7
7
  module Ably
8
- # Auth is responsible for authentication with {https://www.ably.io Ably} using basic or token authentication
8
+ # Auth is responsible for authentication with {https://www.ably.com Ably} using basic or token authentication
9
9
  #
10
- # Find out more about Ably authentication at: https://www.ably.io/documentation/general/authentication/
10
+ # Find out more about Ably authentication at: https://www.ably.com/docs/general/authentication/
11
11
  #
12
12
  # @!attribute [r] client_id
13
13
  # @return [String] The provided client ID, used for identifying this client for presence purposes
@@ -35,7 +35,7 @@ module Ably
35
35
 
36
36
  API_KEY_REGEX = /^[\w-]{2,}\.[\w-]{2,}:[\w-]{2,}$/
37
37
 
38
- # Supported AuthOption keys, see https://www.ably.io/documentation/realtime/types#auth-options
38
+ # Supported AuthOption keys, see https://www.ably.com/docs/realtime/types#auth-options
39
39
  # TODO: Review client_id usage embedded incorrectly within AuthOptions.
40
40
  # This is legacy code to configure a client with a client_id from the ClientOptions
41
41
  # TODO: Review inclusion of use_token_auth, ttl, token_params in auth options
@@ -103,7 +103,6 @@ module Ably
103
103
  end
104
104
 
105
105
  if has_client_id? && !token_creatable_externally? && !token_option
106
- raise ArgumentError, 'client_id cannot be provided without a complete API key or means to authenticate. An API key is needed to automatically authenticate with Ably and obtain a token' unless api_key_present?
107
106
  @client_id = ensure_utf_8(:client_id, client_id) if client_id
108
107
  end
109
108
 
@@ -278,7 +277,7 @@ module Ably
278
277
  #
279
278
  # @param [Hash] token_params the token params used in the token request
280
279
  # @option token_params [String] :client_id A client ID to associate with this token. The generated token may be used to authenticate as this +client_id+
281
- # @option token_params [Integer] :ttl validity time in seconds for the requested {Ably::Models::TokenDetails}. Limits may apply, see {https://www.ably.io/documentation/other/authentication}
280
+ # @option token_params [Integer] :ttl validity time in seconds for the requested {Ably::Models::TokenDetails}. Limits may apply, see {https://www.ably.com/docs/general/authentication}
282
281
  # @option token_params [Hash] :capability canonicalised representation of the resource paths and associated operations
283
282
  # @option token_params [Time] :timestamp the time of the request
284
283
  # @option token_params [String] :nonce an unquoted, unescaped random string of at least 16 characters
@@ -286,7 +285,7 @@ module Ably
286
285
  # @param [Hash] auth_options the authentication options for the token request
287
286
  # @option auth_options [String] :key API key comprising the key name and key secret in a single string
288
287
  # @option auth_options [String] :client_id client ID identifying this connection to other clients (will use +client_id+ specified when library was instanced if provided)
289
- # @option auth_options [Boolean] :query_time when true will query the {https://www.ably.io Ably} system for the current time instead of using the local time
288
+ # @option auth_options [Boolean] :query_time when true will query the {https://www.ably.com Ably} system for the current time instead of using the local time
290
289
  # @option auth_options [Hash] :token_params convenience to pass in +token_params+ within the +auth_options+ argument, especially useful when setting default token_params in the client constructor
291
290
  #
292
291
  # @return [Models::TokenRequest]
@@ -377,7 +376,7 @@ module Ably
377
376
  # True when Token Auth is being used to authenticate with Ably
378
377
  def using_token_auth?
379
378
  return options[:use_token_auth] if options.has_key?(:use_token_auth)
380
- !!(token_option || current_token_details || has_client_id? || token_creatable_externally?)
379
+ !!(token_option || current_token_details || token_creatable_externally?)
381
380
  end
382
381
 
383
382
  def client_id
@@ -408,6 +407,17 @@ module Ably
408
407
  end
409
408
  end
410
409
 
410
+ # Extra headers that may be used during authentication
411
+ #
412
+ # @return [Hash] headers
413
+ def extra_auth_headers
414
+ if client_id && using_basic_auth?
415
+ { 'X-Ably-ClientId' => Base64.urlsafe_encode64(client_id) }
416
+ else
417
+ {}
418
+ end
419
+ end
420
+
411
421
  # Auth params used in URI endpoint for Realtime connections
412
422
  # Will reauthorize implicitly if required and capable
413
423
  #
@@ -500,11 +510,11 @@ module Ably
500
510
  end
501
511
 
502
512
  def authorize_when_necessary
503
- if current_token_details && !current_token_details.expired?
513
+ if current_token_details && !current_token_details.expired?(from: current_time)
504
514
  return current_token_details
505
- else
506
- authorize
507
515
  end
516
+
517
+ authorize
508
518
  end
509
519
 
510
520
  # Returns the current device clock time unless the
@@ -5,7 +5,7 @@ module Ably
5
5
  TOKEN_EXPIRED_CODE = 40140..40149
6
6
 
7
7
  # Base Ably exception class that contains status and code values used by Ably
8
- # Refer to https://github.com/ably/ably-common/blob/master/protocol/errors.json
8
+ # Refer to https://github.com/ably/ably-common/blob/main/protocol/errors.json
9
9
  #
10
10
  # @!attribute [r] message
11
11
  # @return [String] Error message from Ably
@@ -52,6 +52,12 @@ module Ably
52
52
  end
53
53
  end
54
54
 
55
+ # Maximum frame size exceeded TO3l9
56
+ class MaxFrameSizeExceeded < BaseAblyException; end
57
+
58
+ # Maximum message size exceeded TO3l8
59
+ class MaxMessageSizeExceeded < BaseAblyException; end
60
+
55
61
  # An invalid request was received by Ably
56
62
  class InvalidRequest < BaseAblyException; end
57
63
 
@@ -116,7 +122,7 @@ module Ably
116
122
  class InvalidState < BaseAblyException; end
117
123
 
118
124
  # A generic Ably exception taht supports a status & code.
119
- # See https://github.com/ably/ably-common/blob/master/protocol/errors.json for a list of Ably errors
125
+ # See https://github.com/ably/ably-common/blob/main/protocol/errors.json for a list of Ably errors
120
126
  class Standard < BaseAblyException; end
121
127
 
122
128
  # The HTTP request has returned a 500 error
@@ -7,9 +7,9 @@ module Ably
7
7
  extend Forwardable
8
8
 
9
9
  # @param client [Ably::Rest::Client,Ably::Realtime::Client] Rest or Realtime Ably client
10
- # @param log_level [Integer] {http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html Ruby Logger} log level
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
- # however it must provide a {http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html Ruby Logger} compatible interface.
12
+ # however it must provide a {http://www.ruby-doc.org/stdlib-3.1.1/libdoc/logger/rdoc/Logger.html Ruby Logger} compatible interface.
13
13
  #
14
14
  def initialize(client, log_level, custom_logger = nil)
15
15
  @client = client
@@ -24,7 +24,7 @@ module Ably
24
24
  @log_mutex = Mutex.new
25
25
  end
26
26
 
27
- # The logger used by this class, defaults to {http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html Ruby Logger}
27
+ # The logger used by this class, defaults to {http://www.ruby-doc.org/stdlib-3.1.1/libdoc/logger/rdoc/Logger.html Ruby Logger}
28
28
  # @return {Object,Logger}
29
29
  attr_reader :logger
30
30
 
@@ -32,7 +32,7 @@ module Ably
32
32
  # @return {nil,Object}
33
33
  attr_reader :custom_logger
34
34
 
35
- # The log level ranging from DEBUG to FATAL, refer to http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html
35
+ # The log level ranging from DEBUG to FATAL, refer to http://www.ruby-doc.org/stdlib-3.1.1/libdoc/logger/rdoc/Logger.html
36
36
  # @return {Integer}
37
37
  attr_reader :log_level
38
38
 
@@ -0,0 +1,59 @@
1
+ module Ably::Models
2
+ # Convert token details argument to a {ChannelDetails} object
3
+ #
4
+ # @param attributes (see #initialize)
5
+ #
6
+ # @return [ChannelDetails]
7
+ def self.ChannelDetails(attributes)
8
+ case attributes
9
+ when ChannelDetails
10
+ return attributes
11
+ else
12
+ ChannelDetails.new(attributes)
13
+ end
14
+ end
15
+
16
+ # ChannelDetails is a type that represents information for a channel including channelId, name, status and occupancy (CHD1)
17
+ #
18
+ class ChannelDetails
19
+ extend Ably::Modules::Enum
20
+ extend Forwardable
21
+ include Ably::Modules::ModelCommon
22
+
23
+ # The attributes of ChannelDetails (CHD2)
24
+ #
25
+ attr_reader :attributes
26
+
27
+ alias_method :to_h, :attributes
28
+
29
+ # Initialize a new ChannelDetails
30
+ #
31
+ def initialize(attrs)
32
+ @attributes = IdiomaticRubyWrapper(attrs.clone)
33
+ end
34
+
35
+ # The identifier of the channel (CHD2a)
36
+ #
37
+ # @return [String]
38
+ #
39
+ def channel_id
40
+ attributes[:channel_id]
41
+ end
42
+
43
+ # The identifier of the channel (CHD2a)
44
+ #
45
+ # @return [String]
46
+ #
47
+ def name
48
+ attributes[:name]
49
+ end
50
+
51
+ # The status of the channel (CHD2b)
52
+ #
53
+ # @return [Ably::Models::ChannelStatus, nil]
54
+ #
55
+ def status
56
+ Ably::Models::ChannelStatus(attributes[:status])
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,84 @@
1
+ module Ably::Models
2
+ # Convert token details argument to a {ChannelMetrics} object
3
+ #
4
+ # @param attributes (see #initialize)
5
+ #
6
+ # @return [ChannelMetrics]
7
+ def self.ChannelMetrics(attributes)
8
+ case attributes
9
+ when ChannelMetrics
10
+ return attributes
11
+ else
12
+ ChannelMetrics.new(attributes)
13
+ end
14
+ end
15
+
16
+ # ChannelMetrics is a type that contains the count of publishers and subscribers, connections and presenceConnections,
17
+ # presenceMembers and presenceSubscribers (CHM1)
18
+ #
19
+ class ChannelMetrics
20
+ extend Ably::Modules::Enum
21
+ extend Forwardable
22
+ include Ably::Modules::ModelCommon
23
+
24
+ # The attributes of ChannelMetrics (CHM2)
25
+ #
26
+ attr_reader :attributes
27
+
28
+ alias_method :to_h, :attributes
29
+
30
+ # Initialize a new ChannelMetrics
31
+ #
32
+ def initialize(attrs)
33
+ @attributes = IdiomaticRubyWrapper(attrs.clone)
34
+ end
35
+
36
+ # The total number of connections to the channel (CHM2a)
37
+ #
38
+ # @return [Integer]
39
+ #
40
+ def connections
41
+ attributes[:connections]
42
+ end
43
+
44
+ # The total number of presence connections to the channel (CHM2b)
45
+ #
46
+ # @return [Integer]
47
+ #
48
+ def presence_connections
49
+ attributes[:presence_connections]
50
+ end
51
+
52
+ # The total number of presence members for the channel (CHM2c)
53
+ #
54
+ # @return [Integer]
55
+ #
56
+ def presence_members
57
+ attributes[:presence_members]
58
+ end
59
+
60
+ # The total number of presence subscribers for the channel (CHM2d)
61
+ #
62
+ # @return [Integer]
63
+ #
64
+ def presence_subscribers
65
+ attributes[:presence_subscribers]
66
+ end
67
+
68
+ # The total number of publishers to the channel (CHM2e)
69
+ #
70
+ # @return [Integer]
71
+ #
72
+ def publishers
73
+ attributes[:publishers]
74
+ end
75
+
76
+ # The total number of subscribers to the channel (CHM2f)
77
+ #
78
+ # @return [Integer]
79
+ #
80
+ def subscribers
81
+ attributes[:subscribers]
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,43 @@
1
+ module Ably::Models
2
+ # Convert token details argument to a {ChannelOccupancy} object
3
+ #
4
+ # @param attributes (see #initialize)
5
+ #
6
+ # @return [ChannelOccupancy]
7
+ def self.ChannelOccupancy(attributes)
8
+ case attributes
9
+ when ChannelOccupancy
10
+ return attributes
11
+ else
12
+ ChannelOccupancy.new(attributes)
13
+ end
14
+ end
15
+
16
+ # Type that contain channel metrics (CHO1)
17
+ #
18
+ class ChannelOccupancy
19
+ extend Ably::Modules::Enum
20
+ extend Forwardable
21
+ include Ably::Modules::ModelCommon
22
+
23
+ # The attributes of ChannelOccupancy (CH02)
24
+ #
25
+ attr_reader :attributes
26
+
27
+ alias_method :to_h, :attributes
28
+
29
+ # Initialize a new ChannelOccupancy
30
+ #
31
+ def initialize(attrs)
32
+ @attributes = IdiomaticRubyWrapper(attrs.clone)
33
+ end
34
+
35
+ # Metrics object (CHO2a)
36
+ #
37
+ # @return [Ably::Models::ChannelMetrics, nil]
38
+ #
39
+ def metrics
40
+ Ably::Models::ChannelMetrics(attributes[:metrics])
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,97 @@
1
+ module Ably::Models
2
+ # Convert token details argument to a {ChannelOptions} object
3
+ #
4
+ # @param attributes (see #initialize)
5
+ #
6
+ # @return [ChannelOptions]
7
+ def self.ChannelOptions(attributes)
8
+ case attributes
9
+ when ChannelOptions
10
+ return attributes
11
+ else
12
+ ChannelOptions.new(attributes)
13
+ end
14
+ end
15
+
16
+ # Represents options of a channel
17
+ class ChannelOptions
18
+ extend Ably::Modules::Enum
19
+ extend Forwardable
20
+ include Ably::Modules::ModelCommon
21
+
22
+ MODES = ruby_enum('MODES',
23
+ presence: 0,
24
+ publish: 1,
25
+ subscribe: 2,
26
+ presence_subscribe: 3
27
+ )
28
+
29
+ attr_reader :attributes
30
+
31
+ alias_method :to_h, :attributes
32
+
33
+ def_delegators :attributes, :fetch, :size, :empty?
34
+ # Initialize a new ChannelOptions
35
+ #
36
+ # @option params [Hash] (TB2c) params (for realtime client libraries only) a of key/value pairs
37
+ # @option modes [Hash] modes (for realtime client libraries only) an array of ChannelMode
38
+ # @option cipher [Hash,Ably::Models::CipherParams] :cipher A hash of options or a {Ably::Models::CipherParams} to configure the encryption. *:key* is required, all other options are optional.
39
+ #
40
+ def initialize(attrs)
41
+ @attributes = IdiomaticRubyWrapper(attrs.clone)
42
+
43
+ attributes[:modes] = modes.to_a.map { |mode| Ably::Models::ChannelOptions::MODES[mode] } if modes
44
+ attributes[:cipher] = Ably::Models::CipherParams(cipher) if cipher
45
+ attributes.clone
46
+ end
47
+
48
+ # @!attribute cipher
49
+ #
50
+ # @return [CipherParams]
51
+ def cipher
52
+ attributes[:cipher]
53
+ end
54
+
55
+ # @!attribute params
56
+ #
57
+ # @return [Hash]
58
+ def params
59
+ attributes[:params].to_h
60
+ end
61
+
62
+ # @!attribute modes
63
+ #
64
+ # @return [Array<ChannelOptions::MODES>]
65
+ def modes
66
+ attributes[:modes]
67
+ end
68
+
69
+ # Converts modes to a bitfield that coresponds to ProtocolMessage#flags
70
+ #
71
+ # @return [Integer]
72
+ def modes_to_flags
73
+ modes.map { |mode| Ably::Models::ProtocolMessage::ATTACH_FLAGS_MAPPING[mode.to_sym] }.reduce(:|)
74
+ end
75
+
76
+ # @return [Hash]
77
+ # @api private
78
+ def set_params(hash)
79
+ attributes[:params] = hash
80
+ end
81
+
82
+ # Sets modes from ProtocolMessage#flags
83
+ #
84
+ # @return [Array<ChannelOptions::MODES>]
85
+ # @api private
86
+ def set_modes_from_flags(flags)
87
+ return unless flags
88
+
89
+ message_modes = MODES.select do |mode|
90
+ flag = Ably::Models::ProtocolMessage::ATTACH_FLAGS_MAPPING[mode.to_sym]
91
+ flags & flag == flag
92
+ end
93
+
94
+ attributes[:modes] = message_modes.map { |mode| Ably::Models::ChannelOptions::MODES[mode] }
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,53 @@
1
+ module Ably::Models
2
+ # Convert token details argument to a {ChannelStatus} object
3
+ #
4
+ # @param attributes (see #initialize)
5
+ #
6
+ # @return [ChannelStatus]
7
+ def self.ChannelStatus(attributes)
8
+ case attributes
9
+ when ChannelStatus
10
+ return attributes
11
+ else
12
+ ChannelStatus.new(attributes)
13
+ end
14
+ end
15
+
16
+ # ChannelStatus is a type that contains status and occupancy for a channel (CHS1)
17
+ #
18
+ class ChannelStatus
19
+ extend Ably::Modules::Enum
20
+ extend Forwardable
21
+ include Ably::Modules::ModelCommon
22
+
23
+ # The attributes of ChannelStatus (CHS2)
24
+ #
25
+ attr_reader :attributes
26
+
27
+ alias_method :to_h, :attributes
28
+
29
+ # Initialize a new ChannelStatus
30
+ #
31
+ def initialize(attrs)
32
+ @attributes = IdiomaticRubyWrapper(attrs.clone)
33
+ end
34
+
35
+ # Represents if the channel is active (CHS2a)
36
+ #
37
+ # @return [Boolean]
38
+ #
39
+ def is_active
40
+ attributes[:isActive]
41
+ end
42
+ alias_method :active?, :is_active
43
+ alias_method :is_active?, :is_active
44
+
45
+ # Occupancy ChannelOccupancy – occupancy is an object containing the metrics for the channel (CHS2b)
46
+ #
47
+ # @return [Ably::Models::ChannelOccupancy, nil]
48
+ #
49
+ def occupancy
50
+ Ably::Models::ChannelOccupancy(attributes[:occupancy])
51
+ end
52
+ end
53
+ end
@@ -21,6 +21,12 @@ module Ably::Models
21
21
  class ConnectionDetails
22
22
  include Ably::Modules::ModelCommon
23
23
 
24
+ # Max message size
25
+ MAX_MESSAGE_SIZE = 65536 # See spec TO3l8
26
+
27
+ # Max frame size
28
+ MAX_FRAME_SIZE = 524288 # See spec TO3l9
29
+
24
30
  # @param attributes [Hash]
25
31
  # @option attributes [String] :client_id contains the client ID assigned to the connection
26
32
  # @option attributes [String] :connection_key the connection secret key string that is used to resume a connection and its state
@@ -38,6 +44,8 @@ module Ably::Models
38
44
  self.attributes[duration_field] = (self.attributes[duration_field].to_f / 1000).round
39
45
  end
40
46
  end
47
+ self.attributes[:max_message_size] ||= MAX_MESSAGE_SIZE
48
+ self.attributes[:max_frame_size] ||= MAX_FRAME_SIZE
41
49
  self.attributes.freeze
42
50
  end
43
51
 
@@ -0,0 +1,29 @@
1
+ module Ably::Models
2
+ #
3
+ # @!attribute [r] from
4
+ # @return [String] The id of the message the delta was generated from
5
+ # @!attribute [r] format
6
+ # @return [String] The delta format. Only vcdiff is supported as at API version 1.2
7
+ #
8
+ class DeltaExtras
9
+ include Ably::Modules::ModelCommon
10
+
11
+ # The id of the message the delta was generated from.
12
+ # @return [String, nil]
13
+ #
14
+ attr_reader :from
15
+
16
+ # The delta format.
17
+ # @return [String, nil]
18
+ #
19
+ attr_reader :format
20
+
21
+ def initialize(attributes = {})
22
+ @from, @format = IdiomaticRubyWrapper((attributes || {}), stop_at: [:from, :format]).attributes.values_at(:from, :format)
23
+ end
24
+
25
+ def to_json(*args)
26
+ as_json(args).to_json
27
+ end
28
+ end
29
+ end
@@ -27,7 +27,7 @@ module Ably::Models
27
27
  # @!attribute [r] form_factor
28
28
  # @return [String] Device form factor such as phone, tablet, watch
29
29
  # @!attribute [r] client_id
30
- # @return [String] The authenticated client identifier for this device. See {https://www.ably.io/documentation/general/authentication#identified-clients auth documentation}.
30
+ # @return [String] The authenticated client identifier for this device. See {https://www.ably.com/docs/general/authentication#identified-clients auth documentation}.
31
31
  # @!attribute [r] metadata
32
32
  # @return [Hash] Arbitrary metadata that can be associated with a device
33
33
  # @!attribute [r] device_secret
@@ -27,6 +27,10 @@ module Ably::Models
27
27
  # @return [Integer] Ably error code (see ably-common/protocol/errors.json)
28
28
  # @!attribute [r] status
29
29
  # @return [Integer] HTTP Status Code corresponding to this error, where applicable
30
+ # @!attribute [r] request_id
31
+ # @return [Integer] HTTP RequestId corresponding to this error, where applicable (#RSC7c)
32
+ # @!attribute [r] cause
33
+ # @return [Integer] HTTP Status Code corresponding to this error, where applicable (#TI1)
30
34
  # @!attribute [r] attributes
31
35
  # @return [Hash] Access the protocol message Hash object ruby'fied to use symbolized keys
32
36
  #
@@ -38,7 +42,7 @@ module Ably::Models
38
42
  @hash_object = IdiomaticRubyWrapper(hash_object.clone.freeze)
39
43
  end
40
44
 
41
- %w(message code href status_code).each do |attribute|
45
+ %w(message code href status_code request_id cause).each do |attribute|
42
46
  define_method attribute do
43
47
  attributes[attribute.to_sym]
44
48
  end
@@ -52,7 +56,7 @@ module Ably::Models
52
56
  def to_s
53
57
  error_href = href || (code ? "https://help.ably.io/error/#{code}" : '')
54
58
  see_msg = " -> see #{error_href} for help" unless message.to_s.include?(error_href.to_s)
55
- "<Error: #{message} (code: #{code}, http status: #{status})>#{see_msg}"
59
+ "<Error: #{message} (code: #{code}, http status: #{status} request_id: #{request_id} cause: #{cause})>#{see_msg}"
56
60
  end
57
61
  end
58
62
  end
@@ -94,6 +94,10 @@ module Ably::Models
94
94
  attributes.size
95
95
  end
96
96
 
97
+ def empty?
98
+ attributes.empty?
99
+ end
100
+
97
101
  def keys
98
102
  map { |key, value| key }
99
103
  end