Class: Ably::Realtime::Push::DeviceRegistrations

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

Overview

Manage device registrations for push notifications

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(admin) ⇒ DeviceRegistrations


14
15
16
17
# File 'lib/ably/realtime/push/device_registrations.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/device_registrations.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/device_registrations.rb', line 9

def client
  @client
end

Instance Method Details

#get(device_id) { ... } ⇒ Ably::Models::DeviceDetails, Ably::Util::SafeDeferrable

Get registered device by device ID

Yields:

  • Block is invoked when request succeeds

Raises:

  • (ArgumentError)

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

def get(device_id, &callback)
  device_id = device_id.id if device_id.kind_of?(Ably::Models::DeviceDetails)
  raise ArgumentError, "device_id must be a string or DeviceDetails object" unless device_id.kind_of?(String)

  async_wrap(callback) do
    rest_device_registrations.get(device_id)
  end
end

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

List registered devices filtered by optional params

Options Hash (params):

  • :client_id (String)

    filter by devices registered to a client identifier. Cannot be used with device_id param

  • :device_id (String)

    filter by unique device ID. Cannot be used with client_id param

  • :limit (Integer)

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

Yields:

  • Block is invoked when request succeeds

Raises:

  • (ArgumentError)

38
39
40
41
42
43
44
45
46
# File 'lib/ably/realtime/push/device_registrations.rb', line 38

def list(params = {}, &callback)
  params = {} if params.nil?
  raise ArgumentError, "params must be a Hash" unless params.kind_of?(Hash)
  raise ArgumentError, "device_id filter cannot be specified alongside a client_id filter. Use one or the other" if params[:client_id] && params[:device_id]

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

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

Remove device

Yields:

  • Block is invoked when request succeeds

Raises:

  • (ArgumentError)

67
68
69
70
71
72
73
74
# File 'lib/ably/realtime/push/device_registrations.rb', line 67

def remove(device_id, &callback)
  device_id = device_id.id if device_id.kind_of?(Ably::Models::DeviceDetails)
  raise ArgumentError, "device_id must be a string or DeviceDetails object" unless device_id.kind_of?(String)

  async_wrap(callback) do
    rest_device_registrations.remove(device_id)
  end
end

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

Remove device matching where params

Options Hash (params):

  • :client_id (String)

    remove devices registered to a client identifier. Cannot be used with device_id param

  • :device_id (String)

    remove device with this unique device ID. Cannot be used with client_id param

Yields:

  • Block is invoked when request succeeds


81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ably/realtime/push/device_registrations.rb', line 81

def remove_where(params = {}, &callback)
  filter = if params.kind_of?(Ably::Models::DeviceDetails)
    { 'deviceId' => params.id }
  else
    raise ArgumentError, "params must be a Hash" unless params.kind_of?(Hash)
    raise ArgumentError, "device_id filter cannot be specified alongside a client_id filter. Use one or the other" if params[:client_id] && params[:device_id]
    IdiomaticRubyWrapper(params).as_json
  end

  async_wrap(callback) do
    rest_device_registrations.remove_where(filter)
  end
end

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

Save and register device

Yields:

  • Block is invoked when request succeeds

Raises:

  • (ArgumentError)

53
54
55
56
57
58
59
60
# File 'lib/ably/realtime/push/device_registrations.rb', line 53

def save(device, &callback)
  device_details = DeviceDetails(device)
  raise ArgumentError, "Device ID is required yet is empty" if device_details.id.nil? || device_details == ''

  async_wrap(callback) do
    rest_device_registrations.save(device_details)
  end
end