Class: Wor::Push::Notifications::Aws::PushNotifications
- Inherits:
-
Object
- Object
- Wor::Push::Notifications::Aws::PushNotifications
- Defined in:
- lib/wor/push/notifications/aws/push_notifications.rb
Class Method Summary collapse
- .add_token(user, device_token, device_type) ⇒ Object
- .delete_token(user, device_token) ⇒ Object
- .send_message(user, message_content) ⇒ Object
Class Method Details
.add_token(user, device_token, device_type) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/wor/push/notifications/aws/push_notifications.rb', line 12 def add_token(user, device_token, device_type) PushNotificationsValidator.new(user, device_token, device_type).validate_add_token device_token = device_token.to_s.gsub(/\s+/, '') return true if user.device_tokens.key?(device_token) endpoint = sns.create_platform_endpoint( platform_application_arn: app_arn(device_type), token: device_token ) user.device_tokens[device_token] = { 'device_type' => device_type, 'endpoint_arn' => endpoint[:endpoint_arn] } user.save end |
.delete_token(user, device_token) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/wor/push/notifications/aws/push_notifications.rb', line 24 def delete_token(user, device_token) PushNotificationsValidator.new(user).validate_delete_token device_token = device_token.to_s.gsub(/\s+/, '') return true unless user.device_tokens.key?(device_token) sns.delete_endpoint(endpoint_arn: user.device_tokens[device_token]['endpoint_arn']) user.device_tokens.delete(device_token) user.save end |
.send_message(user, message_content) ⇒ Object
33 34 35 36 37 |
# File 'lib/wor/push/notifications/aws/push_notifications.rb', line 33 def (user, ) PushNotificationsValidator.new(user).() = badge_check() send_notifications_to_user(user, ) end |