metatext/Networking/Mastodon API/Endpoints/PushSubscriptionEndpoint.swift

62 lines
1.9 KiB
Swift
Raw Normal View History

2020-08-12 07:24:39 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
enum PushSubscriptionEndpoint {
case create(
endpoint: URL,
publicKey: String,
auth: String,
2020-08-14 01:24:53 +00:00
alerts: PushSubscription.Alerts)
2020-08-12 07:24:39 +00:00
case read
2020-08-14 01:24:53 +00:00
case update(alerts: PushSubscription.Alerts)
2020-08-12 07:24:39 +00:00
case delete
}
extension PushSubscriptionEndpoint: MastodonEndpoint {
typealias ResultType = PushSubscription
var context: [String] {
defaultContext + ["push", "subscription"]
}
var pathComponentsInContext: [String] { [] }
var method: HTTPMethod {
switch self {
case .create: return .post
case .read: return .get
case .update: return .put
case .delete: return .delete
}
}
var parameters: [String: Any]? {
switch self {
2020-08-14 01:24:53 +00:00
case let .create(endpoint, publicKey, auth, alerts):
2020-08-12 07:24:39 +00:00
return ["subscription":
["endpoint": endpoint.absoluteString,
"keys": [
"p256dh": publicKey,
"auth": auth]],
"data": [
"alerts": [
2020-08-14 01:24:53 +00:00
"follow": alerts.follow,
"favourite": alerts.favourite,
"reblog": alerts.reblog,
"mention": alerts.mention,
"poll": alerts.poll
2020-08-12 07:24:39 +00:00
]]]
2020-08-14 01:24:53 +00:00
case let .update(alerts):
2020-08-12 07:24:39 +00:00
return ["data":
["alerts":
2020-08-14 01:24:53 +00:00
["follow": alerts.follow,
"favourite": alerts.favourite,
"reblog": alerts.reblog,
"mention": alerts.mention,
"poll": alerts.poll]]]
2020-08-12 07:24:39 +00:00
default: return nil
}
}
}