Class: Ably::Rest::Push::ChannelSubscriptions

Inherits:
Object
  • Object
show all
Includes:
Modules::Conversions
Defined in:
lib/submodules/ably-ruby/lib/ably/rest/push/channel_subscriptions.rb

Overview

Manage push notification channel subscriptions for devices or client identifiers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(admin) ⇒ ChannelSubscriptions

Returns a new instance of ChannelSubscriptions.



13
14
15
16
# File 'lib/submodules/ably-ruby/lib/ably/rest/push/channel_subscriptions.rb', line 13

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.



11
12
13
# File 'lib/submodules/ably-ruby/lib/ably/rest/push/channel_subscriptions.rb', line 11

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.



8
9
10
# File 'lib/submodules/ably-ruby/lib/ably/rest/push/channel_subscriptions.rb', line 8

def client
  @client
end

Instance Method Details

#list(params) ⇒ Ably::Models::PaginatedResult<Ably::Models::PushChannelSubscription>

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

Returns:

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/submodules/ably-ruby/lib/ably/rest/push/channel_subscriptions.rb', line 28

def list(params)
  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

  params = params.clone

  paginated_options = {
    coerce_into: 'Ably::Models::PushChannelSubscription',
    async_blocking_operations: params.delete(:async_blocking_operations),
  }

  response = client.get('/push/channelSubscriptions', IdiomaticRubyWrapper(params).as_json)

  Ably::Models::PaginatedResult.new(response, '', client, paginated_options)
end

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

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

Returns:

Raises:

  • (ArgumentError)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/submodules/ably-ruby/lib/ably/rest/push/channel_subscriptions.rb', line 54

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

  params = params.clone

  paginated_options = {
    coerce_into: 'String',
    async_blocking_operations: params.delete(:async_blocking_operations),
  }

  response = client.get('/push/channels', IdiomaticRubyWrapper(params).as_json)

  Ably::Models::PaginatedResult.new(response, '', client, paginated_options)
end

#remove(push_channel_subscription) ⇒ void

This method returns an undefined value.

Remove a push channel subscription

Parameters:

Raises:

  • (ArgumentError)


89
90
91
92
93
94
95
96
97
# File 'lib/submodules/ably-ruby/lib/ably/rest/push/channel_subscriptions.rb', line 89

def remove(push_channel_subscription)
  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

  client.delete("/push/channelSubscriptions", push_channel_subscription_object.as_json)
end

#remove_where(params) ⇒ void

This method returns an undefined value.

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.

Raises:

  • (ArgumentError)


108
109
110
111
112
113
114
115
116
117
118
# File 'lib/submodules/ably-ruby/lib/ably/rest/push/channel_subscriptions.rb', line 108

def remove_where(params)
  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

  params = params.clone

  client.delete("/push/channelSubscriptions", IdiomaticRubyWrapper(params).as_json)
end

#save(push_channel_subscription) ⇒ void

This method returns an undefined value.

Save push channel subscription for a device or client ID

Parameters:

Raises:

  • (ArgumentError)


76
77
78
79
80
81
# File 'lib/submodules/ably-ruby/lib/ably/rest/push/channel_subscriptions.rb', line 76

def save(push_channel_subscription)
  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?

  client.post("/push/channelSubscriptions", push_channel_subscription_object.as_json)
end