Skip to content

Commit

Permalink
Unify caching offerings and updating update timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
tonidero committed Aug 23, 2023
1 parent fcf8b2e commit 9550a4d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.revenuecat.sample

import android.app.Application
import android.util.Log
import com.revenuecat.purchases.LogLevel
import com.revenuecat.purchases.Purchases
import com.revenuecat.purchases.PurchasesConfiguration
import com.revenuecat.purchases.amazon.AmazonConfiguration
import com.revenuecat.purchases.getCustomerInfoWith
import com.revenuecat.purchases.getOfferingsWith
import com.revenuecat.sample.data.Constants

class MainApplication : Application() {
Expand All @@ -15,7 +18,7 @@ class MainApplication : Application() {
/*
Enable debug logs before calling `configure`.
*/
Purchases.logLevel = LogLevel.DEBUG
Purchases.logLevel = LogLevel.VERBOSE

/*
Initialize the RevenueCat Purchases SDK.
Expand All @@ -35,5 +38,21 @@ class MainApplication : Application() {
.diagnosticsEnabled(true)
.build(),
)
Purchases.sharedInstance.getCustomerInfoWith(
onError = {
Log.e("TEST", "TEST ERROR GETTING CUSTOMER INFO: $it")
},
onSuccess = {
Log.e("TEST", "TEST SUCCESS GETTING CUSTOMER INFO")
},
)
Purchases.sharedInstance.getOfferingsWith(
onError = {
Log.e("TEST", "TEST ERROR GETTING OFFERINGS: $it")
},
onSuccess = {
Log.e("TEST", "TEST SUCCESS GETTING OFFERINGS")
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object Constants {
Modify this property to reflect your Google Play app's API key.
*/
const val GOOGLE_API_KEY = "googl_api_key"
const val GOOGLE_API_KEY = "goog_cRtaFpfwfcQYPXkIEqFUkVszUfN"

/*
The API key for your Amazon App Store app. This can be found in via Project Settings >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal class OfferingsCache(
fun cacheOfferings(offerings: Offerings, offeringsResponse: JSONObject) {
offeringsCachedObject.cacheInstance(offerings)
deviceCache.cacheOfferingsResponse(offeringsResponse)
offeringsCachedObject.updateCacheTimestamp(dateProvider.now)
}

// region Offerings cache
Expand All @@ -44,11 +45,6 @@ internal class OfferingsCache(
offeringsCachedObject.clearCacheTimestamp()
}

@Synchronized
fun setOfferingsCacheTimestampToNow() {
offeringsCachedObject.updateCacheTimestamp(dateProvider.now)
}

// endregion Offerings cache

// region Offerings response cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ internal class OfferingsManager(
},
onSuccess = { offerings ->
offeringsCache.cacheOfferings(offerings, offeringsJSON)
offeringsCache.setOfferingsCacheTimestampToNow()
dispatch {
onSuccess?.invoke(offerings)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ class OfferingsManagerTest {
)

verify(exactly = 1) {
cache.setOfferingsCacheTimestampToNow()
cache.cacheOfferings(offerings, any())
}
assertThat(offeringsReceived).isTrue
}
Expand Down Expand Up @@ -458,7 +458,7 @@ class OfferingsManagerTest {
)

verify(exactly = 0) {
cache.setOfferingsCacheTimestampToNow()
cache.cacheOfferings(any(), any())
}
assertThat(errorReceived).isTrue
}
Expand Down Expand Up @@ -515,7 +515,6 @@ class OfferingsManagerTest {
}

private fun mockDeviceCache(wasSuccessful: Boolean = true) {
every { cache.setOfferingsCacheTimestampToNow() } just Runs
if (wasSuccessful) {
every { cache.cacheOfferings(any(), any()) } just Runs
} else {
Expand Down

0 comments on commit 9550a4d

Please sign in to comment.