This repository has been archived by the owner on Apr 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from nodes-vapor/feature/chaining-methods
Feature/chaining methods
- Loading branch information
Showing
23 changed files
with
857 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ Config/secrets/ | |
node_modules/ | ||
bower_components/ | ||
.swift-version | ||
CMakeLists.txt | ||
CMakeLists.txt | ||
Package.resolved |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import JSON | ||
|
||
/// Audience segment of an Urban Airship push notification payload | ||
/// See: https://docs.urbanairship.com/api/ua/#audience-selectors | ||
public struct Audience: Segment { | ||
|
||
// MARK: Class fields | ||
|
||
public let key: String = "audience" | ||
public let payload: JSON | ||
|
||
// MARK: Selector values | ||
|
||
public enum Selector: JSONRepresentable { | ||
case all | ||
case tag(value: String) | ||
case tags(values: [String]) | ||
case namedUser(value: String) | ||
case alias(value: String) | ||
|
||
public func makeJSON() throws -> JSON { | ||
switch self { | ||
case .all: | ||
return "all" | ||
case .tag(let value): | ||
var json: JSON = JSON() | ||
try json.set("tag", value) | ||
return json | ||
case .tags(let values): | ||
var json: JSON = JSON() | ||
try json.set("tag", values) | ||
return json | ||
case .namedUser(let value): | ||
var json: JSON = JSON() | ||
try json.set("named_user", value) | ||
return json | ||
case .alias(let value): | ||
print("\"alias\" is deprecated. Use \"named_user\" instead") | ||
print("See https://docs.urbanairship.com/api/ua/#data-formats-1 for more info") | ||
var json: JSON = JSON() | ||
try json.set("named_user", value) | ||
return json | ||
} | ||
} | ||
} | ||
|
||
// MARK: Initializers | ||
|
||
/// Init from JSON | ||
/// | ||
/// - Parameter payload: JSON | ||
public init(payload: JSON) { | ||
self.payload = payload | ||
} | ||
|
||
/// Init from Selector | ||
/// | ||
/// - Parameter selector: Selector | ||
public init(_ selector: Selector) throws { | ||
try self.payload = selector.makeJSON() | ||
} | ||
|
||
} |
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,44 @@ | ||
|
||
import JSON | ||
|
||
/// Campaigns segment of an Urban Airship push notification payload | ||
/// See: https://docs.urbanairship.com/api/ua/#campaigns-object | ||
public struct Campaigns: Segment { | ||
|
||
// MARK: Class fields | ||
|
||
public let key: String = "campaigns" | ||
public let payload: JSON | ||
|
||
// MARK: Selector values | ||
|
||
public enum Selector: JSONRepresentable { | ||
case categories(values: [String]) | ||
|
||
public func makeJSON() throws -> JSON { | ||
switch self { | ||
case .categories(let values): | ||
var json: JSON = JSON() | ||
try json.set("categories", values) | ||
return json | ||
} | ||
} | ||
} | ||
|
||
// MARK: Initializers | ||
|
||
/// Init from JSON | ||
/// | ||
/// - Parameter payload: JSON | ||
public init(payload: JSON) { | ||
self.payload = payload | ||
} | ||
|
||
/// Init from Selector | ||
/// | ||
/// - Parameter selector: Selector | ||
public init(_ selector: Selector) throws { | ||
try self.payload = selector.makeJSON() | ||
} | ||
|
||
} |
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,71 @@ | ||
import JSON | ||
|
||
/// Device type segment of an Urban Airship push notification payload | ||
/// See: https://docs.urbanairship.com/integration/#device-types | ||
public struct DeviceTypes: Segment { | ||
|
||
// MARK: Class fields | ||
|
||
public let key: String = "device_types" | ||
public let payload: JSON | ||
|
||
// MARK: Selector values | ||
|
||
public enum Selector: JSONRepresentable { | ||
case all | ||
case ios | ||
case android | ||
case windows | ||
case web | ||
|
||
public func makeJSON() -> JSON { | ||
switch self { | ||
case .all: | ||
return "all" | ||
case .ios: | ||
return "ios" | ||
case .android: | ||
return "android" | ||
case .windows: | ||
return "wns" | ||
case .web: | ||
return "web" | ||
} | ||
} | ||
} | ||
|
||
// MARK: Initializers | ||
|
||
/// Init from JSON | ||
/// | ||
/// - Parameter payload: JSON | ||
public init(payload: JSON) { | ||
self.payload = payload | ||
} | ||
|
||
/// Init from Selector | ||
/// | ||
/// - Parameter selector: Selector | ||
public init(_ selector: Selector) throws { | ||
guard selector == .all else { | ||
self.init([selector]) | ||
return | ||
} | ||
|
||
self.init(payload: selector.makeJSON()) | ||
} | ||
|
||
/// Init from list of predefined values | ||
/// | ||
/// - Parameter selectors: [Selector] | ||
public init(_ selectors: [Selector]) { | ||
var compoundJson: [JSON] = [] | ||
|
||
for selector in selectors { | ||
compoundJson.append(selector.makeJSON()) | ||
} | ||
|
||
self.init(payload: JSON(compoundJson)) | ||
} | ||
|
||
} |
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,21 @@ | ||
|
||
import JSON | ||
|
||
/// In-app segment of an Urban Airship push notification payload | ||
/// See: https://docs.urbanairship.com/api/ua/#api-in-app-object | ||
public struct InApp: Segment { | ||
// MARK: Class fields | ||
|
||
public let key: String = "in_app" | ||
public let payload: JSON | ||
|
||
// MARK: Initializers | ||
|
||
/// Init from JSON | ||
/// | ||
/// - Parameter payload: JSON | ||
public init(payload: JSON) { | ||
self.payload = payload | ||
} | ||
|
||
} |
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,24 @@ | ||
|
||
import JSON | ||
|
||
/// Message (rich push) segment of an Urban Airship push notification payload | ||
/// See: https://docs.urbanairship.com/api/ua/#rich-push-api | ||
/// NB: This requires a special plan at UA. | ||
/// See: https://www.urbanairship.com/products/mobile-app-engagement/pricing | ||
public struct Message: Segment { | ||
|
||
// MARK: Class fields | ||
|
||
public let key: String = "message" | ||
public let payload: JSON | ||
|
||
// MARK: Initializers | ||
|
||
/// Init from JSON | ||
/// | ||
/// - Parameter payload: JSON | ||
public init(payload: JSON) { | ||
self.payload = payload | ||
} | ||
|
||
} |
Oops, something went wrong.