Class: Hsquare::Notification
- Inherits:
-
Object
- Object
- Hsquare::Notification
- Defined in:
- lib/hsquare/notification.rb
Overview
Public: Notification entries sent to Kakao push.
Instance Attribute Summary collapse
-
#app_ids ⇒ Object
Public: IDs of Hsquare applications to deliver.
-
#badge ⇒ Object
Public: Badge count to set.
-
#collapse ⇒ Object
Public: Collapse key for GCM.
-
#extra ⇒ Object
Public: Extra payload.
-
#idle_delay ⇒ Object
Public: Whether GCM message delivery is delayed while device is idle.
-
#message ⇒ Object
Public: Message (alert in APNS) displayed to recipients.
-
#push_alert ⇒ Object
Public: Whether notification is delivered through notification center.
-
#recipient_ids ⇒ Object
Public: Array of recipient IDs.
-
#sound ⇒ Object
Public: Sound to play.
Instance Method Summary collapse
-
#deliver ⇒ Object
Public: Delivers notification to recipients’ devices.
-
#initialize(attributes = {}) ⇒ Notification
constructor
Public: Initializes new notification object.
-
#recipient_id=(recipient_id) ⇒ Object
Public: Helper method to set recipient_ids with single ID.
Constructor Details
#initialize(attributes = {}) ⇒ Notification
Public: Initializes new notification object.
attributes - Attributes of the notification.
:recipient_id - ID of recipient (optinoal).
:recipient_ids - List of IDs of recipients (optinoal).
:message - Message displayed to recipients (optional).
:badge - Badge count (optinoal).
:sound - Sound to play (optinoal).
:push_alert - Whether notification is delivered through
notification center (default: true).
:collapse - Collapse key for GCM (optional).
:idle_delay - Whether GCM message delivery is delayed
while device is idle (default: false).
:extra - Extra payload (optinoal).
:app_ids - IDs of Hsquare applications to deliver.
Returns newly initialized notification object.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/hsquare/notification.rb', line 48 def initialize(attributes = {}) @recipient_ids = (attributes[:recipient_id] && [attributes[:recipient_id]]) || attributes[:recipient_ids] @message = attributes[:message] @badge = attributes[:badge] @sound = attributes[:sound] @push_alert = attributes.has_key?(:push_alert) ? attributes[:push_alert] : true @collapse = attributes[:collapse] @idle_delay = attributes.has_key?(:idle_delay) ? attributes[:idle_delay] : false @extra = attributes[:extra] @app_ids = attributes[:app_ids] end |
Instance Attribute Details
#app_ids ⇒ Object
Public: IDs of Hsquare applications to deliver.
29 30 31 |
# File 'lib/hsquare/notification.rb', line 29 def app_ids @app_ids end |
#badge ⇒ Object
Public: Badge count to set.
11 12 13 |
# File 'lib/hsquare/notification.rb', line 11 def badge @badge end |
#collapse ⇒ Object
Public: Collapse key for GCM.
20 21 22 |
# File 'lib/hsquare/notification.rb', line 20 def collapse @collapse end |
#extra ⇒ Object
Public: Extra payload.
26 27 28 |
# File 'lib/hsquare/notification.rb', line 26 def extra @extra end |
#idle_delay ⇒ Object
Public: Whether GCM message delivery is delayed while device is idle.
23 24 25 |
# File 'lib/hsquare/notification.rb', line 23 def idle_delay @idle_delay end |
#message ⇒ Object
Public: Message (alert in APNS) displayed to recipients.
8 9 10 |
# File 'lib/hsquare/notification.rb', line 8 def @message end |
#push_alert ⇒ Object
Public: Whether notification is delivered through notification center.
17 18 19 |
# File 'lib/hsquare/notification.rb', line 17 def push_alert @push_alert end |
#recipient_ids ⇒ Object
Public: Array of recipient IDs.
5 6 7 |
# File 'lib/hsquare/notification.rb', line 5 def recipient_ids @recipient_ids end |
#sound ⇒ Object
Public: Sound to play.
14 15 16 |
# File 'lib/hsquare/notification.rb', line 14 def sound @sound end |
Instance Method Details
#deliver ⇒ Object
Public: Delivers notification to recipients’ devices.
Returns nothing.
72 73 74 75 76 77 78 |
# File 'lib/hsquare/notification.rb', line 72 def deliver Hsquare.config.applications.each do |application| if !app_ids || app_ids.include?(application.label) application.admin_client.post('/v1/push/send', body: payload) end end end |
#recipient_id=(recipient_id) ⇒ Object
Public: Helper method to set recipient_ids with single ID.
recipient_id - ID of single recipient.
Returns 1-length array of recipient_id.
65 66 67 |
# File 'lib/hsquare/notification.rb', line 65 def recipient_id=(recipient_id) @recipient_ids = [recipient_id] end |