Class: Ably::Rest::Push::DeviceRegistrations
- Inherits:
-
Object
- Object
- Ably::Rest::Push::DeviceRegistrations
- 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
- #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
Remove device matching where params.
-
#save(device) ⇒ void
Save and register device.
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
#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/submodules/ably-ruby/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/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
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
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 = { 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
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
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
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 |