Class: Ably::Rest::Push::DeviceRegistrations

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

Overview

Manage device registrations for push notifications

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(admin) ⇒ DeviceRegistrations

Returns a new instance of DeviceRegistrations.



13
14
15
16
# File 'lib/ably/rest/push/device_registrations.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/ably/rest/push/device_registrations.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/ably/rest/push/device_registrations.rb', line 8

def client
  @client
end

Instance Method Details

#get(device_id) ⇒ Ably::Models::DeviceDetails

Get registered device by device ID

Parameters:

Returns:

Raises:

  • (ArgumentError)


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

def get(device_id)
  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)

  DeviceDetails(client.get("/push/deviceRegistrations/#{device_id}").body)
end

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

List registered devices filtered by optional params

Parameters:

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

    the filter options for the list registered device request

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

Returns:

Raises:

  • (ArgumentError)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ably/rest/push/device_registrations.rb', line 44

def list(params = {})
  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]

  params = params.clone

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

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

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

#remove(device_id) ⇒ void

This method returns an undefined value.

Remove device

Parameters:

Raises:

  • (ArgumentError)


85
86
87
88
89
90
# File 'lib/ably/rest/push/device_registrations.rb', line 85

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

  client.delete("/push/deviceRegistrations/#{device_id}", {})
end

#remove_where(params = {}) ⇒ void

This method returns an undefined value.

Removes all devices registered to receive push notifications from Ably matching the filter params provided.

Parameters:

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

    the filter params for the remove request

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



102
103
104
105
106
107
108
109
110
111
# File 'lib/ably/rest/push/device_registrations.rb', line 102

def remove_where(params = {})
  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
  client.delete("/push/deviceRegistrations", filter)
end

#save(device) ⇒ void

This method returns an undefined value.

Registers or updates a Models::DeviceDetails object with Ably. Returns the new, or updated Models::DeviceDetails object.

Parameters:

Raises:

  • (ArgumentError)


70
71
72
73
74
75
# File 'lib/ably/rest/push/device_registrations.rb', line 70

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

  client.put("/push/deviceRegistrations/#{device_details.id}", device_details.as_json)
end