-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Paywalls
: implemented PostPaywallEventsOperation
#3158
Changes from all commits
a517ef0
34ec40b
345787d
d595ec8
51f57ac
6579ec4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 {} |
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is thanks to the refactor in #2986 |
||
|
||
static let serverHostURL = URL(string: "https://api-paywalls.revenuecat.com")! | ||
|
||
var authenticated: Bool { | ||
switch self { | ||
case .postEvents: | ||
return true | ||
} | ||
Comment on lines
+21
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sure this makes sense, but why do all of these do switch self case .postEvents return hardcoded value? why not just return the harcoded value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So that when/if we add a new path the compiler fails and forces us to implement these for the new |
||
} | ||
|
||
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 "events" | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need main thread for anything in paywall events?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I did that out of habit from other operations, but
ResponseHandler
isn't@MainActor
anyway.I'll fix in the next PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10da09b