Skip to content

Add await offerings#1096

Merged
vegaro merged 10 commits into
mainfrom
cesar/sdk-3135-coroutine-function-getOfferings
Jul 3, 2023
Merged

Add await offerings#1096
vegaro merged 10 commits into
mainfrom
cesar/sdk-3135-coroutine-function-getOfferings

Conversation

@vegaro

@vegaro vegaro commented Jun 26, 2023

Copy link
Copy Markdown
Member

Added experimental awaitOfferings to the API

@vegaro vegaro requested a review from a team June 26, 2023 15:03
@vegaro vegaro added the pr:feat A new feature label Jun 26, 2023
@codecov

codecov Bot commented Jun 26, 2023

Copy link
Copy Markdown

Codecov Report

Merging #1096 (2028c2a) into main (eb547e3) will decrease coverage by 0.01%.
The diff coverage is 80.00%.

@@            Coverage Diff             @@
##             main    #1096      +/-   ##
==========================================
- Coverage   85.88%   85.88%   -0.01%     
==========================================
  Files         179      179              
  Lines        6364     6369       +5     
  Branches      876      877       +1     
==========================================
+ Hits         5466     5470       +4     
  Misses        556      556              
- Partials      342      343       +1     
Impacted Files Coverage Δ
...n/com/revenuecat/purchases/coroutinesExtensions.kt 83.33% <80.00%> (-2.39%) ⬇️

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Left some comments. Nothing really blocking though

Comment thread purchases/src/main/kotlin/com/revenuecat/purchases/coroutinesExtensions.kt Outdated
* Only available in Kotlin.
*
* @throws [PurchasesException] with a [PurchasesError] if there's an error retrieving the offerings.
* @return [Result] type containing either the [Offerings] or the [PurchasesError]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It won't return a [Result] though right? We removed that in the end?

var result: Offerings? = null
var exception: Throwable? = null
runCatching {
result = purchases.awaitOfferings()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Alternatively, we could add a fail after this line... I kinda prefer it since result is unused here. Thoughts?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The only problem with using fail is that the catch will catch the fail and store it as an exception. So this test will fail checking the type of the exception, not because the fail throws an exception

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ohhh yeah, that makes sense... I guess ideally we would only catch the type of exception we are expecting, so others would just make it fail the test as well... But I'm not sure how that would look like here. This is ok then!

mockOfferingsManager.getOfferings(appUserId, appInBackground = false, any(), any())
} answers {
if (errorGettingOfferings == null) {
val callback = arg<(Offerings) -> Unit>(3)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've become kinda against these ordered parameters... If you changed the parameters, it fails at runtime with a somewhat cryptic message. I would prefer to use slots. Thoughts?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ok! yeah, I saw this somewhere else and copied it haha. I will change it to use slots

* @warning This function is marked as [ExperimentalPreviewRevenueCatPurchasesAPI] and may change in the future.
* Only available in Kotlin.
*
* @throws [PurchasesException] with a [PurchasesError] if there's an error retrieving the offerings.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does Kotlin allow specifying which exception is thrown just like Java does?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can add an @throws annotation though. It won't specify the type but will give a small warning I think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added a @Throws(PurchasesException::class)

Comment on lines +55 to +58
getOfferingsWith(
onSuccess = continuation::resume,
onError = { continuation.resumeWithException(PurchasesException(it)) },
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I love how simple this is, just like in Swift :D

val customerInfoFetchPolicy: CustomerInfo =
purchases.awaitCustomerInfo(fetchPolicy = CacheFetchPolicy.FETCH_CURRENT)

val offerings: Offerings = purchases.awaitOfferings()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It’s weird that this doesn’t need a catch. Is it a RuntimeException?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's not RuntimeException. Kotlin doesn't have checked exceptions, that's why there's no need to catch here. Take a look at this https://kotlinlang.org/docs/exceptions.html#checked-exceptions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh yikes. Okay 🫤

*/
@JvmSynthetic
@ExperimentalPreviewRevenueCatPurchasesAPI
@Throws(PurchasesException::class)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍🏻

)
}
assertThat(result).isNull()
assertThat(exception).isNotNull

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it possible to check the exact exception?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the next test checks for that, I can consolidate them into one test? Or you think it's better to keep them separate

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I’d combine them if that’s the only difference.

@vegaro vegaro requested review from NachoSoto and tonidero June 27, 2023 12:20

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great!

@NachoSoto

Copy link
Copy Markdown
Contributor

This looks great!

@vegaro vegaro merged commit 046add4 into main Jul 3, 2023
@vegaro vegaro deleted the cesar/sdk-3135-coroutine-function-getOfferings branch July 3, 2023 10:22
tonidero added a commit that referenced this pull request Jul 12, 2023
**This is an automatic release.**

### New Features
* `Trusted Entitlements`: made API stable (#1105) via NachoSoto
(@NachoSoto)

This new feature prevents MitM attacks between the SDK and the
RevenueCat server.
With verification enabled, the SDK ensures that the response created by
the server was not modified by a third-party, and the entitlements
received are exactly what was sent.
This is 100% opt-in. `EntitlementInfos` have a new `VerificationResult`
property, which will indicate the validity of the responses when this
feature is enabled.

```kotlin
fun configureRevenueCat() {
    val configuration = PurchasesConfiguration.Builder(context, apiKey)
        .entitlementVerificationMode(EntitlementVerificationMode.INFORMATIONAL)
        .build()
    Purchases.configure(configuration)
}
```
### Experimental features
* Add await offerings (#1096) via Cesar de la Vega (@vegaro)
### Bugfixes
* Fix issue updating customer info on app open (#1128) via Toni Rico
(@tonidero)
### Dependency Updates
* Bump fastlane-plugin-revenuecat_internal from `13773d2` to `b2108fb`
(#1095) via dependabot[bot] (@dependabot[bot])
### Other Changes
* [PurchaseTester] Add option to purchase an arbitrary product id
(#1099) via Mark Villacampa (@MarkVillacampa)
* Fix release path after module refactor (#1129) via Toni Rico
(@tonidero)
* Fix load shedder integration tests (#1125) via Toni Rico (@tonidero)
* Trusted entitlements: New trusted entitlements signature format
(#1117) via Toni Rico (@tonidero)
* Fix integration tests and change to a different project (#1123) via
Toni Rico (@tonidero)
* Move files into src/main/kotlin (#1122) via Cesar de la Vega (@vegaro)
* Remove public module (#1113) via Cesar de la Vega (@vegaro)
* Remove common module (#1106) via Cesar de la Vega (@vegaro)
* Fix flaky integration tests: Wait for coroutines to finish before
continuing (#1120) via Toni Rico (@tonidero)
* Move amazon module into purchases (#1112) via Cesar de la Vega
(@vegaro)
* Trusted entitlements: Add IntermediateSignatureHelper to handle
intermediate signature verification process (#1110) via Toni Rico
(@tonidero)
* Trusted entitlements: Add Signature type to process new signature
response format (#1109) via Toni Rico (@tonidero)
* [EXTERNAL] Add `awaitCustomerInfo` / coroutines tests to
`TrustedEntitlementsInformationalModeIntegrationTest` (#1077) via
@pablo-guardiola (#1107) via Toni Rico (@tonidero)
* Remove feature:google module (#1104) via Cesar de la Vega (@vegaro)
* Remove identity module (#1103) via Cesar de la Vega (@vegaro)
* Remove subscriber attributes module (#1102) via Cesar de la Vega
(@vegaro)
* Delete utils module (#1098) via Cesar de la Vega (@vegaro)
* Remove strings module (#1097) via Cesar de la Vega (@vegaro)
* Update CHANGELOG.md to include external contribution (#1100) via Cesar
de la Vega (@vegaro)
* [EXTERNAL] Add missing `fetchPolicy` parameter to `awaitCustomerInfo`
API (#1086) via @pablo-guardiola (#1090) via Toni Rico (@tonidero)

---------

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Co-authored-by: Toni Rico <antonio.rico.diez@revenuecat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:feat A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants