-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create DiagnosticsPostOperation (#3795)
Add DiagnosticsPostOperation and DiagnosticsAPI
- Loading branch information
Showing
12 changed files
with
419 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,41 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "CwlCatchException", | ||
"repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "3b123999de19bf04905bc1dfdb76f817b0f2cc00", | ||
"version": "2.1.2" | ||
} | ||
}, | ||
{ | ||
"package": "CwlPreconditionTesting", | ||
"repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "a23ded2c91df9156628a6996ab4f347526f17b6b", | ||
"version": "2.1.2" | ||
} | ||
}, | ||
{ | ||
"package": "Nimble", | ||
"repositoryURL": "[email protected]:Quick/Nimble.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "1f3bde57bde12f5e7b07909848c071e9b73d6edc", | ||
"version": "10.0.0" | ||
} | ||
}, | ||
{ | ||
"package": "swift-snapshot-testing", | ||
"repositoryURL": "[email protected]:pointfreeco/swift-snapshot-testing.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "dc46eeb3928a75390651fac6c1ef7f93ad59a73b", | ||
"version": "1.11.1" | ||
} | ||
"pins" : [ | ||
{ | ||
"identity" : "cwlcatchexception", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/mattgallagher/CwlCatchException.git", | ||
"state" : { | ||
"revision" : "3b123999de19bf04905bc1dfdb76f817b0f2cc00", | ||
"version" : "2.1.2" | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
}, | ||
{ | ||
"identity" : "cwlpreconditiontesting", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git", | ||
"state" : { | ||
"revision" : "a23ded2c91df9156628a6996ab4f347526f17b6b", | ||
"version" : "2.1.2" | ||
} | ||
}, | ||
{ | ||
"identity" : "nimble", | ||
"kind" : "remoteSourceControl", | ||
"location" : "[email protected]:Quick/Nimble.git", | ||
"state" : { | ||
"revision" : "1f3bde57bde12f5e7b07909848c071e9b73d6edc", | ||
"version" : "10.0.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-snapshot-testing", | ||
"kind" : "remoteSourceControl", | ||
"location" : "[email protected]:pointfreeco/swift-snapshot-testing.git", | ||
"state" : { | ||
"revision" : "26ed3a2b4a2df47917ca9b790a57f91285b923fb", | ||
"version" : "1.12.0" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
71 changes: 71 additions & 0 deletions
71
Sources/Diagnostics/Networking/DiagnosticsEventsRequest.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// 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 | ||
// | ||
// DiagnosticsEventsRequest.swift | ||
// | ||
// Created by Cesar de la Vega on 11/4/24. | ||
|
||
import Foundation | ||
|
||
/// The content of a request to the events endpoints. | ||
struct DiagnosticsEventsRequest { | ||
|
||
var entries: [Event] | ||
|
||
init(events: [Event]) { | ||
self.entries = events | ||
} | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
init(events: [DiagnosticsEvent]) { | ||
self.init(events: events.map { .init(event: $0) }) | ||
} | ||
|
||
} | ||
|
||
extension DiagnosticsEventsRequest { | ||
|
||
struct Event { | ||
|
||
let version: Int | ||
let name: String | ||
let properties: [String: AnyEncodable] | ||
let timestamp: String | ||
|
||
} | ||
|
||
} | ||
|
||
extension DiagnosticsEventsRequest.Event { | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) | ||
init(event: DiagnosticsEvent) { | ||
self.init( | ||
version: event.version, | ||
name: event.name, | ||
properties: event.properties, | ||
timestamp: event.timestamp.ISO8601Format() | ||
) | ||
} | ||
|
||
} | ||
|
||
// MARK: - Codable | ||
|
||
extension DiagnosticsEventsRequest.Event: Encodable { | ||
|
||
enum CodingKeys: String, CodingKey { | ||
|
||
case version, name, properties, timestamp | ||
|
||
} | ||
|
||
} | ||
|
||
extension DiagnosticsEventsRequest: HTTPRequestBody {} |
46 changes: 46 additions & 0 deletions
46
Sources/Diagnostics/Networking/DiagnosticsPostOperation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// 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 | ||
// | ||
// DiagnosticsPostOperation.swift | ||
// | ||
// Created by Cesar de la Vega on 8/4/24. | ||
|
||
import Foundation | ||
|
||
final class DiagnosticsPostOperation: NetworkOperation { | ||
|
||
private let configuration: Configuration | ||
private let request: DiagnosticsEventsRequest | ||
private let responseHandler: CustomerAPI.SimpleResponseHandler? | ||
|
||
init( | ||
configuration: Configuration, | ||
request: DiagnosticsEventsRequest, | ||
responseHandler: CustomerAPI.SimpleResponseHandler? | ||
) { | ||
self.configuration = configuration | ||
self.request = request | ||
self.responseHandler = responseHandler | ||
|
||
super.init(configuration: configuration) | ||
} | ||
|
||
override func begin(completion: @escaping () -> Void) { | ||
let request = HTTPRequest(method: .post(self.request), path: .postDiagnostics) | ||
|
||
self.httpClient.perform(request) { (response: VerifiedHTTPResponse<HTTPEmptyResponseBody>.Result) in | ||
defer { | ||
completion() | ||
} | ||
|
||
self.responseHandler?(response.error.map(BackendError.networkError)) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.