mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
### Purpose: This is a prerequisite for #2288. The new grace period means that if we didn't update the date from the cached responses, entitlements would become stale and expired after 3 days. ### Changes: - Added `HTTPResponseBody.copy(with newRequestDate:)` to be able to modify responses from the header request date - `CustomerInfo` implements this method to modify its request date - Added `HTTPResponse.requestDate` to be able to keep track of the request date from the server - Added `VerificationResult.from(cache:response:)` to determine the most restrictive verification result based on what's cached or checked from a response - Added `HTTPResponse.copy(with:)` to modify the verification result of a response using the previous method - `HTTPClient` now uses the most restrictive verification result - `HTTPClient` updates request date from server responses or cached responses (unless verification failed). This was the missing piece for #2288. ### Tests: - Verify that `ETagManager` does not use an ETag if verification was previously not enabled - Verify that `ETagManager` returns the request date from the server when returning a cached response - Verify that `HTTPClient` updates the request date from the server or from a cached response - Verify that `HTTPClient` does not update request date if verification failed - Tests for `HTTPResponse` request date parsing - Test for `CustomerInfoResponseHandler` updating request date - Tests for `CustomerInfo.copy(with newRequestDate:)` ### Other smaller changes: - Moved `CustomerInfo.asData()` into `Encodable.asJSONEncodedData()` - Renamed `requestTime` to `requestDate` everywhere for consistency
40 lines
868 B
Swift
40 lines
868 B
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
|
|
//
|
|
// Date+Extensions.swift
|
|
//
|
|
// Created by Josh Holtz on 6/28/21.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension NSDate {
|
|
|
|
func millisecondsSince1970AsUInt64() -> UInt64 {
|
|
return (self as Date).millisecondsSince1970AsUInt64()
|
|
}
|
|
|
|
}
|
|
|
|
extension Date {
|
|
|
|
init(millisecondsSince1970: Int) {
|
|
self.init(timeIntervalSince1970: TimeInterval(millisecondsSince1970) / 1000)
|
|
}
|
|
|
|
var millisecondsSince1970: Int {
|
|
return Int(self.timeIntervalSince1970 * 1000.0)
|
|
}
|
|
|
|
func millisecondsSince1970AsUInt64() -> UInt64 {
|
|
return UInt64(self.millisecondsSince1970)
|
|
}
|
|
|
|
}
|