Class: Ably::Realtime::Push::ChannelSubscriptions

Inherits:
Object
  • Object
show all
Includes:
Modules::AsyncWrapper, Modules::Conversions
Defined in:
lib/ably/realtime/push/channel_subscriptions.rb

Overview

Manage push notification channel subscriptions for devices or clients

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(admin) ⇒ ChannelSubscriptions

Returns a new instance of ChannelSubscriptions.



14
15
16
17
# File 'lib/ably/realtime/push/channel_subscriptions.rb', line 14

def initialize(admin)
  @admin = admin
  @client = admin.client
end

Instance Attribute Details

#adminObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/ably/realtime/push/channel_subscriptions.rb', line 12

def admin
  @admin
end

#clientObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/ably/realtime/push/channel_subscriptions.rb', line 9

def client
  @client
end

Instance Method Details

#list(params) { ... } ⇒ Ably::Models::PaginatedResult<Ably::Models::PushChannelSubscription>, Ably::Util::SafeDeferrable

List channel subscriptions filtered by optional params

Parameters:

  • params (Hash)

    the filter options for the list channel subscription request. At least one of channel, client_id or device_id is required

Options Hash (params):

  • :channel (String)

    filter by realtime pub/sub channel name

  • :client_id (String)

    filter by devices registered to a client identifier. If provided with device_id param, a concat operation is used so that any device with this client_id or provided device_id is returned.

  • :device_id (String)

    filter by unique device ID. If provided with client_id param, a concat operation is used so that any device with this device_id or provided client_id is returned.

  • :limit (Integer)

    maximum number of subscriptions to retrieve up to 1,000, defaults to 100

Yields:

  • Block is invoked when request succeeds

Returns:

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ably/realtime/push/channel_subscriptions.rb', line 24

def list(params, &callback)
  raise ArgumentError, "params must be a Hash" unless params.kind_of?(Hash)

  if (IdiomaticRubyWrapper(params).keys & [:channel, :client_id, :device_id]).length == 0
    raise ArgumentError, "at least one channel, client_id or device_id filter param must be provided"
  end

  async_wrap(callback) do
    rest_channel_subscriptions.list(params.merge(async_blocking_operations: true))
  end
end

#list_channels(params = {}) { ... } ⇒ Ably::Models::PaginatedResult<String>, Ably::Util::SafeDeferrable

List channels with at least one subscribed device

Parameters:

  • params (Hash) (defaults to: {})

    the options for the list channels request

Options Hash (params):

  • :limit (Integer)

    maximum number of channels to retrieve up to 1,000, defaults to 100

Yields:

  • Block is invoked when request succeeds

Returns:

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
# File 'lib/ably/realtime/push/channel_subscriptions.rb', line 41

def list_channels(params = {}, &callback)
  params = {} if params.nil?
  raise ArgumentError, "params must be a Hash" unless params.kind_of?(Hash)

  async_wrap(callback) do
    rest_channel_subscriptions.list_channels(params.merge(async_blocking_operations: true))
  end
end

#remove(push_channel_subscription) { ... } ⇒ void, Ably::Util::SafeDeferrable

Remove a push channel subscription

Parameters:

Yields:

  • Block is invoked when request succeeds

Returns:

Raises:

  • (ArgumentError)


69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ably/realtime/push/channel_subscriptions.rb', line 69

def remove(push_channel_subscription, &callback)
  push_channel_subscription_object = PushChannelSubscription(push_channel_subscription)
  raise ArgumentError, "Channel is required yet is empty" if push_channel_subscription_object.channel.to_s.empty?
  if push_channel_subscription_object.client_id.to_s.empty? && push_channel_subscription_object.device_id.to_s.empty?
    raise ArgumentError, "Either client_id or device_id must be present"
  end

  async_wrap(callback) do
    rest_channel_subscriptions.remove(push_channel_subscription)
  end
end

#remove_where(params) { ... } ⇒ void, Ably::Util::SafeDeferrable

Remove all matching push channel subscriptions

Parameters:

  • params (Hash)

    the filter options for the list channel subscription request. At least one of channel, client_id or device_id is required

Options Hash (params):

  • :channel (String)

    filter by realtime pub/sub channel name

  • :client_id (String)

    filter by devices registered to a client identifier. If provided with device_id param, a concat operation is used so that any device with this client_id or provided device_id is returned.

  • :device_id (String)

    filter by unique device ID. If provided with client_id param, a concat operation is used so that any device with this device_id or provided client_id is returned.

Yields:

  • Block is invoked when request succeeds

Returns:

Raises:

  • (ArgumentError)


86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ably/realtime/push/channel_subscriptions.rb', line 86

def remove_where(params, &callback)
  raise ArgumentError, "params must be a Hash" unless params.kind_of?(Hash)

  if (IdiomaticRubyWrapper(params).keys & [:channel, :client_id, :device_id]).length == 0
    raise ArgumentError, "at least one channel, client_id or device_id filter param must be provided"
  end

  async_wrap(callback) do
    rest_channel_subscriptions.remove_where(params)
  end
end

#save(push_channel_subscription) { ... } ⇒ void, Ably::Util::SafeDeferrable

Save push channel subscription for a device or client ID

Parameters:

Yields:

  • Block is invoked when request succeeds

Returns:

Raises:

  • (ArgumentError)


55
56
57
58
59
60
61
62
# File 'lib/ably/realtime/push/channel_subscriptions.rb', line 55

def save(push_channel_subscription, &callback)
  push_channel_subscription_object = PushChannelSubscription(push_channel_subscription)
  raise ArgumentError, "Channel is required yet is empty" if push_channel_subscription_object.channel.to_s.empty?

  async_wrap(callback) do
    rest_channel_subscriptions.save(push_channel_subscription)
  end
end