Class: Pushkin::NotificationFabric
- Inherits:
-
Object
- Object
- Pushkin::NotificationFabric
- Defined in:
- app/fabrics/pushkin/notification_fabric.rb
Instance Method Summary collapse
- #click_action_attrs(click_action = nil) ⇒ Object
- #icon_attrs(icon = nil) ⇒ Object
- #is_data_message_attrs(is_data_message = false) ⇒ Object
-
#simple_notification_to_users(users: [], title: [], body: [], is_data_message: false, click_action: nil, icon: nil, data: {}, notification_type: nil) ⇒ Object
Создает уведомление со статическими данными.
Instance Method Details
#click_action_attrs(click_action = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/fabrics/pushkin/notification_fabric.rb', line 50 def click_action_attrs(click_action = nil) if click_action.is_a? Hash return { android_click_action: click_action[:android], ios_click_action: click_action[:ios], web_click_action: click_action[:web] } else return { android_click_action: click_action, ios_click_action: click_action, web_click_action: click_action } end end |
#icon_attrs(icon = nil) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/fabrics/pushkin/notification_fabric.rb', line 66 def icon_attrs(icon = nil) if icon.is_a? Hash return { android_icon: icon[:android], ios_icon: icon[:ios], web_icon: icon[:web] } else return { android_icon: icon, ios_icon: icon, web_icon: icon } end end |
#is_data_message_attrs(is_data_message = false) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/fabrics/pushkin/notification_fabric.rb', line 26 def ( = false) if .is_a? Hash = [:android] = [:ios] = [:web] = false if .nil? = false if .nil? = false if .nil? return { is_android_data_message: , is_ios_data_message: , is_web_data_message: } else return { is_android_data_message: , is_ios_data_message: , is_web_data_message: } end end |
#simple_notification_to_users(users: [], title: [], body: [], is_data_message: false, click_action: nil, icon: nil, data: {}, notification_type: nil) ⇒ Object
Создает уведомление со статическими данными. Актуальный список устройств, на которые нужно отправить уведомления, будут получены из пользователей в момент отправки.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/fabrics/pushkin/notification_fabric.rb', line 8 def simple_notification_to_users(users: [], title: [], body: [], is_data_message: false, click_action: nil, icon: nil, data: {}, notification_type: nil) return nil if users.blank? payload_attrs = { title: title, body: body, data: data } payload_attrs = payload_attrs.merge(self.()) payload_attrs = payload_attrs.merge(self.click_action_attrs(click_action)) payload_attrs = payload_attrs.merge(self.icon_attrs(icon)) payload = Payload.create(payload_attrs) tokens_provider = TokensProvider.create(users: users) Notification.create(notification_type: notification_type, payload: payload, tokens_provider: tokens_provider) end |