Class: HeyYouFcmPush::MessageObject

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, token: nil, topic: nil, condition: nil, **options) ⇒ MessageObject

Returns a new instance of MessageObject.

Parameters:

  • [String] (Hash)

    a customizable set of options

  • [Hash] (Hash)

    a customizable set of options

Raises:

See Also:



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, **options)
  @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(**options[:notification].transform_keys(&:to_sym)) if options[:notification]
  @android_config = AndroidConfig.new(options[:android].transform_keys(&:to_sym)) if options[:android_config]
  @web_push_config = WebPushConfig.new(options[:webpush].transform_keys(&:to_sym)) if options[:web_push_config]
  @apns_config = ApnsConfig.new(options[:apns].transform_keys(&:to_sym)) if options[:apns_config]
  @fcm_options = FcmOptions.new(**options[:fcm_options].transform_keys(&:to_sym)) if options[:fcm_options]
  @push_data = { data: options[:data].to_json }
end

Instance Attribute Details

#android_configObject (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_configObject (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_optionsObject (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
  @fcm_options
end

#nameObject (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

#notificationObject (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_dataObject (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_hashObject (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_configObject (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_hObject



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: fcm_options&.to_h
  }.merge(receiver_hash).compact
end