Class: HeyYouFcmPush::MessageObject
- Inherits:
-
Object
- Object
- HeyYouFcmPush::MessageObject
- Defined in:
- lib/hey_you_fcm_push/message_object.rb,
lib/hey_you_fcm_push/message_object/apns_config.rb,
lib/hey_you_fcm_push/message_object/fcm_options.rb,
lib/hey_you_fcm_push/message_object/notification.rb,
lib/hey_you_fcm_push/message_object/android_config.rb,
lib/hey_you_fcm_push/message_object/web_push_config.rb
Defined Under Namespace
Classes: AndroidConfig, ApnsConfig, FcmOptions, Notification, PushReceiverError, WebPushConfig
Instance Attribute Summary collapse
-
#android_config ⇒ Object
readonly
Returns the value of attribute android_config.
-
#apns_config ⇒ Object
readonly
Returns the value of attribute apns_config.
-
#fcm_options ⇒ Object
readonly
Returns the value of attribute fcm_options.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#notification ⇒ Object
readonly
Returns the value of attribute notification.
-
#push_data ⇒ Object
readonly
Returns the value of attribute push_data.
-
#receiver_hash ⇒ Object
readonly
Returns the value of attribute receiver_hash.
-
#web_push_config ⇒ Object
readonly
Returns the value of attribute web_push_config.
Instance Method Summary collapse
-
#initialize(name: nil, token: nil, topic: nil, condition: nil, **options) ⇒ MessageObject
constructor
A new instance of MessageObject.
- #to_h ⇒ Object
Constructor Details
#initialize(name: nil, token: nil, topic: nil, condition: nil, **options) ⇒ MessageObject
Returns a new instance of MessageObject.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/hey_you_fcm_push/message_object.rb', line 24 def initialize(name: nil, token: nil, topic: nil, condition: nil, **) @receiver_hash = { token: token } if token @receiver_hash = { topic: topic } if topic @receiver_hash = { condition: condition } if condition raise PushReceiverError, "You should pass `token` or `topic` or `condition`" unless receiver_hash @name = name @notification = Notification.new(**[:notification].transform_keys(&:to_sym)) if [:notification] @android_config = AndroidConfig.new([:android].transform_keys(&:to_sym)) if [:android_config] @web_push_config = WebPushConfig.new([:webpush].transform_keys(&:to_sym)) if [:web_push_config] @apns_config = ApnsConfig.new([:apns].transform_keys(&:to_sym)) if [:apns_config] @fcm_options = FcmOptions.new(**[:fcm_options].transform_keys(&:to_sym)) if [:fcm_options] @push_data = { data: [:data].to_json } end |
Instance Attribute Details
#android_config ⇒ Object (readonly)
Returns the value of attribute android_config.
9 10 11 |
# File 'lib/hey_you_fcm_push/message_object.rb', line 9 def android_config @android_config end |
#apns_config ⇒ Object (readonly)
Returns the value of attribute apns_config.
9 10 11 |
# File 'lib/hey_you_fcm_push/message_object.rb', line 9 def apns_config @apns_config end |
#fcm_options ⇒ Object (readonly)
Returns the value of attribute fcm_options.
9 10 11 |
# File 'lib/hey_you_fcm_push/message_object.rb', line 9 def @fcm_options end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/hey_you_fcm_push/message_object.rb', line 9 def name @name end |
#notification ⇒ Object (readonly)
Returns the value of attribute notification.
9 10 11 |
# File 'lib/hey_you_fcm_push/message_object.rb', line 9 def notification @notification end |
#push_data ⇒ Object (readonly)
Returns the value of attribute push_data.
9 10 11 |
# File 'lib/hey_you_fcm_push/message_object.rb', line 9 def push_data @push_data end |
#receiver_hash ⇒ Object (readonly)
Returns the value of attribute receiver_hash.
9 10 11 |
# File 'lib/hey_you_fcm_push/message_object.rb', line 9 def receiver_hash @receiver_hash end |
#web_push_config ⇒ Object (readonly)
Returns the value of attribute web_push_config.
9 10 11 |
# File 'lib/hey_you_fcm_push/message_object.rb', line 9 def web_push_config @web_push_config end |
Instance Method Details
#to_h ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hey_you_fcm_push/message_object.rb', line 40 def to_h { name: name, data: push_data, notification: notification&.to_h, android_config: android_config&.to_h, web_push_config: web_push_config&.to_h, apns_config: apns_config&.to_h, fcm_options: &.to_h }.merge(receiver_hash).compact end |