Skip to content

New syncAttributesAndOfferingsIfNeeded method#3709

Merged
joshdholtz merged 8 commits into
mainfrom
lauren/fia-2946-add-syncattributesandofferingsifneeded-to-the-sdk
Feb 28, 2024
Merged

New syncAttributesAndOfferingsIfNeeded method#3709
joshdholtz merged 8 commits into
mainfrom
lauren/fia-2946-add-syncattributesandofferingsifneeded-to-the-sdk

Conversation

@lburdock

@lburdock lburdock commented Feb 22, 2024

Copy link
Copy Markdown
Contributor

Motivation

Adding new method to manually sync attributes and fetch fresh offerings

Description

  • New Purchases.shared.syncAttributesAndOfferingsIfNeeded() method
    • Syncs subscriber attributes and then fetches fresh offerings from network
    • This is designed to be a blocking call since developer will want fresh offerings after syncing subscriber attributes
    • The method is rate limited to 5 calls per minute (new RateLimiter class()

@joshdholtz joshdholtz force-pushed the lauren/fia-2946-add-syncattributesandofferingsifneeded-to-the-sdk branch from 4d9ddbf to be9b2c8 Compare February 23, 2024 17:14
@joshdholtz joshdholtz changed the base branch from 5.0-dev to new-presented-offering-context February 23, 2024 17:15
@joshdholtz joshdholtz force-pushed the lauren/fia-2946-add-syncattributesandofferingsifneeded-to-the-sdk branch from be9b2c8 to e784198 Compare February 23, 2024 17:18
@joshdholtz joshdholtz added the pr:feat A new feature label Feb 23, 2024
@joshdholtz joshdholtz changed the title Add syncAttributesAndOfferingsIfNeeded function New syncAttributesAndOfferingsIfNeeded method Feb 27, 2024
@joshdholtz joshdholtz requested review from a team and removed request for a team February 28, 2024 04:43
@joshdholtz joshdholtz marked this pull request as ready for review February 28, 2024 04:43

@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, but nothing blocking

Comment thread Sources/Purchasing/OfferingsManager.swift
Comment thread Sources/Misc/RateLimiter.swift Outdated

func shouldProceed() -> Bool {
let now = Date()
timestamps = timestamps.filter { now.timeIntervalSince($0) <= period }

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 I kinda liked the approach in android since it avoided this loop every time we check this... But it shouldn't take long at all, so I'm ok with this.

return try await logOutAsync()
}

@objc func syncAttributesAndOfferingsIfNeeded(completion: @escaping (Offerings?, PublicError?) -> Void) {

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.

Hmm I've been thinking whether it would be worth moving the logic inside this method to the PurchasesOrchestrator (mostly for organization purposes)... However, seems that the getOfferings method already was not moved there, so I'm ok with this for now.

}

func shouldProceed() -> Bool {
let now = Date()

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.

Since we are getting the current time here, it makes it more difficult to mock the values... Should we inject a provider-type class in the constructor of the limiter? That would avoid the sleep in the tests.

Base automatically changed from new-presented-offering-context to main February 28, 2024 19:53
@joshdholtz joshdholtz force-pushed the lauren/fia-2946-add-syncattributesandofferingsifneeded-to-the-sdk branch from 54b7431 to f4679c4 Compare February 28, 2024 21:25
@joshdholtz joshdholtz merged commit ff68b8a into main Feb 28, 2024
@joshdholtz joshdholtz deleted the lauren/fia-2946-add-syncattributesandofferingsifneeded-to-the-sdk branch February 28, 2024 22:13
joshdholtz added a commit that referenced this pull request Mar 5, 2024
**This is an automatic release.**

### New Features
* Paywalls: add `updateWithDisplayCloseButton` to
`PaywallViewController` (#3708) via Cesar de la Vega (@vegaro)
* New `syncAttributesAndOfferingsIfNeeded` method (#3709) via Burdock
(@lburdock)
* Add targeting to `PresentedOfferingContext` (#3730) via Josh Holtz
(@joshdholtz)
* Add `currentOffering(forPlacement: String)` to `Offerings` (#3707) via
Guido Torres (@guido732)
* New `Package.presentedOfferingContext` (#3712) via Josh Holtz
(@joshdholtz)
### Bugfixes
* Mark methods with StaticString for appUserID as deprecated (#3739) via
Mark Villacampa (@MarkVillacampa)
### Other Changes
* [EXTERNAL] Spelling typo fix to comment (#3713) via @vdeaugustine
(#3740) via Mark Villacampa (@MarkVillacampa)

---------

Co-authored-by: Josh Holtz <me@joshholtz.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