From b50045a2511b11800c7f830319fd1832020142ee Mon Sep 17 00:00:00 2001 From: Vincent Sellier Date: Wed, 26 Mar 2014 12:39:15 +0100 Subject: [PATCH] Support an option delegateBean in configuration --- ApnsGrailsPlugin.groovy | 4 ++++ README.md | 9 +++++++++ .../org/epseelon/grails/apns/ApnsFactoryBean.groovy | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/ApnsGrailsPlugin.groovy b/ApnsGrailsPlugin.groovy index a1dc5b9..918dc1c 100644 --- a/ApnsGrailsPlugin.groovy +++ b/ApnsGrailsPlugin.groovy @@ -41,6 +41,10 @@ push notifications to an iPhone client of your Grails application. certificateResourcePath = application.config.apns.certificateResourcePath ?: null password = application.config.apns.password environment = configuredEnvironment + if ( application.config.apns.delegateBean ) { + log.debug "Using delegate ${application.config.apns.delegateBean}" + delegateBean = ref( application.config.apns.delegateBean ) + } } } diff --git a/README.md b/README.md index 62e2823..5cde72c 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,15 @@ If you don't have access to your server's file system, you can also replace path This new configuration system is way better for Heroku deployment. +You can configure a bean to be notified by sent event via the option "delegateBean". This bean must implement the interface com.notnoop.apns.ApnsDelegate. + + apns { + pathToCertificate = "/usr/local/myapp/APNs_production_certificates.p12" + password = "password" + environment = "production" + delegateBean = "apnsDelegateService" + } + Usage ===== diff --git a/src/groovy/org/epseelon/grails/apns/ApnsFactoryBean.groovy b/src/groovy/org/epseelon/grails/apns/ApnsFactoryBean.groovy index 13d3f7e..c19a8d8 100644 --- a/src/groovy/org/epseelon/grails/apns/ApnsFactoryBean.groovy +++ b/src/groovy/org/epseelon/grails/apns/ApnsFactoryBean.groovy @@ -17,6 +17,7 @@ class ApnsFactoryBean implements FactoryBean { boolean queued = false Environment environment = Environment.SANDBOX boolean nonBlocking = false + def delegateBean Object getObject() { def apnsService = APNS.newService() @@ -49,6 +50,10 @@ class ApnsFactoryBean implements FactoryBean { apnsService = apnsService.asQueued() + if( delegateBean ) { + apnsService = apnsService.withDelegate( delegateBean ) + } + return apnsService.build() }