-
Notifications
You must be signed in to change notification settings - Fork 54
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
Serializes PaywallData #1222
Serializes PaywallData #1222
Conversation
67a5905
to
9a50363
Compare
// TODO-PAYWALLS: uncomment after testing | ||
private val json = Json { | ||
// ignoreUnknownKeys = true | ||
} |
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.
I will refactor this and add it as a dependency in a followup PR. Also I think until we make sure all keys are there, we should not ignore unknown keys
internal val localization: Map<String, LocalizedConfiguration>, | ||
@SerialName("asset_base_url") @Serializable(with = URLSerializer::class) val assetBaseURL: URL, | ||
// TODO-PAYWALLS: do we need this one? | ||
@SerialName("default_locale") val defaultLocale: String, |
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.
iOS doesn't have this property, but it's returned in the JSON
cc @NachoSoto
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.
Hmm we should confirm with the team, but maybe we should make it optional in case it disappears?
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.
Let's see what they say I can fix in a follow up if needed
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.
Yeah this is no longer required and will be removed from the backend. It's only still there for backwards compatibility with Josh's app 😅
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.
Lol ok. I'll remove it then
@@ -86,5 +86,6 @@ internal val testOffering: Offering | |||
availablePackages = listOf( | |||
Package("package_id", PackageType.ANNUAL, storeProduct, "offering_id"), | |||
), | |||
paywall = null, |
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.
Tests will be in a followup PR so we can start building the view asap
data class PaywallData( | ||
/** | ||
* The type of template used to display this paywall. | ||
*/ | ||
val templateName: String, | ||
@SerialName("template_name") val templateName: String, |
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.
I was thinking most fields need to add this to support the snake_case to camelCase transformation and it would be good to do this automatically... But from a quick search, looks like there is JsonNamingStrategy but it's still experimental... So this might be the best for now...
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.
Yes! Thankfully it looks like they will add it soon
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.
LGTM!
internal val localization: Map<String, LocalizedConfiguration>, | ||
@SerialName("asset_base_url") @Serializable(with = URLSerializer::class) val assetBaseURL: URL, | ||
// TODO-PAYWALLS: do we need this one? | ||
@SerialName("default_locale") val defaultLocale: String, |
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.
Hmm we should confirm with the team, but maybe we should make it optional in case it disappears?
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.
Awesome 👏🏻 data driven FTW
@@ -47,28 +53,29 @@ data class PaywallData( | |||
/** | |||
* Whether the background image will be blurred (in templates with one). | |||
*/ | |||
val blurredBackgroundImage: Boolean = false, | |||
@SerialName("blurred_background_image") val blurredBackgroundImage: Boolean = false, |
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.
Does the serializer decode the default value if it's not present?
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.
Yes
|
||
/** | ||
* If set, the paywall will display a privacy policy link. | ||
*/ | ||
val privacyURL: URL? = null, | ||
@SerialName("privacy_url") @Serializable(with = URLSerializer::class) val privacyURL: URL? = null, |
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.
Does this ignore errors if the URL is invalid? Better for it to become null
than failing the decode the whole thing
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.
I haven't actually tested it. I'll check but I think it's going to crash. Good call
Tests will go in a followup PR