forked from ileitch/rapns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Rapns::Config class; Adding support for Config to be modified …
…from the rails app 'config/initializers/rapns.rb' file; Adding Feedback receiver call a callback when feedback is received. For issue ileitch#77
- Loading branch information
1 parent
db18892
commit 3fd15dd
Showing
5 changed files
with
90 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
require 'rapns/notification' | ||
require 'rapns/feedback' | ||
require 'rapns/app' | ||
require 'rapns/config' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module Rapns | ||
|
||
# A globally accessible instance of Rapns::Config | ||
def self.configuration | ||
@configuration ||= Rapns::Config.new | ||
end | ||
|
||
# Call the given block yielding to it the global Rapns::Config instance for setting | ||
# configuration values / callbacks. | ||
# | ||
# Typically this would be used in your Rails application's config/initializers/rapns.rb file | ||
def self.configure | ||
yield configuration if block_given? | ||
end | ||
|
||
# A class to hold Rapns configuration settings and callbacks. | ||
class Config < Struct.new(:foreground, :push_poll, :feedback_poll, :airbrake_notify, :check_for_errors, :pid_file, :batch_size) | ||
|
||
attr_accessor :feedback_callback | ||
|
||
# Initialize the Config with default values | ||
def initialize | ||
super | ||
|
||
# defaults: | ||
self.foreground = false | ||
self.push_poll = 2 | ||
self.feedback_poll = 60 | ||
self.airbrake_notify = true | ||
self.check_for_errors = true | ||
self.batch_size = 5000 | ||
end | ||
|
||
# Define a block that will be executed with a Rapns::Feedback instance when feedback has been received from the | ||
# push notification servers that a notification has failed to be delivered. Further notifications should not | ||
# be sent to this device token. | ||
# | ||
# Example usage (in config/initializers/rapns.rb): | ||
# | ||
# Rapns.configure do |config| | ||
# config.on_feedback do |feedback| | ||
# device = Device.find_by_device_token feedback.device_token | ||
# if device | ||
# device.active = false | ||
# device.save | ||
# end | ||
# end | ||
# end | ||
# | ||
# Where `Device` is a model specific to your Rails app that has a `device_token` field. | ||
def on_feedback(&block) | ||
self.feedback_callback = block | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters