Skip to content
Snippets Groups Projects
Commit 7809f80a authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Add SendReport functor

parent d47c9e47
No related branches found
No related tags found
3 merge requests!71Releasing v1.1.5 (214),!69Implemented filtering for banned/blocked users and reporting,!67v1.1.5 b(203)
import Foundation
import XCTestDynamicOverlay
public struct SendReport {
public typealias Completion = (Result<Void, Error>) -> Void
public var run: (Report, @escaping Completion) -> Void
public func callAsFunction(_ report: Report, completion: @escaping Completion) {
run(report, completion)
}
}
extension SendReport {
public static let live = SendReport { report, completion in
let url = URL(string: "https://3.74.237.181:11420/report")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
do {
request.httpBody = try JSONEncoder().encode(report)
} catch {
completion(.failure(error))
return
}
let session = URLSession(configuration: .default)
let task = session.dataTask(with: request) { data, response, error in
if let error = error {
completion(.failure(error))
return
}
completion(.success(()))
}
task.resume()
}
}
extension SendReport {
public static let unimplemented = SendReport(
run: XCTUnimplemented("\(Self.self)")
)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment