mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-10 22:45:55 +05:45
* [CF-106] Fetch AdServices Token (#1519) Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com> Co-authored-by: Josh Holtz <me@joshholtz.com> * [CF-553] Post AdServices token (#1534) Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com> Co-authored-by: Josh Holtz <me@joshholtz.com> * Update ios 14 snapshots tets * Reworked adservices to use new Purchases.shared.attribution API * Updated with some comments from PR * Add iAd code back (#1739) Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com> * use new mapKeys dictionary extension for device cache * update for some pr comments * remove purchasestests * generate missing snapshots * fix deprecation messages to clarify method now called on shared instance * Fix for inserting nonstring into userdefaults * Add tests for bug * fix lint * Added availablility checks for tests and removed unused varialbes * Whoops... wrong class Co-authored-by: beylmk <maddie@revenuecat.com> Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
70 lines
1.9 KiB
Swift
70 lines
1.9 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
|
|
//
|
|
// PostAdServicesTokenOperation.swift
|
|
//
|
|
// Created by Madeline Beyl on 4/20/22.
|
|
|
|
import Foundation
|
|
|
|
class PostAdServicesTokenOperation: NetworkOperation {
|
|
|
|
private let configuration: UserSpecificConfiguration
|
|
private let token: String
|
|
private let responseHandler: CustomerAPI.SimpleResponseHandler?
|
|
|
|
init(configuration: UserSpecificConfiguration,
|
|
token: String,
|
|
responseHandler: CustomerAPI.SimpleResponseHandler?) {
|
|
self.token = token
|
|
self.configuration = configuration
|
|
self.responseHandler = responseHandler
|
|
|
|
super.init(configuration: configuration)
|
|
}
|
|
|
|
override func begin(completion: @escaping () -> Void) {
|
|
self.post(completion: completion)
|
|
}
|
|
|
|
private func post(completion: @escaping () -> Void) {
|
|
guard let appUserID = try? self.configuration.appUserID.escapedOrError() else {
|
|
self.responseHandler?(.missingAppUserID())
|
|
completion()
|
|
return
|
|
}
|
|
|
|
let request = HTTPRequest(method: .post(Body(aadAttributionToken: self.token)),
|
|
path: .postAdServicesToken(appUserID: appUserID))
|
|
|
|
self.httpClient.perform(request) { (response: HTTPResponse<HTTPEmptyResponseBody>.Result) in
|
|
defer {
|
|
completion()
|
|
}
|
|
|
|
self.responseHandler?(response.error.map(BackendError.networkError))
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private extension PostAdServicesTokenOperation {
|
|
|
|
struct Body: Encodable {
|
|
|
|
let aadAttributionToken: String
|
|
|
|
init(aadAttributionToken: String) {
|
|
self.aadAttributionToken = aadAttributionToken
|
|
}
|
|
|
|
}
|
|
|
|
}
|