Skip to content

Commit 5ed4d12

Browse files
committed
Rename -> APNSwift
1 parent dacea3a commit 5ed4d12

22 files changed

+119
-119
lines changed

Package.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import PackageDescription
44
let package = Package(
55
name: "nio-apns",
66
products: [
7-
.executable(name: "NIOAPNSExample", targets: ["NIOAPNSExample"]),
8-
.library(name: "NIOAPNS", targets: ["NIOAPNS"]),
7+
.executable(name: "APNSwiftExample", targets: ["APNSwiftExample"]),
8+
.library(name: "APNSwift", targets: ["APNSwift"]),
99
],
1010
dependencies: [
1111
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
@@ -22,10 +22,10 @@ let package = Package(
2222
]
2323
),
2424

25-
.target(name: "NIOAPNSExample", dependencies: ["NIOAPNS"]),
26-
.testTarget(name: "NIOAPNSJWTTests", dependencies: ["NIOAPNS"]),
27-
.testTarget(name: "NIOAPNSTests", dependencies: ["NIOAPNS"]),
28-
.target(name: "NIOAPNS", dependencies: ["NIO",
25+
.target(name: "APNSwiftExample", dependencies: ["APNSwift"]),
26+
.testTarget(name: "APNSwiftJWTTests", dependencies: ["APNSwift"]),
27+
.testTarget(name: "APNSwiftTests", dependencies: ["APNSwift"]),
28+
.target(name: "APNSwift", dependencies: ["NIO",
2929
"NIOSSL",
3030
"NIOHTTP1",
3131
"NIOHTTP2",

README.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,33 @@ dependencies: [
1919
## Getting Started
2020

2121
```swift
22-
let signer = try! APNSSigner(filePath: "/Users/kylebrowning/Downloads/AuthKey_9UC9ZLQ8YW.p8")
22+
let signer = try! APNSwiftSigner(filePath: "/Users/kylebrowning/Downloads/AuthKey_9UC9ZLQ8YW.p8")
2323

24-
let apnsConfig = APNSConfiguration(keyIdentifier: "9UC9ZLQ8YW",
24+
let apnsConfig = APNSwiftConfiguration(keyIdentifier: "9UC9ZLQ8YW",
2525
teamIdentifier: "ABBM6U9RM5",
2626
signer: signer,
2727
topic: "com.grasscove.Fern",
2828
environment: .sandbox)
2929

30-
let apns = try APNSConnection.connect(configuration: apnsConfig, on: group.next()).wait()
30+
let apns = try APNSwiftConnection.connect(configuration: apnsConfig, on: group.next()).wait()
3131
let alert = Alert(title: "Hey There", subtitle: "Full moon sighting", body: "There was a full moon last night did you see it")
32-
let aps = APSPayload(alert: alert, badge: 1, sound: .normal("cow.wav"))
33-
let notification = APNSNotification(aps: aps)
32+
let aps = APNSwiftPayload(alert: alert, badge: 1, sound: .normal("cow.wav"))
33+
let notification = APNSwiftNotification(aps: aps)
3434
let res = try apns.send(notification, to: "de1d666223de85db0186f654852cc960551125ee841ca044fdf5ef6a4756a77e").wait()
3535
try apns.close().wait()
3636
try group.syncShutdownGracefully()
3737
```
3838

3939

40-
### APNSConfiguration
40+
### APNSwiftConfiguration
4141

42-
[`APNSConfiguration`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/NIOAPNS/APNSConfiguration.swift) is a structure that provides the system with common configuration.
42+
[`APNSwiftConfiguration`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/APNSwift/APNSwiftConfiguration.swift) is a structure that provides the system with common configuration.
4343

4444
```swift
45-
public struct APNSConfiguration {
45+
public struct APNSwiftConfiguration {
4646
public var keyIdentifier: String
4747
public var teamIdentifier: String
48-
public var signer: APNSSigner
48+
public var signer: APNSwiftSigner
4949
public var topic: String
5050
public var environment: Environment
5151
public var tlsConfiguration: TLSConfiguration
@@ -59,10 +59,10 @@ public struct APNSConfiguration {
5959
}
6060
}
6161
```
62-
#### Example `APNSConfiguration`
62+
#### Example `APNSwiftConfiguration`
6363
```swift
6464
let signer = ...
65-
let apnsConfig = try APNSConfiguration(keyIdentifier: "9UC9ZLQ8YW",
65+
let apnsConfig = try APNSwiftConfiguration(keyIdentifier: "9UC9ZLQ8YW",
6666
teamIdentifier: "ABBM6U9RM5",
6767
signer: signer),
6868
topic: "com.grasscove.Fern",
@@ -71,50 +71,50 @@ let apnsConfig = try APNSConfiguration(keyIdentifier: "9UC9ZLQ8YW",
7171

7272
### Signer
7373

74-
[`APNSSigner`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/NIOAPNS/APNSSigner.swift) provides a structure to sign the payloads with. This should be loaded into memory at the configuration level. It requires the data to be in a ByteBuffer format.
74+
[`APNSwiftSigner`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/APNSwift/APNSwiftSigner.swift) provides a structure to sign the payloads with. This should be loaded into memory at the configuration level. It requires the data to be in a ByteBuffer format.
7575

7676
```swift
7777
let url = URL(fileURLWithPath: "/Users/kylebrowning/Downloads/AuthKey_9UC9ZLQ8YW.p8")
7878
let data: Data
7979
do {
8080
data = try Data(contentsOf: url)
8181
} catch {
82-
throw APNSError.SigningError.certificateFileDoesNotExist
82+
throw APNSwiftError.SigningError.certificateFileDoesNotExist
8383
}
8484
var byteBuffer = ByteBufferAllocator().buffer(capacity: data.count)
8585
byteBuffer.writeBytes(data)
86-
let signer = try! APNSSigner.init(buffer: byteBuffer)
86+
let signer = try! APNSwiftSigner.init(buffer: byteBuffer)
8787
```
88-
### APNSConnection
88+
### APNSwiftConnection
8989

90-
[`APNSConnection`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/NIOAPNS/APNSConnection.swift) is a class with methods thats provides a wrapper to NIO's ClientBootstrap. The `swift-nio-http2` dependency is utilized here. It also provides a function to send a notification to a specific device token string.
90+
[`APNSwiftConnection`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/APNSwift/APNSwiftConnection.swift) is a class with methods thats provides a wrapper to NIO's ClientBootstrap. The `swift-nio-http2` dependency is utilized here. It also provides a function to send a notification to a specific device token string.
9191

9292

93-
#### Example `APNSConnection`
93+
#### Example `APNSwiftConnection`
9494
```swift
9595
let apnsConfig = ...
96-
let apns = try APNSConnection.connect(configuration: apnsConfig, on: group.next()).wait()
96+
let apns = try APNSwiftConnection.connect(configuration: apnsConfig, on: group.next()).wait()
9797
```
9898

9999
### Alert
100100

101-
[`Alert`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/NIOAPNS/APNSRequest.swift) is the actual meta data of the push notification alert someone wishes to send. More details on the specifics of each property are provided [here](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html). They follow a 1-1 naming scheme listed in Apple's documentation
101+
[`Alert`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/APNSwift/APNSRequest.swift) is the actual meta data of the push notification alert someone wishes to send. More details on the specifics of each property are provided [here](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html). They follow a 1-1 naming scheme listed in Apple's documentation
102102

103103

104104
#### Example `Alert`
105105
```swift
106106
let alert = Alert(title: "Hey There", subtitle: "Full moon sighting", body: "There was a full moon last night did you see it")
107107
```
108108

109-
### APSPayload
109+
### APNSwiftPayload
110110

111-
[`APSPayload`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/NIOAPNS/APNSRequest.swift) is the meta data of the push notification. Things like the alert, badge count. More details on the specifics of each property are provided [here](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html). They follow a 1-1 naming scheme listed in Apple's documentation
111+
[`APNSwiftPayload`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/APNSwift/APNSRequest.swift) is the meta data of the push notification. Things like the alert, badge count. More details on the specifics of each property are provided [here](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html). They follow a 1-1 naming scheme listed in Apple's documentation
112112

113113

114-
#### Example `APSPayload`
114+
#### Example `APNSwiftPayload`
115115
```swift
116116
let alert = ...
117-
let aps = APSPayload(alert: alert, badge: 1, sound: .normal("cow.wav"))
117+
let aps = APNSwiftPayload(alert: alert, badge: 1, sound: .normal("cow.wav"))
118118
```
119119

120120
## Putting it all together
@@ -126,21 +126,21 @@ let data: Data
126126
do {
127127
data = try Data(contentsOf: url)
128128
} catch {
129-
throw APNSError.SigningError.certificateFileDoesNotExist
129+
throw APNSwiftError.SigningError.certificateFileDoesNotExist
130130
}
131131
var byteBuffer = ByteBufferAllocator().buffer(capacity: data.count)
132132
byteBuffer.writeBytes(data)
133-
let signer = try! APNSSigner.init(buffer: byteBuffer)
133+
let signer = try! APNSwiftSigner.init(buffer: byteBuffer)
134134

135-
let apnsConfig = APNSConfiguration(keyIdentifier: "9UC9ZLQ8YW",
135+
let apnsConfig = APNSwiftConfiguration(keyIdentifier: "9UC9ZLQ8YW",
136136
teamIdentifier: "ABBM6U9RM5",
137137
signer: signer,
138138
topic: "com.grasscove.Fern",
139139
environment: .sandbox)
140140

141-
let apns = try APNSConnection.connect(configuration: apnsConfig, on: group.next()).wait()
141+
let apns = try APNSwiftConnection.connect(configuration: apnsConfig, on: group.next()).wait()
142142
let alert = Alert(title: "Hey There", subtitle: "Full moon sighting", body: "There was a full moon last night did you see it")
143-
let aps = APSPayload(alert: alert, badge: 1, sound: .normal("cow.wav"))
143+
let aps = APNSwiftPayload(alert: alert, badge: 1, sound: .normal("cow.wav"))
144144
let notification = BasicNotification(aps: aps)
145145
let res = try apns.send(notification, to: "de1d666223de85db0186f654852cc960551125ee841ca044fdf5ef6a4756a77e").wait()
146146
try apns.close().wait()
@@ -149,22 +149,22 @@ try group.syncShutdownGracefully()
149149

150150
### Custom Notification Data
151151

152-
Apple provides engineers with the ability to add custom payload data to each notification. In order to facilitate this we have the `APNSNotification`.
152+
Apple provides engineers with the ability to add custom payload data to each notification. In order to facilitate this we have the `APNSwiftNotification`.
153153

154154
#### Example
155155
```swift
156-
struct AcmeNotification: APNSNotification {
156+
struct AcmeNotification: APNSwiftNotification {
157157
let acme2: [String]
158-
let aps: APSPayload
158+
let aps: APNSwiftPayload
159159

160-
init(acme2: [String], aps: APSPayload) {
160+
init(acme2: [String], aps: APNSwiftPayload) {
161161
self.acme2 = acme2
162162
self.aps = aps
163163
}
164164
}
165165

166-
let apns: APNSConnection: = ...
167-
let aps: APSPayload = ...
166+
let apns: APNSwiftConnection: = ...
167+
let aps: APNSwiftPayload = ...
168168
let notification = AcmeNotification(acme2: ["bang", "whiz"], aps: aps)
169169
let res = try apns.send(notification, to: "de1d666223de85db0186f654852cc960551125ee841ca044fdf5ef6a4756a77e").wait()
170170
```

Sources/NIOAPNS/NIOAPNSJWT/APNSJWT.swift renamed to Sources/APNSwift/APNSSwiftJWT/APNSwiftJWT.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Foundation
1616
import CAPNSOpenSSL
1717
import NIO
1818

19-
internal struct APNSJWT: Codable {
19+
internal struct APNSwiftJWT: Codable {
2020
private struct Payload: Codable {
2121
/// iss
2222
public let teamID: String

Sources/NIOAPNS/NIOAPNSJWT/APNSJWTError.swift renamed to Sources/APNSwift/APNSSwiftJWT/APNSwiftJWTError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import Foundation
16-
internal enum APNSJWTError {
16+
internal enum APNSwiftJWTError {
1717
case encodingFailed
1818
case tokenWasNotGeneratedCorrectly
1919
}
2020

21-
extension APNSJWTError: LocalizedError {
21+
extension APNSwiftJWTError: LocalizedError {
2222
internal var errorDescription: String? {
2323
switch self {
2424
case .encodingFailed:

Sources/NIOAPNS/APNSConfiguration.swift renamed to Sources/APNSwift/APNSwiftConfiguration.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import NIOHTTP2
1818
import NIOSSL
1919

2020
/// This is structure that provides the system with common configuration.
21-
public struct APNSConfiguration {
21+
public struct APNSwiftConfiguration {
2222
public var keyIdentifier: String
2323
public var teamIdentifier: String
24-
public var signer: APNSSigner
24+
public var signer: APNSwiftSigner
2525
public var topic: String
2626
public var environment: Environment
2727
public var tlsConfiguration: TLSConfiguration
@@ -49,15 +49,15 @@ public struct APNSConfiguration {
4949

5050
### Usage Example: ###
5151
````
52-
let apnsConfig = try APNSConfiguration(keyIdentifier: "9UC9ZLQ8YW",
52+
let apnsConfig = try APNSwiftConfiguration(keyIdentifier: "9UC9ZLQ8YW",
5353
teamIdentifier: "ABBM6U9RM5",
5454
signingMode: .file(path: "/Users/kylebrowning/Downloads/AuthKey_9UC9ZLQ8YW.p8"),
5555
topic: "com.grasscove.Fern",
5656
environment: .sandbox
5757
)
5858
````
5959
*/
60-
public init(keyIdentifier: String, teamIdentifier: String, signer: APNSSigner, topic: String, environment: APNSConfiguration.Environment) {
60+
public init(keyIdentifier: String, teamIdentifier: String, signer: APNSwiftSigner, topic: String, environment: APNSwiftConfiguration.Environment) {
6161
self.keyIdentifier = keyIdentifier
6262
self.teamIdentifier = teamIdentifier
6363
self.topic = topic
@@ -67,7 +67,7 @@ public struct APNSConfiguration {
6767
}
6868
}
6969

70-
extension APNSConfiguration {
70+
extension APNSwiftConfiguration {
7171
public enum Environment {
7272
case production
7373
case sandbox

Sources/NIOAPNS/APNSConnection.swift renamed to Sources/APNSwift/APNSwiftConnection.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import NIO
1717
import NIOHTTP2
1818
import NIOSSL
1919

20-
public final class APNSConnection {
21-
public static func connect(configuration: APNSConfiguration, on eventLoop: EventLoop) -> EventLoopFuture<APNSConnection> {
20+
public final class APNSwiftConnection {
21+
public static func connect(configuration: APNSwiftConfiguration, on eventLoop: EventLoop) -> EventLoopFuture<APNSwiftConnection> {
2222
let bootstrap = ClientBootstrap(group: eventLoop)
2323
.channelOption(ChannelOptions.socket(IPPROTO_TCP, TCP_NODELAY), value: 1)
2424
.channelInitializer { channel in
@@ -38,30 +38,30 @@ public final class APNSConnection {
3838

3939
return bootstrap.connect(host: configuration.url.host!, port: 443).flatMap { channel in
4040
return channel.pipeline.handler(type: HTTP2StreamMultiplexer.self).map { multiplexer in
41-
return APNSConnection(channel: channel, multiplexer: multiplexer, configuration: configuration)
41+
return APNSwiftConnection(channel: channel, multiplexer: multiplexer, configuration: configuration)
4242
}
4343
}
4444
}
4545

4646
public let multiplexer: HTTP2StreamMultiplexer
4747
public let channel: Channel
48-
public let configuration: APNSConfiguration
48+
public let configuration: APNSwiftConfiguration
4949

50-
public init(channel: Channel, multiplexer: HTTP2StreamMultiplexer, configuration: APNSConfiguration) {
50+
public init(channel: Channel, multiplexer: HTTP2StreamMultiplexer, configuration: APNSwiftConfiguration) {
5151
self.channel = channel
5252
self.multiplexer = multiplexer
5353
self.configuration = configuration
5454
}
5555

5656
public func send<Notification>(_ notification: Notification, to deviceToken: String, with customEncoder: JSONEncoder? = nil, expiration: Date? = nil, priority: Int? = nil, collapseIdentifier: String? = nil, topic: String? = nil) -> EventLoopFuture<Void>
57-
where Notification: APNSNotification {
57+
where Notification: APNSwiftNotification {
5858
let streamPromise = channel.eventLoop.makePromise(of: Channel.self)
5959
multiplexer.createStreamChannel(promise: streamPromise) { channel, streamID in
6060
let handlers: [ChannelHandler] = [
6161
HTTP2ToHTTP1ClientCodec(streamID: streamID, httpProtocol: .https),
62-
APNSRequestEncoder<Notification>(deviceToken: deviceToken, configuration: self.configuration, expiration: expiration, priority: priority, collapseIdentifier: collapseIdentifier),
63-
APNSResponseDecoder(),
64-
APNSStreamHandler(),
62+
APNSwiftRequestEncoder<Notification>(deviceToken: deviceToken, configuration: self.configuration, expiration: expiration, priority: priority, collapseIdentifier: collapseIdentifier),
63+
APNSwiftResponseDecoder(),
64+
APNSwiftStreamHandler(),
6565
]
6666
return channel.pipeline.addHandlers(handlers)
6767
}
@@ -76,7 +76,7 @@ public final class APNSConnection {
7676

7777
var buffer = ByteBufferAllocator().buffer(capacity: data.count)
7878
buffer.writeBytes(data)
79-
let context = APNSRequestContext(
79+
let context = APNSwiftRequestContext(
8080
request: buffer,
8181
responsePromise: responsePromise
8282
)

Sources/NIOAPNS/APNSErrors.swift renamed to Sources/APNSwift/APNSwiftErrors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import Foundation
1616

1717
/// This is an enum that provides the possible responses from Apple
18-
public struct APNSError {
18+
public struct APNSwiftError {
1919
public enum ResponseError: Error {
2020
case badRequest(ResponseErrorMessage)
2121
}

0 commit comments

Comments
 (0)