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
| fileprivate func handleResponse(_ result: Result<NearEarthListCall.T, GenericError>) { | |
| stopLoading() | |
| switch result { | |
| case .success(_): | |
| do { | |
| try self.nearEarthListVM = result.get() | |
| } | |
| catch (let err) { | |
| print(err) /// popup or whatever you use !! beware of cancel ;) |
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
| fileprivate func handleResponse(_ result: Result<NearEarthListCall.T, GenericError>) { | |
| stopLoading() | |
| switch result { | |
| case .success(_): | |
| do { | |
| try self.nearEarthListVM = result.get() | |
| } | |
| catch (let err) { | |
| print(err) /// popup or whatever you use !! beware of cancel ;) |
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
| class NearEarthListService { | |
| static let shared = NearEarthListService() | |
| //restricted, yep singleton | |
| private init(){} | |
| /// lazy var & lazy me | |
| lazy var urlSession: URLSession = { |
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
| class NearEarthListCall : RestCall { | |
| var mimeTypeData: [MimeType]? = nil | |
| var httpMethod: HttpMethod = .GET | |
| var contentType: ContentType = .json | |
| var callRoot: CallRoot { | |
| return CallRoot(scheme: "https", |
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
| /// Execution | |
| extension RestCall { | |
| /** | |
| This method execute and return the task back, developper can use the task ref to cancel it, pause it, resume it back... | |
| - Remark: The result back to the user on main thread | |
| - Parameter session: **URLSession** the connection that will create the task that will be performed | |
| - Parameter completion: **Result** The result of the execution an enum <success, fail>. | |
| - Returns: The URLSessionDataTask to be executed |
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
| protocol RestCall { | |
| ///responseBodyType `T` must be `Codable` , it will be used when parsing and creating web service response from json | |
| associatedtype T: Codable | |
| ///callInterceptor `RestCallInterceptor` used to intercept the url request | |
| var callInterceptor : RestCallInterceptor { get } | |
| /// The call `method`, le swift : -"all, what are u ?" | |
| var httpMethod : HttpMethod { get } |
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
| struct MimeType { | |
| let filename: String | |
| let mimeType : String | |
| let data: Data | |
| } |
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
| enum ContentType: String { | |
| case json = "application/json" | |
| case multipart = "multipart/form-data" | |
| case urlencoded = "application/x-www-form-urlencoded" | |
| } |
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
| struct CallRoot { | |
| let scheme: String | |
| let host : String | |
| let path: String | |
| let queryItems: [URLQueryItem]? | |
| } |
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
| enum HttpMethod: String { | |
| case GET | |
| case POST | |
| case UPDATE | |
| case DELETE | |
| } |
NewerOlder