mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-10 22:45:55 +05:45
44 lines
1.6 KiB
Swift
44 lines
1.6 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
|
|
//
|
|
// IdentityAPI.swift
|
|
//
|
|
// Created by Joshua Liebowitz on 6/15/22.
|
|
|
|
import Foundation
|
|
|
|
class IdentityAPI {
|
|
|
|
typealias LogInResponseHandler = (Result<(info: CustomerInfo, created: Bool), BackendError>) -> Void
|
|
|
|
private let logInCallbacksCache: CallbackCache<LogInCallback>
|
|
private let backendConfig: BackendConfiguration
|
|
|
|
init(backendConfig: BackendConfiguration) {
|
|
self.backendConfig = backendConfig
|
|
self.logInCallbacksCache = CallbackCache<LogInCallback>(callbackQueue: backendConfig.callbackQueue)
|
|
}
|
|
|
|
func logIn(currentAppUserID: String,
|
|
newAppUserID: String,
|
|
completion: @escaping LogInResponseHandler) {
|
|
let config = NetworkOperation.UserSpecificConfiguration(httpClient: self.backendConfig.httpClient,
|
|
appUserID: currentAppUserID)
|
|
let loginOperation = LogInOperation(configuration: config,
|
|
newAppUserID: newAppUserID,
|
|
loginCallbackCache: self.logInCallbacksCache)
|
|
|
|
let loginCallback = LogInCallback(cacheKey: loginOperation.cacheKey, completion: completion)
|
|
let cacheStatus = self.logInCallbacksCache.add(callback: loginCallback)
|
|
|
|
self.backendConfig.operationQueue.addCacheableOperation(loginOperation, cacheStatus: cacheStatus)
|
|
}
|
|
|
|
}
|