Created
November 8, 2018 04:13
-
-
Save vialyx/951fc8a9f8f29ae8690a31025af17acc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import Foundation | |
// TODO: - Move to the separated file FlightData.swift | |
struct FlightData: Codable { | |
let Airline: String | |
let Flight: String | |
let ActualTime: String | |
} | |
final class Repository { | |
private let apiClient: APIClient! | |
init(apiClient: APIClient) { | |
self.apiClient = apiClient | |
} | |
func getFlights(_ completion: @escaping ((Result<[FlightData]>) -> Void)) { | |
let resource = Resource(url: URL(string: "https://desolate-beyond-86929.herokuapp.com/arrival")!) | |
apiClient.load(resource) { (result) in | |
switch result { | |
case .success(let data): | |
do { | |
let items = try JSONDecoder().decode([FlightData].self, from: data) | |
completion(.success(items)) | |
} catch { | |
completion(.failure(error)) | |
} | |
case .failure(let error): | |
completion(.failure(error)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment