Skip to content
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: add PaywallData.revision #3155

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion RevenueCatUI/Helpers/PaywallData+Default.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ extension PaywallData {
displayRestorePurchases: true
),
localization: Self.localization,
assetBaseURL: Self.defaultTemplateBaseURL
assetBaseURL: Self.defaultTemplateBaseURL,
revision: Self.revisionID
)
}

static let defaultTemplate: PaywallTemplate = .template2

static let appIconPlaceholder = "revenuecatui_default_paywall_app_icon"
static let revisionID: Int = -1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me and confirmed by @estefaniarabadan 👍


}

Expand Down
6 changes: 6 additions & 0 deletions Sources/Misc/Codable/DefaultDecodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ enum DefaultDecodable {
static var defaultValue: String { "" }
}

enum Zero: DefaultValueProvider {
static var defaultValue: Int { 0 }
}

enum EmptyArray<T: List>: DefaultValueProvider {
static var defaultValue: T { [] }
}
Expand Down Expand Up @@ -226,6 +230,7 @@ enum DefaultDecodable {
* @DefaultDecodable.EmptyArray var values: [String]
* @DefaultDecodable.EmptyDictionary var dictionary: [String: Int]
* @DefaultDecodable.Now var date: Date
* @DefaultDecodable.Zero var number: Int
* }
* ```
*/
Expand All @@ -237,5 +242,6 @@ extension DefaultDecodable {
typealias EmptyArray<T: List> = DefaultValue<Sources.EmptyArray<T>>
typealias EmptyDictionary<T: Map> = DefaultValue<Sources.EmptyDictionary<T>>
typealias Now = DefaultValue<Sources.Now>
typealias Zero = DefaultValue<Sources.Zero>

}
24 changes: 18 additions & 6 deletions Sources/Paywalls/PaywallData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//
// Created by Nacho Soto on 7/10/23.

// swiftlint:disable file_length
// swiftlint:disable file_length identifier_name

import Foundation

Expand All @@ -31,6 +31,15 @@ public struct PaywallData {
/// The base remote URL where assets for this paywall are stored.
public var assetBaseURL: URL

/// The revision identifier for this paywall.
var revision: Int {
get { return self._revision }
set { self._revision = newValue }
}

@DefaultDecodable.Zero
internal private(set) var _revision: Int = 0

@EnsureNonEmptyCollectionDecodable
internal private(set) var localization: [String: LocalizedConfiguration]

Expand Down Expand Up @@ -60,8 +69,6 @@ public protocol PaywallLocalizedConfiguration {

}

// swiftlint:disable identifier_name

extension PaywallData {

/// Defines the necessary localized information for a paywall.
Expand Down Expand Up @@ -347,28 +354,32 @@ extension PaywallData {
templateName: String,
config: Configuration,
localization: [String: LocalizedConfiguration],
assetBaseURL: URL
assetBaseURL: URL,
revision: Int = 0
) {
self.templateName = templateName
self.config = config
self.localization = localization
self.assetBaseURL = assetBaseURL
self.revision = revision
}

/// Creates a test ``PaywallData`` with one localization
public init(
templateName: String,
config: Configuration,
localization: LocalizedConfiguration,
assetBaseURL: URL
assetBaseURL: URL,
revision: Int = 0
) {
let locale = Locale.current.identifier

self.init(
templateName: templateName,
config: config,
localization: [locale: localization],
assetBaseURL: assetBaseURL
assetBaseURL: assetBaseURL,
revision: revision
)
}

Expand Down Expand Up @@ -428,6 +439,7 @@ extension PaywallData: Codable {
case config
case localization = "localizedStrings"
case assetBaseURL = "assetBaseUrl"
case _revision = "revision"
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"title" : "Ignite your child's curiosity"
}
},
"revision" : 1,
"template_name" : "1"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"title" : "Ignite your child's curiosity"
}
},
"revision" : 3,
"template_name" : "2"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
"title" : "{{ app_name }}"
}
},
"revision" : -1,
"template_name" : "2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
"title" : "{{ app_name }}"
}
},
"revision" : -1,
"template_name" : "2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
"title" : "{{ app_name }}"
}
},
"revision" : -1,
"template_name" : "2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
"title" : "{{ app_name }}"
}
},
"revision" : -1,
"template_name" : "2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
"title" : "{{ app_name }}"
}
},
"revision" : -1,
"template_name" : "2"
}
3 changes: 2 additions & 1 deletion Tests/UnitTests/Networking/Responses/Fixtures/Offerings.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
"dark": null
}
},
"asset_base_url": "https://rc-paywalls.s3.amazonaws.com"
"asset_base_url": "https://rc-paywalls.s3.amazonaws.com",
"revision": 5
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@
}
}
},
"asset_base_url": "https://rc-paywalls.s3.amazonaws.com"
"asset_base_url": "https://rc-paywalls.s3.amazonaws.com",
"revision": 7
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class OfferingsDecodingTests: BaseHTTPResponseTest {
let paywall = try XCTUnwrap(offering.paywall)
expect(paywall.templateName) == "1"
try expect(paywall.assetBaseURL) == XCTUnwrap(URL(string: "https://rc-paywalls.s3.amazonaws.com"))
expect(paywall.revision) == 5

expect(paywall.config.packages) == ["$rc_monthly", "$rc_annual", "custom_package"]
expect(paywall.config.defaultPackage).to(beNil())
Expand Down
1 change: 1 addition & 0 deletions Tests/UnitTests/Paywalls/PaywallDataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class PaywallDataTests: BaseHTTPResponseTest {

expect(paywall.templateName) == "1"
expect(paywall.assetBaseURL) == URL(string: "https://rc-paywalls.s3.amazonaws.com")!
expect(paywall.revision) == 7
expect(paywall.config.packages) == ["$rc_monthly", "$rc_annual", "custom_package"]
expect(paywall.config.defaultPackage) == "$rc_annual"
expect(paywall.config.images) == .init(
Expand Down