Sha256: 12cfe3da474cb75b30f0422fc66de785801eea5c47e81f041649532eec67eb22

Contents?: true

Size: 1019 Bytes

Versions: 2

Compression:

Stored size: 1019 Bytes

Contents

# frozen_string_literal: true

module NotificationPusher
  module DeliveryMethod
    class OneSignal < NotificationPusher::DeliveryMethod::Base
      def call
        return unless options[:player_ids].any?

        ::OneSignal::Notification.create params: {
          app_id: options[:app_id],
          url: url_param,
          contents: contents_param,
          headings: headings_param,
          subtitle: subtitle_param,
          include_player_ids: options[:player_ids]
        }, opts: { auth_key: options[:auth_key] }
      end

      private

      def url_param
        options[:url]      || notification.metadata[:onesignal_url].to_h
      end

      def contents_param
        options[:contents] || notification.metadata[:onesignal_contents].to_h
      end

      def headings_param
        options[:headings] || notification.metadata[:onesignal_headings].to_h
      end

      def subtitle_param
        options[:subtitle] || notification.metadata[:onesignal_subtitle].to_h
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
notification-pusher-onesignal-3.0.2 lib/notification_pusher/delivery_method/one_signal.rb
notification-pusher-onesignal-2.0.0 lib/notification_pusher/delivery_method/one_signal.rb