From afc99875d2213d72c69d180ab602ac7dfd21be6b Mon Sep 17 00:00:00 2001 From: Tanner Date: Thu, 9 Jan 2020 16:33:23 -0500 Subject: [PATCH] Make Application.APNS an APNSwiftClient (#12) --- Sources/APNS/Application+APNS.swift | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Sources/APNS/Application+APNS.swift b/Sources/APNS/Application+APNS.swift index 42c41c1..14737af 100644 --- a/Sources/APNS/Application+APNS.swift +++ b/Sources/APNS/Application+APNS.swift @@ -50,3 +50,40 @@ extension Application { let application: Application } } + +extension Application.APNS: APNSwiftClient { + public var logger: Logger? { + self.application.logger + } + + public var eventLoop: EventLoop { + self.application.eventLoopGroup.next() + } + + public func send( + rawBytes payload: ByteBuffer, + pushType: APNSwiftConnection.PushType, + to deviceToken: String, + expiration: Date?, + priority: Int?, + collapseIdentifier: String?, + topic: String?, + logger: Logger? + ) -> EventLoopFuture { + self.application.apns.pool.withConnection( + logger: logger, + on: self.eventLoop + ) { + $0.send( + rawBytes: payload, + pushType: pushType, + to: deviceToken, + expiration: expiration, + priority: priority, + collapseIdentifier: collapseIdentifier, + topic: topic, + logger: logger + ) + } + } +}