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

Add FetchBannedList functor

parent 8ced6ec0
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 FetchBannedList {
public enum Error: Swift.Error, Equatable {
case network(URLError)
case invalidResponse
}
public typealias Completion = (Result<Data, Error>) -> Void
public var run: (@escaping Completion) -> Void
public func callAsFunction(completion: @escaping Completion) {
run(completion)
}
}
extension FetchBannedList {
public static let live = FetchBannedList { completion in
let url = URL(string: "https://elixxir-bins.s3.us-west-1.amazonaws.com/client/bannedUsers/bannedTesting.csv")!
let session = URLSession.shared
let task = session.dataTask(with: url) { data, response, error in
if let error = error {
completion(.failure(.network(error as! URLError)))
return
}
guard let response = response as? HTTPURLResponse,
(200..<300).contains(response.statusCode),
let data = data
else {
completion(.failure(.invalidResponse))
return
}
completion(.success(data))
}
task.resume()
}
}
extension FetchBannedList {
public static let unimplemented = FetchBannedList(
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