mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-09 22:35:56 +05:45
46 lines
1.5 KiB
Swift
46 lines
1.5 KiB
Swift
//
|
|
// Copyright RevenueCat Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the MIT License (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://opensource.org/licenses/MIT
|
|
//
|
|
// OfflineEntitlementsAPI.swift
|
|
//
|
|
// Created by Nacho Soto on 3/22/23.
|
|
|
|
import Foundation
|
|
|
|
class OfflineEntitlementsAPI {
|
|
|
|
typealias ProductEntitlementMappingResponseHandler = Backend.ResponseHandler<ProductEntitlementMappingResponse>
|
|
|
|
private let productEntitlementMappingCallbacksCache: CallbackCache<ProductEntitlementMappingCallback>
|
|
private let backendConfig: BackendConfiguration
|
|
|
|
init(backendConfig: BackendConfiguration) {
|
|
self.backendConfig = backendConfig
|
|
self.productEntitlementMappingCallbacksCache = .init()
|
|
}
|
|
|
|
func getProductEntitlementMapping(withRandomDelay randomDelay: Bool,
|
|
completion: @escaping ProductEntitlementMappingResponseHandler) {
|
|
let factory = GetProductEntitlementMappingOperation.createFactory(
|
|
configuration: self.backendConfig,
|
|
callbackCache: self.productEntitlementMappingCallbacksCache
|
|
)
|
|
|
|
let callback = ProductEntitlementMappingCallback(cacheKey: factory.cacheKey, completion: completion)
|
|
let cacheStatus = self.productEntitlementMappingCallbacksCache.add(callback)
|
|
|
|
self.backendConfig.addCacheableOperation(
|
|
with: factory,
|
|
withRandomDelay: randomDelay,
|
|
cacheStatus: cacheStatus
|
|
)
|
|
}
|
|
|
|
}
|