Class: Notifun::Notifier::CloudFiveNotifier

Inherits:
ParentNotifier show all
Defined in:
lib/notifun/notifiers/cloud_five_notifier.rb

Instance Attribute Summary

Attributes inherited from ParentNotifier

#error_message, #success

Instance Method Summary collapse

Methods inherited from ParentNotifier

#initialize

Constructor Details

This class inherits a constructor from Notifun::Notifier::ParentNotifier

Instance Method Details

#notify!(text, title, uuid, options) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/notifun/notifiers/cloud_five_notifier.rb', line 2

def notify!(text, title, uuid, options)
  if !defined?(CloudFivePush)
    @success = false
    @error_message = "CloudFivePush is not defined."
    return
  end
  api_key = options[:api_key].presence
  api_key ||= Notifun.configuration.push_config[:api_key]
  return false unless api_key.present?
  notification = CloudFivePush::Notification.new(api_key)
  if title.present?
    notification.alert = title
    notification.message = text
  else
    notification.alert = text
    notification.message = ""
  end
  notification.user_identifiers = [uuid]
  notification.data = options[:push_data]
  notification.content_available = options[:content_available]
  notification.badge = options[:badge].presence
  response = notification.notify!

  if response['success']
    @success = true
  else
    @error_message = response["error"].presence || "Failed to send push notification"
    @success = false
  end
end