Class: Nuntius::ApnoticPushProvider

Inherits:
BaseProvider show all
Defined in:
app/providers/nuntius/apnotic_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
39
40
41
42
# File 'app/providers/nuntius/apnotic_push_provider.rb', line 21

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

  connection = if environment.to_sym == :development
    Apnotic::Connection.development(cert_path: StringIO.new(certificate), cert_pass: passphrase)
  else
    Apnotic::Connection.new(cert_path: StringIO.new(certificate), cert_pass: passphrase)
  end

  notification = Apnotic::Notification.new(message.to)
  notification.alert = message.text
  notification.custom_payload = message.payload

  response = connection.push(notification)

  message.status = if response.ok?
    "sent"
  else
    "undelivered"
  end
  message
end