class ActiveNotifier::Transports::Pushmeup

Attributes

configuration[RW]

Public Class Methods

deliver(tokens, payload, network) click to toggle source
# File lib/active_notifier/transports/pushmeup.rb, line 43
def self.deliver(tokens, payload, network)
  case network
  when 'apns'
    APNS.send_notification(tokens, payload)
  when 'gcm'
    GCM.send_notification(tokens, payload)
  else
    fail "Unrecognized network"
  end
end
new(configuration, notifier) click to toggle source
# File lib/active_notifier/transports/pushmeup.rb, line 12
def initialize(configuration, notifier)
  self.configuration = configuration
end

Public Instance Methods

deliverable(notifier) click to toggle source
# File lib/active_notifier/transports/pushmeup.rb, line 16
def deliverable(notifier)
  if configuration[:device_list_attribute]
    devices = notifier.recipient.public_send(configuration[:device_list_attribute])
  else
    devices = Array(notifier.recipient)
  end

  deliverables = devices.map do |device|
    token_attribute = configuration.token_attribute
    token = device.public_send(token_attribute)
    if token.blank?
      raise ActiveNotifier::DeliveryImpossible.new("Recipient mobile token not present.")
    end

    network_attribute = configuration.network_attribute
    network = device.public_send(network_attribute)
    if token.blank?
      raise ActiveNotifier::DeliveryImpossible.new("Recipient network token not present.")
    end

    payload = configuration.serializer.new(notifier).as_json(root: false)

    Deliverable.new(token, payload, network)
  end
  MultipleDeliverables.new(deliverables)
end