NetworkServiceImpl
class NetworkServiceImpl : NetworkService
extension NetworkServiceImpl: OfflineRequestManagerDelegate
Production implementation of NetworkService
-
Direct accessor for connection status
Declaration
Swift
var isConnected: Bool { get }
-
Direct accessor for queued requests
Declaration
Swift
var requests: [OfflineRequest] { get }
-
Direct accessor for network controller
Declaration
Swift
let mtp: MTPNetworkController
-
Construction by injection
Declaration
Swift
init(controller: MTPNetworkController = MTPNetworkController())
Parameters
controller
MTPNetworkController
-
Send contact form
Declaration
Swift
func contact(payload: ContactPayload, then: @escaping NetworkCompletion<String>)
Parameters
payload
Contact payload
then
Completion
-
Load location photos
Declaration
Swift
func loadPhotos(location id: Int, reload: Bool, then: @escaping NetworkCompletion<PhotosInfoJSON>)
Parameters
id
Location ID
reload
Force reload
then
Completion
-
Load logged in user photos
Declaration
Swift
func loadPhotos(page: Int, reload: Bool, then: @escaping NetworkCompletion<PhotosPageInfoJSON>)
Parameters
page
Index
reload
Force reload
then
Completion
-
Load user photos
Declaration
Swift
func loadPhotos(profile id: Int, page: Int, reload: Bool, then: @escaping NetworkCompletion<PhotosPageInfoJSON>)
Parameters
id
User ID
page
Index
reload
Force reload
then
Completion
-
Load location posts
Declaration
Swift
func loadPosts(location id: Int, reload: Bool, then: @escaping NetworkCompletion<PostsJSON>)
Parameters
id
Location ID
reload
Force reload
then
Completion
-
Load user posts
Declaration
Swift
func loadPosts(user id: Int, reload: Bool, then: @escaping NetworkCompletion<PostsJSON>)
Parameters
id
User ID
reload
Force reload
then
Completion
-
Load rankings
Declaration
Swift
func loadRankings(query: RankingsQuery, then: @escaping NetworkCompletion<RankingsPageInfoJSON>)
Parameters
query
Filter
then
Completion
-
Load scorecard
Declaration
Swift
func loadScorecard(list: Checklist, user id: Int, then: @escaping NetworkCompletion<ScorecardJSON>)
Parameters
list
Checklist
id
User ID
then
Completion
-
Load user
Declaration
Swift
func loadUser(id: Int, then: @escaping NetworkCompletion<UserJSON>)
Parameters
id
User ID
then
Completion
-
Search
Declaration
Swift
func search(query: String, then: @escaping NetworkCompletion<SearchResultJSON>)
Parameters
query
Query
then
Completion
-
Set places visit status
Declaration
Swift
func set(items: [Checklist.Item], visited: Bool, then: @escaping NetworkCompletion<Bool>)
Parameters
items
Places
visited
Whether visited
then
Completion
-
Upload photo
Declaration
Swift
func upload(photo: Data, caption: String?, location id: Int?, then: @escaping NetworkCompletion<PhotoReply>)
Parameters
photo
Data
caption
String
id
Location ID if any
then
Completion
-
Update photo
Declaration
Swift
func photoUpdate(payload: PhotoUpdatePayload, then: @escaping NetworkCompletion<Bool>)
Parameters
payload
UserUpdatePayload
then
Completion
-
Delete photo
Declaration
Swift
func delete(photo: Int, then: @escaping NetworkCompletion<Bool>)
Parameters
photo
Int
then
Completion
-
Publish post
Declaration
Swift
func postPublish(payload: PostPayload, then: @escaping NetworkCompletion<PostReply>)
Parameters
payload
Post payload
then
Completion
-
Update post
Declaration
Swift
func postUpdate(payload: PostUpdatePayload, then: @escaping NetworkCompletion<Bool>)
Parameters
payload
PostUpdatePayload
then
Completion
-
Delete post
Declaration
Swift
func delete(post: Int, then: @escaping NetworkCompletion<Bool>)
Parameters
oist
Int
then
Completion
-
Delete user account
Declaration
Swift
func userDeleteAccount(then: @escaping NetworkCompletion<String>)
Parameters
then
Completion
-
Send reset password link
Declaration
Swift
func userForgotPassword(email: String, then: @escaping NetworkCompletion<String>)
Parameters
email
Email
then
Completion
-
Login user
Declaration
Swift
func userLogin(email: String, password: String, then: @escaping NetworkCompletion<UserJSON>)
Parameters
email
Email
password
Password
then
Completion
-
Register new user
Declaration
Swift
func userRegister(payload: RegistrationPayload, then: @escaping NetworkCompletion<UserJSON>)
Parameters
payload
RegistrationPayload
then
Completion
-
Update user info
Declaration
Swift
func userUpdate(payload: UserUpdatePayload, then: @escaping NetworkCompletion<UserJSON>)
Parameters
payload
UserUpdatePayload
then
Completion
-
Update user token
Declaration
Swift
func userUpdate(token: String, then: @escaping NetworkCompletion<UserTokenReply>)
Parameters
token
String
then
Completion
-
Resend verification email
Declaration
Swift
func userVerify(id: Int, then: @escaping NetworkCompletion<String>)
Parameters
id
User ID
then
Completion
-
Refresh first page of each list’s rankings
Declaration
Swift
func refreshRankings()
-
Refresh everything
Declaration
Swift
func refreshEverything()
-
Reset all networking
Declaration
Swift
func logout()
-
Method that the delegate uses to generate OfflineRequest objects from dictionaries written to disk
Declaration
Swift
func offlineRequest(withDictionary dictionary: [String : Any]) -> OfflineRequest?
Parameters
dictionary
dictionary saved to disk associated with an unfinished request
Return Value
OfflineRequest object to be queued
-
Callback indicating the OfflineRequestManager’s current progress
Declaration
Swift
func offlineRequestManager(_ manager: OfflineRequestManager, didUpdateProgress progress: Double)
Parameters
manager
OfflineRequestManager instance
progress
current progress for all ongoing requests (ranges from 0 to 1)
-
Callback indicating the OfflineRequestManager’s current connection status
Declaration
Swift
func offlineRequestManager(_ manager: OfflineRequestManager, didUpdateConnectionStatus connected: Bool)
Parameters
manager
OfflineRequestManager instance
connected
value indicating whether there is currently connectivity
-
Callback that can be used to block a request attempt
- manager: OfflineRequestManager instance
- request: OfflineRequest to be performed
Declaration
Swift
func offlineRequestManager(_ manager: OfflineRequestManager, shouldAttemptRequest request: OfflineRequest) -> Bool
Return Value
value indicating whether the OfflineRequestManager should move forward with the request attempt
-
Callback to reconfigure and reattempt an OfflineRequest after a failure not related to connectivity issues
Declaration
Swift
func offlineRequestManager(_ manager: OfflineRequestManager, shouldReattemptRequest request: OfflineRequest, withError error: Error) -> Bool
Parameters
manager
OfflineRequestManager instance
request
OfflineRequest that failed
error
NSError associated with the failure
Return Value
value indicating whether the OfflineRequestManager should reattempt the OfflineRequest action
-
Callback indicating that the OfflineRequest action has started
Declaration
Swift
func offlineRequestManager(_ manager: OfflineRequestManager, didStartRequest request: OfflineRequest)
Parameters
manager
OfflineRequestManager instance
request
OfflineRequest that started its action
-
Callback indicating that the OfflineRequest status has changed
Declaration
Swift
func offlineRequestManager(_ manager: OfflineRequestManager, didUpdateRequest request: OfflineRequest)
Parameters
manager
OfflineRequestManager instance
request
OfflineRequest that changed its subtitle
-
Callback indicating that the OfflineRequest action has successfully finished
Declaration
Swift
func offlineRequestManager(_ manager: OfflineRequestManager, didFinishRequest request: OfflineRequest)
Parameters
manager
OfflineRequestManager instance
request
OfflineRequest that finished its action
-
Callback indicating that the OfflineRequest action has failed for reasons unrelated to connectivity
Declaration
Swift
func offlineRequestManager(_ manager: OfflineRequestManager, requestDidFail request: OfflineRequest, withError error: Error)
Parameters
manager
OfflineRequestManager instance
request
OfflineRequest that failed
error
NSError associated with the failure