/
PushConfiguration.swift
48 lines (40 loc) · 1.77 KB
/
PushConfiguration.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
47
48
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import Foundation
public enum PushConfigurationLabel: String {
case Developer = "Developer"
case Stage = "Stage"
case Production = "Production"
public func toConfiguration() -> PushConfiguration {
switch self {
case .Stage: return StagePushConfiguration()
case .Production: return ProductionPushConfiguration()
case .Developer: return DeveloperPushConfiguration()
}
}
}
public protocol PushConfiguration {
var label: PushConfigurationLabel { get }
/// The associated autopush server should speak the protocol documented at
/// http://autopush.readthedocs.io/en/latest/http.html#push-service-http-api
/// /v1/{type}/{app_id}
/// type == apns
/// app_id == the “platform” or “channel” of development (e.g. “firefox”, “beta”, “gecko”, etc.)
var endpointURL: NSURL { get }
}
public struct DeveloperPushConfiguration: PushConfiguration {
public init() {}
public let label = PushConfigurationLabel.Developer
public let endpointURL = NSURL(string: "https://updates-autopush.dev.mozaws.net/v1/apns/dev")!
}
public struct StagePushConfiguration: PushConfiguration {
public init() {}
public let label = PushConfigurationLabel.Stage
public let endpointURL = NSURL(string: "https://updates-autopush.stage.mozaws.net/v1/apns/stage")!
}
public struct ProductionPushConfiguration: PushConfiguration {
public init() {}
public let label = PushConfigurationLabel.Production
public let endpointURL = NSURL(string: "https://updates.push.services.mozilla.com/v1/apns/firefox")!
}