ably 1.1.8 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/check.yml +14 -5
- data/CHANGELOG.md +48 -0
- data/README.md +2 -2
- data/UPDATING.md +30 -0
- data/ably.gemspec +12 -24
- data/lib/ably/auth.rb +8 -8
- data/lib/ably/logger.rb +4 -4
- data/lib/ably/models/channel_details.rb +59 -0
- data/lib/ably/models/channel_metrics.rb +84 -0
- data/lib/ably/models/channel_occupancy.rb +43 -0
- data/lib/ably/models/channel_options.rb +97 -0
- data/lib/ably/models/channel_status.rb +53 -0
- data/lib/ably/models/device_details.rb +1 -1
- data/lib/ably/models/idiomatic_ruby_wrapper.rb +4 -0
- data/lib/ably/models/message.rb +4 -4
- data/lib/ably/models/protocol_message.rb +19 -7
- data/lib/ably/models/token_details.rb +7 -2
- data/lib/ably/models/token_request.rb +1 -1
- data/lib/ably/modules/ably.rb +1 -1
- data/lib/ably/modules/channels_collection.rb +22 -2
- data/lib/ably/modules/conversions.rb +34 -0
- data/lib/ably/realtime/auth.rb +2 -2
- data/lib/ably/realtime/channel/channel_manager.rb +16 -4
- data/lib/ably/realtime/channel/channel_state_machine.rb +5 -0
- data/lib/ably/realtime/channel.rb +54 -24
- data/lib/ably/realtime/channels.rb +1 -1
- data/lib/ably/rest/channel.rb +33 -34
- data/lib/ably/rest/client.rb +8 -5
- data/lib/ably/rest/middleware/encoder.rb +1 -1
- data/lib/ably/rest/middleware/exceptions.rb +1 -1
- data/lib/ably/rest/middleware/external_exceptions.rb +1 -1
- data/lib/ably/rest/middleware/fail_if_unsupported_mime_type.rb +1 -1
- data/lib/ably/rest/middleware/logger.rb +1 -1
- data/lib/ably/rest/middleware/parse_json.rb +1 -1
- data/lib/ably/rest/middleware/parse_message_pack.rb +1 -1
- data/lib/ably/util/crypto.rb +1 -1
- data/lib/ably/version.rb +2 -2
- data/spec/acceptance/realtime/channel_spec.rb +247 -21
- data/spec/acceptance/realtime/channels_spec.rb +59 -7
- data/spec/acceptance/realtime/connection_spec.rb +21 -1
- data/spec/acceptance/realtime/message_spec.rb +77 -0
- data/spec/acceptance/rest/auth_spec.rb +18 -0
- data/spec/acceptance/rest/channel_spec.rb +19 -1
- data/spec/acceptance/rest/channels_spec.rb +22 -5
- data/spec/acceptance/rest/client_spec.rb +3 -3
- data/spec/acceptance/rest/message_spec.rb +61 -3
- data/spec/lib/unit/models/channel_options_spec.rb +52 -0
- data/spec/run_parallel_tests +2 -7
- data/spec/unit/logger_spec.rb +6 -14
- data/spec/unit/models/channel_details_spec.rb +30 -0
- data/spec/unit/models/channel_metrics_spec.rb +42 -0
- data/spec/unit/models/channel_occupancy_spec.rb +17 -0
- data/spec/unit/models/channel_status_spec.rb +36 -0
- data/spec/unit/models/message_spec.rb +14 -0
- data/spec/unit/models/protocol_message_spec.rb +53 -7
- data/spec/unit/models/token_details_spec.rb +14 -0
- data/spec/unit/realtime/channels_spec.rb +52 -14
- data/spec/unit/rest/channels_spec.rb +81 -14
- metadata +69 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 254c6088b3e3ef0d8cd6d2837b4efc73c2c7c04d8b7d4c61d416f023a8933603
|
4
|
+
data.tar.gz: 91d7b17e533b41ede327696aff66dd97ea35d6f7cf2a9fee9fd467fa42e9041e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d51a067f02691481cf9489f82334f9200ef9ae00d71c2639c26a8d0b8fa62fbd76921fafb114699d4bf0d8e0f0e46f865bb07411a4dc4d6197a7ffeb9ebd6be
|
7
|
+
data.tar.gz: a392f7f5ec08ab445aaad519e45dc841090950402516ef2bafe3863817af77536b85549701acfc52e4a171544b79a190b499b3f8d32552a9a08973bf60831c3d
|
data/.github/workflows/check.yml
CHANGED
@@ -10,8 +10,9 @@ jobs:
|
|
10
10
|
continue-on-error: true
|
11
11
|
strategy:
|
12
12
|
matrix:
|
13
|
-
ruby: [ '2.
|
13
|
+
ruby: [ '2.7', '3.0', '3.1' ]
|
14
14
|
protocol: [ 'json', 'msgpack' ]
|
15
|
+
type: [ 'unit', 'acceptance' ]
|
15
16
|
steps:
|
16
17
|
- uses: actions/checkout@v2
|
17
18
|
with:
|
@@ -20,15 +21,23 @@ jobs:
|
|
20
21
|
with:
|
21
22
|
ruby-version: ${{ matrix.ruby }}
|
22
23
|
bundler-cache: true
|
23
|
-
-
|
24
|
-
|
24
|
+
- name: 'Run ${{ matrix.type }} tests on ruby ${{ matrix.ruby }} (${{ matrix.protocol }} protocol)'
|
25
|
+
env:
|
25
26
|
PARALLEL_TEST_PROCESSORS: 2
|
27
|
+
RSPEC_RETRY: true
|
26
28
|
PROTOCOL: ${{ matrix.protocol }}
|
27
|
-
run:
|
29
|
+
run: bundle exec parallel_rspec --prefix-output-with-test-env-number -- --format documentation --format RspecJunitFormatter --out ${{ matrix.protocol }}-${{ matrix.type }}-ruby-${{ matrix.ruby }}.junit -- spec/${{ matrix.type }}
|
30
|
+
- name: Upload test results
|
31
|
+
if: always()
|
32
|
+
uses: ably-labs/test-observability-action@main
|
33
|
+
with:
|
34
|
+
server-url: 'https://test-observability.herokuapp.com'
|
35
|
+
server-auth: ${{ secrets.TEST_OBSERVABILITY_SERVER_AUTH_KEY }}
|
36
|
+
path: '.'
|
28
37
|
- uses: coverallsapp/github-action@1.1.3
|
29
38
|
with:
|
30
39
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
31
|
-
flag-name:
|
40
|
+
flag-name: ruby-${{ matrix.ruby }}-${{ matrix.protocol }}-${{ matrix.type }}
|
32
41
|
parallel: true
|
33
42
|
finish:
|
34
43
|
needs: check
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,53 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v1.2.2](https://github.com/ably/ably-ruby/tree/v1.2.2)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/ably/ably-ruby/compare/v1.2.1...v1.2.2)
|
6
|
+
|
7
|
+
**Implemented enhancements:**
|
8
|
+
|
9
|
+
- Add support to get channel lifecycle status [\#362](https://github.com/ably/ably-ruby/issues/362)
|
10
|
+
|
11
|
+
## [v1.2.1](https://github.com/ably/ably-ruby/tree/v1.2.1)
|
12
|
+
|
13
|
+
[Full Changelog](https://github.com/ably/ably-ruby/compare/v1.2.0...v1.2.1)
|
14
|
+
|
15
|
+
**Fixed bugs:**
|
16
|
+
|
17
|
+
- Update Ruby version \(and Gemfile.lock dependencies\) [\#253](https://github.com/ably/ably-ruby/issues/253)
|
18
|
+
- Error not emitted when failing to connect to an endpoint indefinitely [\#233](https://github.com/ably/ably-ruby/issues/233)
|
19
|
+
- Connection errors when there should be warnings [\#198](https://github.com/ably/ably-ruby/issues/198)
|
20
|
+
- Implement presence re-entry requirement change for 1.1 [\#185](https://github.com/ably/ably-ruby/issues/185)
|
21
|
+
|
22
|
+
**Closed issues:**
|
23
|
+
|
24
|
+
- Update urls in readme [\#353](https://github.com/ably/ably-ruby/issues/353)
|
25
|
+
- Reconsider required Ruby version [\#344](https://github.com/ably/ably-ruby/issues/344)
|
26
|
+
|
27
|
+
## [v1.2.0](https://github.com/ably/ably-ruby/tree/v1.2.0)
|
28
|
+
|
29
|
+
[Full Changelog](https://github.com/ably/ably-ruby/compare/v1.1.8...v1.2.0)
|
30
|
+
|
31
|
+
This release updates ably-ruby to be compliant with the 1.2 version of the Ably client library feature specification. There are some minor breaking changes, please see [the migration guide](./UPDATING.md) for more information.
|
32
|
+
|
33
|
+
**Closed issues:**
|
34
|
+
|
35
|
+
- Add Channel.setOptions method [\#291](https://github.com/ably/ably-ruby/issues/291)
|
36
|
+
- Add support for channel params [\#288](https://github.com/ably/ably-ruby/issues/288)
|
37
|
+
- Use ATTACH_RESUME flag for unclean attaches [\#287](https://github.com/ably/ably-ruby/issues/287)
|
38
|
+
- Add ChannelOptions param to Channels.get [\#285](https://github.com/ably/ably-ruby/issues/285)
|
39
|
+
- Update library to adhere to new spec for token renewal (see [the spec definition](https://docs.ably.io/client-lib-development-guide/features/#RSA4b) for more info) [\#268](https://github.com/ably/ably-ruby/issues/268)
|
40
|
+
|
41
|
+
**Merged pull requests:**
|
42
|
+
|
43
|
+
- Add migration guide from 1.1.8 to 1.2.0 [\#348](https://github.com/ably/ably-ruby/pull/348) ([TheSmartnik](https://github.com/TheSmartnik))
|
44
|
+
- RTL21 [\#345](https://github.com/ably/ably-ruby/pull/345) ([lukaszsliwa](https://github.com/lukaszsliwa))
|
45
|
+
- RTL4j [\#341](https://github.com/ably/ably-ruby/pull/341) ([TheSmartnik](https://github.com/TheSmartnik))
|
46
|
+
- RSL1a, RSL1b [\#340](https://github.com/ably/ably-ruby/pull/340) ([lukaszsliwa](https://github.com/lukaszsliwa))
|
47
|
+
- Add support for RSA4b, b1, c, RSA16 \(Authentication\) [\#338](https://github.com/ably/ably-ruby/pull/338) ([lukaszsliwa](https://github.com/lukaszsliwa))
|
48
|
+
- ChannelOptions related tasks [\#336](https://github.com/ably/ably-ruby/pull/336) ([TheSmartnik](https://github.com/TheSmartnik))
|
49
|
+
- Update RSC7 [\#334](https://github.com/ably/ably-ruby/pull/334) ([TheSmartnik](https://github.com/TheSmartnik))
|
50
|
+
|
3
51
|
## [v1.1.8](https://github.com/ably/ably-ruby/tree/v1.1.8)
|
4
52
|
|
5
53
|
[Full Changelog](https://github.com/ably/ably-ruby/compare/v1.1.7...v1.1.8)
|
data/README.md
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
_[Ably](https://ably.com) is the platform that powers synchronized digital experiences in realtime. Whether attending an event in a virtual venue, receiving realtime financial information, or monitoring live car performance data – consumers simply expect realtime digital experiences as standard. Ably provides a suite of APIs to build, extend, and deliver powerful digital experiences in realtime for more than 250 million devices across 80 countries each month. Organizations like Bloomberg, HubSpot, Verizon, and Hopin depend on Ably’s platform to offload the growing complexity of business-critical realtime data synchronization at global scale. For more information, see the [Ably documentation](https://ably.com/documentation)._
|
7
7
|
|
8
|
-
This is a Ruby client library for Ably. The library currently targets the [Ably 1.
|
8
|
+
This is a Ruby client library for Ably. The library currently targets the [Ably 1.2 client library specification](https://ably.com/documentation/client-lib-development-guide/features/). You can see the complete list of features this client library supports in [our client library SDKs feature support matrix](https://ably.com/download/sdk-feature-support-matrix).
|
9
9
|
|
10
10
|
## Supported platforms
|
11
11
|
|
12
|
-
This SDK supports Ruby
|
12
|
+
This SDK supports Ruby 2.7 and 3.x. For eventmachine and Ruby 3.x note please visit [Ruby 3.0 support](#ruby-30-support) section.
|
13
13
|
|
14
14
|
As of v1.1.5 this library requires `libcurl` as a system dependency. On most systems this is already installed but in rare cases where it isn't (for example debian-slim Docker images such as ruby-slim) you will need to install it yourself. On debian you can install it with the command `sudo apt-get install libcurl4`.
|
15
15
|
|
data/UPDATING.md
ADDED
@@ -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
|
+
```
|
data/ably.gemspec
CHANGED
@@ -20,41 +20,29 @@ 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', '~>
|
24
|
-
spec.add_runtime_dependency 'faraday', '~>
|
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'
|
25
26
|
spec.add_runtime_dependency 'typhoeus', '~> 1.4'
|
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
|
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
32
|
spec.add_development_dependency 'rake', '~> 13.0'
|
37
33
|
spec.add_development_dependency 'redcarpet', '~> 3.3'
|
38
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
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'
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
spec.add_development_dependency 'webmock', '~> 3.11'
|
50
|
-
spec.add_development_dependency 'simplecov', '~> 0.21.2'
|
51
|
-
spec.add_development_dependency 'simplecov-lcov', '~> 0.8.0'
|
52
|
-
spec.add_development_dependency 'parallel_tests', '~> 3.7'
|
53
|
-
if !RUBY_VERSION.match(/^2\.[0123]/)
|
54
|
-
spec.add_development_dependency 'pry', '~> 0.14.1'
|
55
|
-
spec.add_development_dependency 'pry-byebug', '~> 3.8.0'
|
56
|
-
end
|
57
|
-
end
|
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'
|
58
46
|
|
59
47
|
if RUBY_VERSION.match(/^3\./)
|
60
48
|
spec.add_development_dependency 'webrick', '~> 1.7.0'
|
data/lib/ably/auth.rb
CHANGED
@@ -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.
|
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.
|
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.
|
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
|
@@ -277,7 +277,7 @@ module Ably
|
|
277
277
|
#
|
278
278
|
# @param [Hash] token_params the token params used in the token request
|
279
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+
|
280
|
-
# @option token_params [Integer] :ttl validity time in seconds for the requested {Ably::Models::TokenDetails}. Limits may apply, see {https://www.ably.
|
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}
|
281
281
|
# @option token_params [Hash] :capability canonicalised representation of the resource paths and associated operations
|
282
282
|
# @option token_params [Time] :timestamp the time of the request
|
283
283
|
# @option token_params [String] :nonce an unquoted, unescaped random string of at least 16 characters
|
@@ -285,7 +285,7 @@ module Ably
|
|
285
285
|
# @param [Hash] auth_options the authentication options for the token request
|
286
286
|
# @option auth_options [String] :key API key comprising the key name and key secret in a single string
|
287
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)
|
288
|
-
# @option auth_options [Boolean] :query_time when true will query the {https://www.ably.
|
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
|
289
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
|
290
290
|
#
|
291
291
|
# @return [Models::TokenRequest]
|
@@ -510,11 +510,11 @@ module Ably
|
|
510
510
|
end
|
511
511
|
|
512
512
|
def authorize_when_necessary
|
513
|
-
if current_token_details && !current_token_details.expired?
|
513
|
+
if current_token_details && !current_token_details.expired?(from: current_time)
|
514
514
|
return current_token_details
|
515
|
-
else
|
516
|
-
authorize
|
517
515
|
end
|
516
|
+
|
517
|
+
authorize
|
518
518
|
end
|
519
519
|
|
520
520
|
# Returns the current device clock time unless the
|
data/lib/ably/logger.rb
CHANGED
@@ -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.
|
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.
|
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.
|
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.
|
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
|
@@ -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.
|
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
|