Sha256: deb0e716b20e28d9519c816aa0dd395107e8e5d4217b291e3562b5c09620f555

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

# 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
notification-pusher-onesignal-1.2.6 lib/notification_pusher/one_signal.rb