-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added APIEndpoint inheritance to all network classes * working implementation * working adapter * Updated JSONSerializable & added generic update() method * More update refactoring * Added generic delete request * Added create() method * Create comment reworked * Added views create() method * minor * refactored create() for attempts and submissions * Added retrieve() for one object by id * Added retrieve with parameters * minor * Added retrieve() with fetch to NotificationsAPI * minor * Refactored UnitsAPI * multiple fixes * Refactored UserActivitiesAPI * Refactor DiscussionProxiesAPI * Refactored getObjectsByIds * Refactored CommentsAPI * Added deprecations to CommentsAPI * Added default implementation of async fetch using DatabaseFetchService * fixed GET requests & added deprecations to CoursesAPI * Refactored CertificatesAPI * Refactored CourseListsAPI * Refactored NotificationsStatusesAPI * fixed formatting * Removed some checkToken() calls * Fixed JSONSerializables * AsyncFetchService -> DatabaseFetchService * Cleaned up UserActivitiesAPI * minor format * fixed force unwrap * Removed forced unwraps * Renamed IdType & some more * Added CoreDataRepresentable protocol for IdType of IDFetchable * fixed "Submit" localization * Deleted not passing tests file * minor
- Loading branch information
Showing
79 changed files
with
1,136 additions
and
1,293 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// ApiRequestRetrier.swift | ||
// Stepic | ||
// | ||
// Created by Ostrenkiy on 18.03.2018. | ||
// Copyright © 2018 Alex Karpov. All rights reserved. | ||
// | ||
import Foundation | ||
import Alamofire | ||
import PromiseKit | ||
|
||
class ApiRequestRetrier: RequestRetrier, RequestAdapter { | ||
|
||
func adapt(_ urlRequest: URLRequest) throws -> URLRequest { | ||
var urlRequest = urlRequest | ||
for (headerField, value) in AuthInfo.shared.initialHTTPHeaders { | ||
urlRequest.setValue(value, forHTTPHeaderField: headerField) | ||
} | ||
return urlRequest | ||
} | ||
|
||
func should(_ manager: SessionManager, retry request: Request, with error: Error, completion: @escaping RequestRetryCompletion) { | ||
if let response = request.task?.response as? HTTPURLResponse, response.statusCode == 401 && request.retryCount == 0 { | ||
checkToken().then { | ||
completion(true, 0.0) | ||
}.catch { | ||
_ in | ||
completion(false, 0.0) | ||
} | ||
} else { | ||
completion(false, 0.0) | ||
} | ||
} | ||
} |
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
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.