Module: FwtPushNotificationServer
- Defined in:
- lib/fwt_push_notification_server.rb,
lib/fwt_push_notification_server/engine.rb,
lib/fwt_push_notification_server/version.rb,
app/models/fwt_push_notification_server/user.rb,
app/models/fwt_push_notification_server/device_token.rb,
app/helpers/fwt_push_notification_server/application_helper.rb,
app/helpers/fwt_push_notification_server/device_tokens_helper.rb,
app/controllers/fwt_push_notification_server/application_controller.rb,
app/controllers/fwt_push_notification_server/device_tokens_controller.rb,
lib/generators/fwt_push_notification_server/install/install_generator.rb
Defined Under Namespace
Modules: ApplicationHelper, DeviceTokensHelper, Generators
Classes: ApplicationController, DeviceToken, DeviceTokensController, Engine, User
Constant Summary
collapse
- VERSION =
"0.0.6"
Class Method Summary
collapse
Class Method Details
.apns_config ⇒ Object
10
11
12
|
# File 'lib/fwt_push_notification_server.rb', line 10
def self.apns_config
config.slice(:gateway, :certificate, :passphrase)
end
|
.send_notification(alert, device_tokens) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/fwt_push_notification_server.rb', line 19
def self.send_notification(alert, device_tokens)
alert = alert.byteslice(0, 232)
alert += '...' if alert.bytesize > 232
config = self.apns_config
pusher = Grocer.pusher(config)
device_tokens = [device_tokens] unless device_tokens.is_a?(Array)
device_tokens.each do |device|
if device.is_valid
token = device.token
n = Grocer::Notification.new(device_token: token, alert: alert)
pusher.push n
end
end
feedback = Grocer.feedback(config)
feedback.each do |attempt|
token = attempt.device_token
device_token = DeviceToken.find_by_token(token)
device_token.update_attribute("is_valid", false) unless device_token.nil?
puts "Device #{token} failed at #{attempt.timestamp}"
end
end
|
.send_notification_to_all(alert) ⇒ Object
14
15
16
17
|
# File 'lib/fwt_push_notification_server.rb', line 14
def self.send_notification_to_all(alert)
devices = DeviceToken.where(:is_valid => true).all
send_notification(alert, devices)
end
|