Class: Nuntius::HoustonPushProvider

Inherits:
BaseProvider show all
Defined in:
app/providers/nuntius/houston_push_provider.rb

Instance Attribute Summary

Attributes inherited from BaseProvider

#message

Instance Method Summary collapse

Methods inherited from BaseProvider

all_settings, #callback, class_from_name, #initialize, #name, #refresh, setting_reader, states, transport

Constructor Details

This class inherits a constructor from Nuntius::BaseProvider

Instance Method Details

#deliverObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/providers/nuntius/houston_push_provider.rb', line 21

def deliver
  return message if message.to.size != 64

  apn = environment.to_sym == :development ? Houston::Client.development : Houston::Client.production
  apn.certificate = certificate
  apn.passphrase = passphrase

  notification = Houston::Notification.new((message.payload || {}).merge(device: message.to,
                                                                         alert: message.text, sound: 'default'))
  apn.push(notification)

  message.status = if notification.sent?
                     'sent'
                   elsif !notification.valid? || notification.error
                     'undelivered'
                   end
  message
end