-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #365 from ably/issue-362
Add RSL8, RSL8a lifecycle channel status
- Loading branch information
Showing
10 changed files
with
389 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module Ably::Models | ||
# Convert token details argument to a {ChannelDetails} object | ||
# | ||
# @param attributes (see #initialize) | ||
# | ||
# @return [ChannelDetails] | ||
def self.ChannelDetails(attributes) | ||
case attributes | ||
when ChannelDetails | ||
return attributes | ||
else | ||
ChannelDetails.new(attributes) | ||
end | ||
end | ||
|
||
# ChannelDetails is a type that represents information for a channel including channelId, name, status and occupancy (CHD1) | ||
# | ||
class ChannelDetails | ||
extend Ably::Modules::Enum | ||
extend Forwardable | ||
include Ably::Modules::ModelCommon | ||
|
||
# The attributes of ChannelDetails (CHD2) | ||
# | ||
attr_reader :attributes | ||
|
||
alias_method :to_h, :attributes | ||
|
||
# Initialize a new ChannelDetails | ||
# | ||
def initialize(attrs) | ||
@attributes = IdiomaticRubyWrapper(attrs.clone) | ||
end | ||
|
||
# The identifier of the channel (CHD2a) | ||
# | ||
# @return [String] | ||
# | ||
def channel_id | ||
attributes[:channel_id] | ||
end | ||
|
||
# The identifier of the channel (CHD2a) | ||
# | ||
# @return [String] | ||
# | ||
def name | ||
attributes[:name] | ||
end | ||
|
||
# The status of the channel (CHD2b) | ||
# | ||
# @return [Ably::Models::ChannelStatus, nil] | ||
# | ||
def status | ||
Ably::Models::ChannelStatus(attributes[:status]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
module Ably::Models | ||
# Convert token details argument to a {ChannelMetrics} object | ||
# | ||
# @param attributes (see #initialize) | ||
# | ||
# @return [ChannelMetrics] | ||
def self.ChannelMetrics(attributes) | ||
case attributes | ||
when ChannelMetrics | ||
return attributes | ||
else | ||
ChannelMetrics.new(attributes) | ||
end | ||
end | ||
|
||
# ChannelMetrics is a type that contains the count of publishers and subscribers, connections and presenceConnections, | ||
# presenceMembers and presenceSubscribers (CHM1) | ||
# | ||
class ChannelMetrics | ||
extend Ably::Modules::Enum | ||
extend Forwardable | ||
include Ably::Modules::ModelCommon | ||
|
||
# The attributes of ChannelMetrics (CHM2) | ||
# | ||
attr_reader :attributes | ||
|
||
alias_method :to_h, :attributes | ||
|
||
# Initialize a new ChannelMetrics | ||
# | ||
def initialize(attrs) | ||
@attributes = IdiomaticRubyWrapper(attrs.clone) | ||
end | ||
|
||
# The total number of connections to the channel (CHM2a) | ||
# | ||
# @return [Integer] | ||
# | ||
def connections | ||
attributes[:connections] | ||
end | ||
|
||
# The total number of presence connections to the channel (CHM2b) | ||
# | ||
# @return [Integer] | ||
# | ||
def presence_connections | ||
attributes[:presence_connections] | ||
end | ||
|
||
# The total number of presence members for the channel (CHM2c) | ||
# | ||
# @return [Integer] | ||
# | ||
def presence_members | ||
attributes[:presence_members] | ||
end | ||
|
||
# The total number of presence subscribers for the channel (CHM2d) | ||
# | ||
# @return [Integer] | ||
# | ||
def presence_subscribers | ||
attributes[:presence_subscribers] | ||
end | ||
|
||
# The total number of publishers to the channel (CHM2e) | ||
# | ||
# @return [Integer] | ||
# | ||
def publishers | ||
attributes[:publishers] | ||
end | ||
|
||
# The total number of subscribers to the channel (CHM2f) | ||
# | ||
# @return [Integer] | ||
# | ||
def subscribers | ||
attributes[:subscribers] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Ably::Models | ||
# Convert token details argument to a {ChannelOccupancy} object | ||
# | ||
# @param attributes (see #initialize) | ||
# | ||
# @return [ChannelOccupancy] | ||
def self.ChannelOccupancy(attributes) | ||
case attributes | ||
when ChannelOccupancy | ||
return attributes | ||
else | ||
ChannelOccupancy.new(attributes) | ||
end | ||
end | ||
|
||
# Type that contain channel metrics (CHO1) | ||
# | ||
class ChannelOccupancy | ||
extend Ably::Modules::Enum | ||
extend Forwardable | ||
include Ably::Modules::ModelCommon | ||
|
||
# The attributes of ChannelOccupancy (CH02) | ||
# | ||
attr_reader :attributes | ||
|
||
alias_method :to_h, :attributes | ||
|
||
# Initialize a new ChannelOccupancy | ||
# | ||
def initialize(attrs) | ||
@attributes = IdiomaticRubyWrapper(attrs.clone) | ||
end | ||
|
||
# Metrics object (CHO2a) | ||
# | ||
# @return [Ably::Models::ChannelMetrics, nil] | ||
# | ||
def metrics | ||
Ably::Models::ChannelMetrics(attributes[:metrics]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module Ably::Models | ||
# Convert token details argument to a {ChannelStatus} object | ||
# | ||
# @param attributes (see #initialize) | ||
# | ||
# @return [ChannelStatus] | ||
def self.ChannelStatus(attributes) | ||
case attributes | ||
when ChannelStatus | ||
return attributes | ||
else | ||
ChannelStatus.new(attributes) | ||
end | ||
end | ||
|
||
# ChannelStatus is a type that contains status and occupancy for a channel (CHS1) | ||
# | ||
class ChannelStatus | ||
extend Ably::Modules::Enum | ||
extend Forwardable | ||
include Ably::Modules::ModelCommon | ||
|
||
# The attributes of ChannelStatus (CHS2) | ||
# | ||
attr_reader :attributes | ||
|
||
alias_method :to_h, :attributes | ||
|
||
# Initialize a new ChannelStatus | ||
# | ||
def initialize(attrs) | ||
@attributes = IdiomaticRubyWrapper(attrs.clone) | ||
end | ||
|
||
# Represents if the channel is active (CHS2a) | ||
# | ||
# @return [Boolean] | ||
# | ||
def is_active | ||
attributes[:isActive] | ||
end | ||
alias_method :active?, :is_active | ||
alias_method :is_active?, :is_active | ||
|
||
# Occupancy ChannelOccupancy – occupancy is an object containing the metrics for the channel (CHS2b) | ||
# | ||
# @return [Ably::Models::ChannelOccupancy, nil] | ||
# | ||
def occupancy | ||
Ably::Models::ChannelOccupancy(attributes[:occupancy]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'spec_helper' | ||
require 'shared/model_behaviour' | ||
|
||
describe Ably::Models::ChannelDetails do | ||
subject { Ably::Models::ChannelDetails(channel_id: 'channel-id-123-xyz', name: 'name', status: { isActive: 'true', occupancy: { metrics: { connections: 1, presence_connections: 2, presence_members: 2, presence_subscribers: 5, publishers: 7, subscribers: 9 } } }) } | ||
|
||
describe '#channel_id' do | ||
it 'should return channel id' do | ||
expect(subject.channel_id).to eq('channel-id-123-xyz') | ||
end | ||
end | ||
|
||
describe '#name' do | ||
it 'should return name' do | ||
expect(subject.name).to eq('name') | ||
end | ||
end | ||
|
||
describe '#status' do | ||
it 'should return status' do | ||
expect(subject.status).to be_a(Ably::Models::ChannelStatus) | ||
expect(subject.status.occupancy.metrics.connections).to eq(1) | ||
expect(subject.status.occupancy.metrics.presence_connections).to eq(2) | ||
expect(subject.status.occupancy.metrics.presence_members).to eq(2) | ||
expect(subject.status.occupancy.metrics.presence_subscribers).to eq(5) | ||
expect(subject.status.occupancy.metrics.publishers).to eq(7) | ||
expect(subject.status.occupancy.metrics.subscribers).to eq(9) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'spec_helper' | ||
require 'shared/model_behaviour' | ||
|
||
describe Ably::Models::ChannelMetrics do | ||
subject { Ably::Models::ChannelMetrics(connections: 1, presence_connections: 2, presence_members: 2, presence_subscribers: 5, publishers: 7, subscribers: 9) } | ||
|
||
describe '#connections' do | ||
it 'should return integer' do | ||
expect(subject.connections).to eq(1) | ||
end | ||
end | ||
|
||
describe '#presence_connections' do | ||
it 'should return integer' do | ||
expect(subject.presence_connections).to eq(2) | ||
end | ||
end | ||
|
||
describe '#presence_members' do | ||
it 'should return integer' do | ||
expect(subject.presence_members).to eq(2) | ||
end | ||
end | ||
|
||
describe '#presence_subscribers' do | ||
it 'should return integer' do | ||
expect(subject.presence_subscribers).to eq(5) | ||
end | ||
end | ||
|
||
describe '#publishers' do | ||
it 'should return integer' do | ||
expect(subject.publishers).to eq(7) | ||
end | ||
end | ||
|
||
describe '#subscribers' do | ||
it 'should return integer' do | ||
expect(subject.subscribers).to eq(9) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'spec_helper' | ||
require 'shared/model_behaviour' | ||
|
||
describe Ably::Models::ChannelOccupancy do | ||
subject { Ably::Models::ChannelOccupancy({ metrics: { connections: 1, presence_connections: 2, presence_members: 2, presence_subscribers: 5, publishers: 7, subscribers: 9 } }) } | ||
|
||
describe '#metrics' do | ||
it 'should return attributes' do | ||
expect(subject.metrics.connections).to eq(1) | ||
expect(subject.metrics.presence_connections).to eq(2) | ||
expect(subject.metrics.presence_members).to eq(2) | ||
expect(subject.metrics.presence_subscribers).to eq(5) | ||
expect(subject.metrics.publishers).to eq(7) | ||
expect(subject.metrics.subscribers).to eq(9) | ||
end | ||
end | ||
end |
Oops, something went wrong.