Class: Ably::Realtime::Push::DeviceRegistrations
- Inherits:
-
Object
- Object
- Ably::Realtime::Push::DeviceRegistrations
- 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
- #admin ⇒ Object readonly private
- #client ⇒ Object readonly private
Instance Method Summary collapse
-
#get(device_id) { ... } ⇒ Ably::Models::DeviceDetails, Ably::Util::SafeDeferrable
Get registered device by device ID.
-
#initialize(admin) ⇒ DeviceRegistrations
constructor
A new instance of DeviceRegistrations.
-
#list(params = {}) { ... } ⇒ Ably::Models::PaginatedResult<Ably::Models::DeviceDetails>, Ably::Util::SafeDeferrable
List registered devices filtered by optional params.
-
#remove(device_id) { ... } ⇒ void, Ably::Util::SafeDeferrable
Remove device.
-
#remove_where(params = {}) { ... } ⇒ void, Ably::Util::SafeDeferrable
Removes all devices registered to receive push notifications from Ably matching the filter params provided.
-
#save(device) { ... } ⇒ void, Ably::Util::SafeDeferrable
Registers or updates a Models::DeviceDetails object with Ably.
Constructor Details
#initialize(admin) ⇒ DeviceRegistrations
Returns a new instance of 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
#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.
12 13 14 |
# File 'lib/ably/realtime/push/device_registrations.rb', line 12 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.
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
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
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
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
Removes all devices registered to receive push notifications from Ably matching the filter params provided.
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
Registers or updates a Models::DeviceDetails object with Ably. Returns the new, or updated Models::DeviceDetails object.
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 |