lib/notification_pusher/one_signal.rb in notification-pusher-onesignal-1.2.5 vs lib/notification_pusher/one_signal.rb in notification-pusher-onesignal-1.2.6
- old
+ new
@@ -1,18 +1,38 @@
-require 'one_signal'
-
-class NotificationPusher::OneSignal
-
- def initialize notification, options = {}
- if options[:player_ids].any?
- ::OneSignal::Notification.create params: {
- app_id: options[:app_id],
- url: options[:url] || notification.metadata[:onesignal_url],
- contents: options[:contents] || notification.metadata[:onesignal_contents].to_h,
- headings: options[:headings] || notification.metadata[:onesignal_headings].to_h,
- subtitle: options[:subtitle] || notification.metadata[:onesignal_subtitle].to_h,
- include_player_ids: options[:player_ids]
- }, opts: { auth_key: options[:auth_key] }
- end
- end
-
-end
+# frozen_string_literal: true
+
+require 'one_signal'
+
+module NotificationPusher
+ class OneSignal
+ def initialize(notification, options = {})
+ return unless options[:player_ids].any?
+
+ ::OneSignal::Notification.create params: {
+ app_id: options[:app_id],
+ url: url_param(options[:url], notification),
+ contents: contents_param(options[:contents], notification),
+ headings: headings_param(options[:headings], notification),
+ subtitle: subtitle_param(options[:subtitle], notification),
+ include_player_ids: options[:player_ids]
+ }, opts: { auth_key: options[:auth_key] }
+ end
+
+ private
+
+ def url_param(url, notification)
+ url || notification.metadata[:onesignal_url].to_h
+ end
+
+ def contents_param(contents, notification)
+ contents || notification.metadata[:onesignal_contents].to_h
+ end
+
+ def headings_param(headings, notification)
+ headings || notification.metadata[:onesignal_headings].to_h
+ end
+
+ def subtitle_param(subtitle, notification)
+ subtitle || notification.metadata[:onesignal_subtitle].to_h
+ end
+ end
+end