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

Inherits:
Object
  • Object
show all
Includes:
Modules::Conversions
Defined in:
lib/submodules/ably-ruby/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/submodules/ably-ruby/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/submodules/ably-ruby/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/submodules/ably-ruby/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)


24
25
26
27
28
29
# File 'lib/submodules/ably-ruby/lib/ably/rest/push/device_registrations.rb', line 24

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)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/submodules/ably-ruby/lib/ably/rest/push/device_registrations.rb', line 40

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)


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

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.

Remove device matching where params

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



91
92
93
94
95
96
97
98
99
100
# File 'lib/submodules/ably-ruby/lib/ably/rest/push/device_registrations.rb', line 91

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.

Save and register device

Parameters:

Raises:

  • (ArgumentError)


63
64
65
66
67
68
# File 'lib/submodules/ably-ruby/lib/ably/rest/push/device_registrations.rb', line 63

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