mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-10 22:45:55 +05:45
Initial step for [CSDK-17]. Fixes [CSDK-523]. ### Changes: - Renamed `ReceiptParser` to `PurchasesReceiptParser` to avoid name collision with future SPM `ReceiptParser` - Exposed `ReceiptParser`, `AppleReceipt`, `PurchasesReceiptParser.Error` - Added new types to `SwiftAPITester` - Added docs to these types - Moved `LoggerType` to be available to `ReceiptParser` - Moved `DateFormatter+Extensions` to be available to `ReceiptParser` - Moved `Codable+Extensions` to be available to `ReceiptParser` - Created `ReceiptParserLogger` for `ReceiptParser` [CSDK-17]: https://revenuecats.atlassian.net/browse/CSDK-17?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ [CSDK-523]: https://revenuecats.atlassian.net/browse/CSDK-523?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
66 lines
1.5 KiB
Swift
66 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
|
|
//
|
|
// Codable+Extensions.swift
|
|
//
|
|
// Created by Nacho Soto on 11/29/22.
|
|
|
|
import Foundation
|
|
|
|
extension Encodable {
|
|
|
|
/// - Throws: if encoding failed
|
|
/// - Returns: `nil` if the encoded `Data` can't be serialized into a `String`.
|
|
var prettyPrintedJSON: String? {
|
|
get throws {
|
|
return String(data: try self.prettyPrintedData, encoding: .utf8)
|
|
}
|
|
}
|
|
|
|
var prettyPrintedData: Data {
|
|
get throws {
|
|
return try JSONEncoder.prettyPrinted.encode(self)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension JSONEncoder {
|
|
|
|
static let `default`: JSONEncoder = {
|
|
let encoder = JSONEncoder()
|
|
encoder.keyEncodingStrategy = .convertToSnakeCase
|
|
encoder.dateEncodingStrategy = .iso8601
|
|
|
|
return encoder
|
|
}()
|
|
|
|
static let prettyPrinted: JSONEncoder = {
|
|
let encoder = JSONEncoder()
|
|
encoder.keyEncodingStrategy = .convertToSnakeCase
|
|
encoder.dateEncodingStrategy = .iso8601
|
|
encoder.outputFormatting = .prettyPrinted
|
|
|
|
return encoder
|
|
}()
|
|
|
|
}
|
|
|
|
extension JSONDecoder {
|
|
|
|
static let `default`: JSONDecoder = {
|
|
let decoder = JSONDecoder()
|
|
decoder.keyDecodingStrategy = .convertFromSnakeCase
|
|
decoder.dateDecodingStrategy = .iso8601
|
|
|
|
return decoder
|
|
}()
|
|
|
|
}
|