Sha256: e66485d47244e7e4d2371f26c0f0f4bcb0717fef3b062e03587780083390a5cb

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

class ApnsChannel
  class << self

  	def default_options
  	  {
  	    description: "Push Notifications"
  	  }
  	end

    def deliver(notification, options={})
      devices = fetch_devices(notification, options[:device_method])

      NotifyUser::Apns.new([notification], devices[:ios], options).push if devices[:ios].any?
      NotifyUser::Gcm.new([notification], devices[:android], options).push if devices[:android].any?
    end

    def deliver_aggregated(notifications, options={})
      devices = fetch_devices(notifications.first, options[:device_method])

      NotifyUser::Apns.new(notifications, devices[:ios], options).push if devices[:ios].any?
      NotifyUser::Gcm.new(notifications, devices[:android], options).push if devices[:android].any?
    end

    private

    def fetch_devices(notification, device_method = nil)
      device_method ||= :devices
      devices = notification.target.send(device_method)

      { ios: devices.ios.to_a, android: devices.android.to_a }
    rescue
      Rails.logger.info "Notification target, #{notification.target.class}, does not respond to the method, #{device_method}."
      { ios: [], android: [] }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
notify_user-0.3.2 lib/notify_user/channels/apns/apns_channel.rb
notify_user-0.3.1 lib/notify_user/channels/apns/apns_channel.rb