-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Paywalls
: implemented PostPaywallEventsOperation
This adds the operation + `PaywallEventsRequest` and associated tests. Also added method to `InternalAPI` for posting events.
- Loading branch information
Showing
10 changed files
with
485 additions
and
6 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
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
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
120 changes: 120 additions & 0 deletions
120
Sources/Paywalls/Events/Networking/PaywallEventsRequest.swift
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,120 @@ | ||
// | ||
// Copyright RevenueCat Inc. All Rights Reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/MIT | ||
// | ||
// PaywallEventsRequest.swift | ||
// | ||
// Created by Nacho Soto on 9/6/23. | ||
|
||
import Foundation | ||
|
||
/// The content of a request to the events endpoints. | ||
struct PaywallEventsRequest { | ||
|
||
var events: [Event] | ||
|
||
init(events: [Event]) { | ||
self.events = events | ||
} | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
init(events: [PaywallStoredEvent]) { | ||
self.init(events: events.map { .init(storedEvent: $0) }) | ||
} | ||
|
||
} | ||
|
||
extension PaywallEventsRequest { | ||
|
||
enum EventType: String { | ||
|
||
case view | ||
case cancel | ||
case close | ||
|
||
} | ||
|
||
struct Event { | ||
|
||
let version: Int | ||
var type: EventType | ||
var appUserID: String | ||
var sessionID: String | ||
var offeringID: String | ||
var paywallRevision: Int | ||
var timestamp: Date | ||
var displayMode: PaywallViewMode | ||
var darkMode: Bool | ||
var localeIdentifier: String | ||
|
||
} | ||
|
||
} | ||
|
||
extension PaywallEventsRequest.Event { | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
init(storedEvent: PaywallStoredEvent) { | ||
let data = storedEvent.event.data | ||
|
||
self.init( | ||
version: Self.version, | ||
type: storedEvent.event.eventType, | ||
appUserID: storedEvent.userID, | ||
sessionID: data.sessionIdentifier.uuidString, | ||
offeringID: data.offeringIdentifier, | ||
paywallRevision: data.paywallRevision, | ||
timestamp: data.date, | ||
displayMode: data.displayMode, | ||
darkMode: data.darkMode, | ||
localeIdentifier: data.localeIdentifier | ||
) | ||
} | ||
|
||
private static let version: Int = 1 | ||
|
||
} | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
private extension PaywallEvent { | ||
|
||
var eventType: PaywallEventsRequest.EventType { | ||
switch self { | ||
case .view: return .view | ||
case .cancel: return .cancel | ||
case .close: return .close | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
// MARK: - Codable | ||
|
||
extension PaywallEventsRequest.EventType: Encodable {} | ||
|
||
extension PaywallEventsRequest.Event: Encodable { | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
|
||
case version | ||
case type | ||
case appUserID = "appUserId" | ||
case sessionID = "sessionId" | ||
case offeringID = "offeringId" | ||
case paywallRevision | ||
case timestamp | ||
case displayMode | ||
case darkMode | ||
case localeIdentifier | ||
|
||
} | ||
|
||
} | ||
|
||
extension PaywallEventsRequest: HTTPRequestBody {} |
55 changes: 55 additions & 0 deletions
55
Sources/Paywalls/Events/Networking/PaywallHTTPRequestPath.swift
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,55 @@ | ||
// | ||
// Copyright RevenueCat Inc. All Rights Reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/MIT | ||
// | ||
// PaywallHTTPRequestPath.swift | ||
// | ||
// Created by Nacho Soto on 9/5/23. | ||
|
||
import Foundation | ||
|
||
extension HTTPRequest.PaywallPath: HTTPRequestPath { | ||
|
||
// TODO: TBD | ||
static let serverHostURL = URL(string: "https://api-paywalls.revenuecat.com")! | ||
|
||
var authenticated: Bool { | ||
switch self { | ||
case .postEvents: | ||
return true | ||
} | ||
} | ||
|
||
var shouldSendEtag: Bool { | ||
switch self { | ||
case .postEvents: | ||
return false | ||
} | ||
} | ||
|
||
var supportsSignatureVerification: Bool { | ||
switch self { | ||
case .postEvents: | ||
return false | ||
} | ||
} | ||
|
||
var needsNonceForSigning: Bool { | ||
switch self { | ||
case .postEvents: | ||
return false | ||
} | ||
} | ||
|
||
var pathComponent: String { | ||
switch self { | ||
case .postEvents: | ||
return "paywall_events" | ||
} | ||
} | ||
} |
Oops, something went wrong.