Class: Ably::Rest::Push::DeviceRegistrations
- Inherits:
-
Object
- Object
- Ably::Rest::Push::DeviceRegistrations
- Includes:
- Modules::Conversions
- Defined in:
- lib/ably/rest/push/device_registrations.rb
Overview
Manage device registrations for push notifications
Instance Attribute Summary collapse
- #admin ⇒ Object readonly private
- #client ⇒ Object readonly private
Instance Method Summary collapse
-
#get(device_id) ⇒ Ably::Models::DeviceDetails
Get registered device by device ID.
-
#initialize(admin) ⇒ DeviceRegistrations
constructor
A new instance of DeviceRegistrations.
-
#list(params = {}) ⇒ Ably::Models::PaginatedResult<Ably::Models::DeviceDetails>
List registered devices filtered by optional params.
-
#remove(device_id) ⇒ void
Remove device.
-
#remove_where(params = {}) ⇒ void
Removes all devices registered to receive push notifications from Ably matching the filter params provided.
-
#save(device) ⇒ void
Registers or updates a Models::DeviceDetails object with Ably.
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
#admin ⇒ Object (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 |
#client ⇒ Object (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
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
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 = { 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, ) end |
#remove(device_id) ⇒ void
This method returns an undefined value.
Remove device
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.
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.
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 |