Renamed request manager to check-in request manager

This commit is contained in:
Raimund Wege
2017-09-08 11:10:01 +02:00
parent 8f4c0ee8e6
commit 3e274c69a7
10 changed files with 65 additions and 68 deletions
@@ -321,7 +321,7 @@
C84936181D40D295000F30E8 /* GPSFixController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C84936171D40D295000F30E8 /* GPSFixController.swift */; };
C84936291D47645F000F30E8 /* RegattaCheckInTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C84936281D47645F000F30E8 /* RegattaCheckInTableViewCell.swift */; };
C852914F1D48FB91009E9A9D /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C85291511D48FB91009E9A9D /* Localizable.strings */; };
C852BAA21CF5E1EA0093B0C5 /* RequestManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C852BAA11CF5E1EA0093B0C5 /* RequestManager.swift */; };
C852BAA21CF5E1EA0093B0C5 /* CheckInRequestManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C852BAA11CF5E1EA0093B0C5 /* CheckInRequestManager.swift */; };
C852BAAB1CF736680093B0C5 /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = C852BAAA1CF736680093B0C5 /* Preferences.swift */; };
C85DB8251F30B680009559CE /* SignUp.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C85DB8241F30B680009559CE /* SignUp.storyboard */; };
C85DB8281F31AAE0009559CE /* SignUpViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C85DB8271F31AAE0009559CE /* SignUpViewController.swift */; };
@@ -729,7 +729,7 @@
C84936171D40D295000F30E8 /* GPSFixController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GPSFixController.swift; sourceTree = "<group>"; };
C84936281D47645F000F30E8 /* RegattaCheckInTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegattaCheckInTableViewCell.swift; sourceTree = "<group>"; };
C85291501D48FB91009E9A9D /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
C852BAA11CF5E1EA0093B0C5 /* RequestManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestManager.swift; sourceTree = "<group>"; };
C852BAA11CF5E1EA0093B0C5 /* CheckInRequestManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckInRequestManager.swift; sourceTree = "<group>"; };
C852BAAA1CF736680093B0C5 /* Preferences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; };
C85DB8241F30B680009559CE /* SignUp.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = SignUp.storyboard; sourceTree = "<group>"; };
C85DB8271F31AAE0009559CE /* SignUpViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignUpViewController.swift; sourceTree = "<group>"; };
@@ -1323,7 +1323,7 @@
C8289F391F386D8300A76953 /* SignUpRequestManager.swift */,
7F2C605919F160E400C32D93 /* LocationManager.swift */,
7F1B66F81A0CDCF600904A41 /* BatteryManager.swift */,
C852BAA11CF5E1EA0093B0C5 /* RequestManager.swift */,
C852BAA11CF5E1EA0093B0C5 /* CheckInRequestManager.swift */,
C87A74E01F4EE570003DE396 /* TrainingRequestManager.swift */,
);
name = Managers;
@@ -2011,7 +2011,7 @@
7F1B66F91A0CDCF600904A41 /* BatteryManager.swift in Sources */,
7FA6551A19F6661900A1B92D /* CoreDataManager.swift in Sources */,
C8F71EE71D8691F700826DE4 /* SVRadialGradientLayer.m in Sources */,
C852BAA21CF5E1EA0093B0C5 /* RequestManager.swift in Sources */,
C852BAA21CF5E1EA0093B0C5 /* CheckInRequestManager.swift in Sources */,
C8F71EE01D8691F700826DE4 /* AFURLRequestSerialization.m in Sources */,
C8BBAC791C52649E004CA551 /* LicenseViewController.swift in Sources */,
C8BFCCC41D51C53500FC1A27 /* TeamData.swift in Sources */,
@@ -17,8 +17,8 @@ class CheckInController : NSObject {
}
fileprivate unowned let coreDataManager: CoreDataManager
fileprivate weak var viewController: UIViewController?
fileprivate var requestManager = RequestManager()
init(coreDataManager: CoreDataManager) {
self.coreDataManager = coreDataManager
@@ -34,7 +34,6 @@ class CheckInController : NSObject {
failure: @escaping (_ error: Error) -> Void)
{
self.viewController = viewController
requestManager = RequestManager(baseURLString: checkInData.serverURL)
collectCheckInData(checkInData: checkInData, success: success, failure: failure)
}
@@ -90,7 +89,8 @@ class CheckInController : NSObject {
failure: @escaping (_ error: Error) -> Void)
{
SVProgressHUD.show()
requestManager.postCheckIn(checkInData: checkInData, success: { [weak self] () in
let checkInRequestManager = CheckInRequestManager(baseURLString: checkInData.serverURL)
checkInRequestManager.postCheckIn(checkInData: checkInData, success: { [weak self] () in
SVProgressHUD.popActivity()
self?.postCheckInSuccess(checkInData: checkInData, success: success)
}) { [weak self] error in
@@ -23,10 +23,10 @@ extension CheckInDataCollectorError: LocalizedError {
class CheckInDataCollector: NSObject {
fileprivate let requestManager: RequestManager
fileprivate let checkInRequestManager: CheckInRequestManager
init(checkInData: CheckInData) {
requestManager = RequestManager(baseURLString: checkInData.serverURL)
checkInRequestManager = CheckInRequestManager(baseURLString: checkInData.serverURL)
super.init()
}
@@ -45,7 +45,7 @@ class CheckInDataCollector: NSObject {
success: @escaping (_ collector: CheckInData) -> Void,
failure: @escaping (_ error: Error) -> Void)
{
requestManager.getEvent(eventID: collector.eventID, success: { (eventData) in
checkInRequestManager.getEvent(eventID: collector.eventID, success: { (eventData) in
collector.eventData = eventData
self.getLeaderboardData(collector: collector, success: success, failure: failure)
}) { (error) in
@@ -60,7 +60,7 @@ class CheckInDataCollector: NSObject {
success: @escaping (_ collector: CheckInData) -> Void,
failure: @escaping (_ error: Error) -> Void)
{
requestManager.getLeaderboard(leaderboardName: collector.leaderboardName, success: { (leaderboardData) in
checkInRequestManager.getLeaderboard(leaderboardName: collector.leaderboardName, success: { (leaderboardData) in
collector.leaderboardData = leaderboardData
self.getLeaderboardDataSuccess(collector: collector, success: success, failure: failure)
}) { (error) in
@@ -88,7 +88,7 @@ class CheckInDataCollector: NSObject {
success: @escaping (_ collector: CheckInData) -> Void,
failure: @escaping (_ error: Error) -> Void)
{
requestManager.getCompetitor(competitorID: competitorID, success: { (competitorData) in
checkInRequestManager.getCompetitor(competitorID: competitorID, success: { (competitorData) in
collector.competitorData = competitorData
self.getCompetitorDataSuccess(
collector: collector,
@@ -107,7 +107,7 @@ class CheckInDataCollector: NSObject {
success: @escaping (_ collector: CheckInData) -> Void,
failure: @escaping (_ error: Error) -> Void)
{
requestManager.getTeamImageURL(competitorID: competitorID, result: { (imageURL) in
checkInRequestManager.getTeamImageURL(competitorID: competitorID, result: { (imageURL) in
collector.teamImageURL = imageURL
success(collector)
})
@@ -121,7 +121,7 @@ class CheckInDataCollector: NSObject {
success: @escaping (_ collector: CheckInData) -> Void,
failure: @escaping (_ error: Error) -> Void)
{
requestManager.getMark(leaderboardName: collector.leaderboardName, markID: markID, success: { (markData) in
checkInRequestManager.getMark(leaderboardName: collector.leaderboardName, markID: markID, success: { (markData) in
collector.markData = markData
success(collector)
}) { error in
@@ -1,5 +1,5 @@
//
// RequestManager.swift
// CheckInRequestManager.swift
// SAPTracker
//
// Created by Raimund Wege on 25.05.16.
@@ -9,7 +9,7 @@
import UIKit
enum RequestManagerError: Error {
enum CheckInRequestManagerError: Error {
case communicationFailed
case getCompetitorFailed
case getEventFailed
@@ -23,36 +23,36 @@ enum RequestManagerError: Error {
case teamImageURLIsInvalid
}
extension RequestManagerError: LocalizedError {
extension CheckInRequestManagerError: LocalizedError {
var errorDescription: String? {
switch self {
case .communicationFailed:
return Translation.RequestManagerError.CommunicationFailed.String
return Translation.CheckInRequestManagerError.CommunicationFailed.String
case .getCompetitorFailed:
return Translation.RequestManagerError.GetCompetitorFailed.String
return Translation.CheckInRequestManagerError.GetCompetitorFailed.String
case .getEventFailed:
return Translation.RequestManagerError.GetEventFailed.String
return Translation.CheckInRequestManagerError.GetEventFailed.String
case .getLeaderboardFailed:
return Translation.RequestManagerError.GetLeaderboardFailed.String
return Translation.CheckInRequestManagerError.GetLeaderboardFailed.String
case .getMarkFailed:
return Translation.RequestManagerError.GetMarkFailed.String
return Translation.CheckInRequestManagerError.GetMarkFailed.String
case .getTeamFailed:
return Translation.RequestManagerError.GetTeamFailed.String
return Translation.CheckInRequestManagerError.GetTeamFailed.String
case .postCheckInFailed:
return Translation.RequestManagerError.PostCheckInFailed.String
return Translation.CheckInRequestManagerError.PostCheckInFailed.String
case .postCheckOutFailed:
return Translation.RequestManagerError.PostCheckOutFailed.String
return Translation.CheckInRequestManagerError.PostCheckOutFailed.String
case .postGPSFixFailed:
return Translation.RequestManagerError.PostGPSFixFailed.String
return Translation.CheckInRequestManagerError.PostGPSFixFailed.String
case .postTeamImageFailed:
return Translation.RequestManagerError.PostTeamImageFailed.String
return Translation.CheckInRequestManagerError.PostTeamImageFailed.String
case .teamImageURLIsInvalid:
return Translation.RequestManagerError.TeamImageURLIsInvalid.String
return Translation.CheckInRequestManagerError.TeamImageURLIsInvalid.String
}
}
}
class RequestManager: NSObject {
class CheckInRequestManager: NSObject {
fileprivate let basePathString = "/sailingserver/api/v1"
@@ -118,7 +118,7 @@ class RequestManager: NSObject {
fileprivate func getEventFailure(error: Error, failure: (_ error: Error) -> Void) -> Void {
logError(name: "\(#function)", error: error)
failure(RequestManagerError.getEventFailed)
failure(CheckInRequestManagerError.getEventFailed)
}
// MARK: - Leaderboard
@@ -145,7 +145,7 @@ class RequestManager: NSObject {
fileprivate func getLeaderboardFailure(error: Error, failure: (_ error: Error) -> Void) {
logError(name: "\(#function)", error: error)
failure(RequestManagerError.getLeaderboardFailed)
failure(CheckInRequestManagerError.getLeaderboardFailed)
}
// MARK: - Competitor
@@ -172,7 +172,7 @@ class RequestManager: NSObject {
fileprivate func getCompetitorFailure(error: Error, failure: (_ error: Error) -> Void) {
logError(name: "\(#function)", error: error)
failure(RequestManagerError.getCompetitorFailed)
failure(CheckInRequestManagerError.getCompetitorFailed)
}
// MARK: - Mark
@@ -201,7 +201,7 @@ class RequestManager: NSObject {
fileprivate func getMarkFailure(error: Error, failure: (_ error: Error) -> Void) {
logError(name: "\(#function)", error: error)
failure(RequestManagerError.getMarkFailed)
failure(CheckInRequestManagerError.getMarkFailed)
}
// MARK: - Team
@@ -228,7 +228,7 @@ class RequestManager: NSObject {
fileprivate func getTeamFailure(error: Error, failure: (_ error: Error) -> Void) {
logError(name: "\(#function)", error: error)
failure(RequestManagerError.getTeamFailed)
failure(CheckInRequestManagerError.getTeamFailed)
}
func getTeamImageURL(competitorID: String, result: @escaping (_ imageURL: String?) -> Void) {
@@ -278,7 +278,7 @@ class RequestManager: NSObject {
fileprivate func postCheckInFailure(error: Error, failure: (_ error: Error) -> Void) {
logError(name: "\(#function)", error: error)
failure(RequestManagerError.postCheckInFailed)
failure(CheckInRequestManagerError.postCheckInFailed)
}
// MARK: - CheckOut
@@ -317,7 +317,7 @@ class RequestManager: NSObject {
fileprivate func postCheckOutFailure(error: Error, failure: (_ error: Error) -> Void) {
logError(name: "\(#function)", error: error)
failure(RequestManagerError.postCheckOutFailed)
failure(CheckInRequestManagerError.postCheckOutFailed)
}
// MARK: - GPSFixes
@@ -358,7 +358,7 @@ class RequestManager: NSObject {
fileprivate func postGPSFixesFailure(error: Error, failure: (_ error: Error) -> Void) {
logError(name: "\(#function)", error: error)
failure(RequestManagerError.postGPSFixFailed)
failure(CheckInRequestManagerError.postGPSFixFailed)
}
// MARK: - TeamImage
@@ -370,7 +370,7 @@ class RequestManager: NSObject {
failure: @escaping (_ error: Error) -> Void)
{
guard let teamImageURL = URL(string: "\(baseURLString)\(basePathString)/competitors/\(competitorID)/team/image") else {
failure(RequestManagerError.teamImageURLIsInvalid)
failure(CheckInRequestManagerError.teamImageURLIsInvalid)
return
}
@@ -408,11 +408,11 @@ class RequestManager: NSObject {
failure: (_ error: Error) -> Void)
{
guard let teamImageDictionary = responseObject as? [String: AnyObject] else {
postTeamImageDataFailure(error: RequestManagerError.communicationFailed, failure: failure)
postTeamImageDataFailure(error: CheckInRequestManagerError.communicationFailed, failure: failure)
return
}
guard let teamImageURL = teamImageDictionary[TeamImageKeys.TeamImageURL] as? String else {
postTeamImageDataFailure(error: RequestManagerError.communicationFailed, failure: failure)
postTeamImageDataFailure(error: CheckInRequestManagerError.communicationFailed, failure: failure)
return
}
@@ -18,7 +18,7 @@ class CompetitorSessionController: SessionController {
success: @escaping (_ teamImageURL: String) -> Void,
failure: @escaping (_ error: Error) -> Void
) {
requestManager.postTeamImageData(
checkInRequestManager.postTeamImageData(
imageData: imageData,
competitorID: competitorID,
success: success,
@@ -114,11 +114,11 @@ class GPSFixController: NSObject {
failure: @escaping (_ error: Error, _ gpsFixesLeft: Set<GPSFix>) -> Void)
{
log(info: "\(gpsFixes.count) GPS fixes will be sent and \(gpsFixesLeft.count) will be left")
requestManager.postGPSFixes(
gpsFixes: gpsFixes,
success: { () in self.sendSliceSuccess(gpsFixes: gpsFixes, gpsFixesLeft: gpsFixesLeft, success: success) },
failure: { (error) in self.sendSliceFailure(error: error, gpsFixesLeft: gpsFixesLeft, failure: failure) }
)
checkInRequestManager.postGPSFixes(gpsFixes: gpsFixes, success: { () in
self.sendSliceSuccess(gpsFixes: gpsFixes, gpsFixesLeft: gpsFixesLeft, success: success)
}) { (error) in
self.sendSliceFailure(error: error, gpsFixesLeft: gpsFixesLeft, failure: failure)
}
}
fileprivate func sendSliceSuccess(
@@ -158,9 +158,8 @@ class GPSFixController: NSObject {
// MARK: - Properties
fileprivate lazy var requestManager: RequestManager = {
let requestManager = RequestManager(baseURLString: self.checkIn.serverURL)
return requestManager
fileprivate lazy var checkInRequestManager: CheckInRequestManager = {
return CheckInRequestManager(baseURLString: self.checkIn.serverURL)
}()
// MARK: - Helper
@@ -135,7 +135,7 @@ class SessionController: NSObject {
// MARK: - CheckOut
func checkOut(completion: @escaping (_ withSuccess: Bool) -> Void) {
requestManager.postCheckOut(
checkInRequestManager.postCheckOut(
checkIn,
success: { () in completion(true) },
failure: { (error) in completion(false) }
@@ -145,13 +145,11 @@ class SessionController: NSObject {
// MARK: - Properties
lazy var gpsFixController: GPSFixController = {
let gpsFixController = GPSFixController(checkIn: self.checkIn, coreDataManager: self.coreDataManager)
return gpsFixController
return GPSFixController(checkIn: self.checkIn, coreDataManager: self.coreDataManager)
}()
lazy var requestManager: RequestManager = {
let requestManager = RequestManager(baseURLString: self.checkIn.serverURL)
return requestManager
lazy var checkInRequestManager: CheckInRequestManager = {
return CheckInRequestManager(baseURLString: self.checkIn.serverURL)
}()
}
@@ -106,40 +106,40 @@ class Translation: NSObject {
}
}
// MARK: - RequestManagerError
// MARK: - CheckInRequestManagerError
struct RequestManagerError { static let Key = "\(RequestManagerError.self)"
struct CommunicationFailed { static let Key = "\(RequestManagerError.Key).\(CommunicationFailed.self)"
struct CheckInRequestManagerError { static let Key = "\(CheckInRequestManagerError.self)"
struct CommunicationFailed { static let Key = "\(CheckInRequestManagerError.Key).\(CommunicationFailed.self)"
static let String = NSLocalizedString(Key, comment: "")
}
struct GetCompetitorFailed { static let Key = "\(RequestManagerError.Key).\(GetCompetitorFailed.self)"
struct GetCompetitorFailed { static let Key = "\(CheckInRequestManagerError.Key).\(GetCompetitorFailed.self)"
static let String = NSLocalizedString(Key, comment: "")
}
struct GetEventFailed { static let Key = "\(RequestManagerError.Key).\(GetEventFailed.self)"
struct GetEventFailed { static let Key = "\(CheckInRequestManagerError.Key).\(GetEventFailed.self)"
static let String = NSLocalizedString(Key, comment: "")
}
struct GetLeaderboardFailed { static let Key = "\(RequestManagerError.Key).\(GetLeaderboardFailed.self)"
struct GetLeaderboardFailed { static let Key = "\(CheckInRequestManagerError.Key).\(GetLeaderboardFailed.self)"
static let String = NSLocalizedString(Key, comment: "")
}
struct GetMarkFailed { static let Key = "\(RequestManagerError.Key).\(GetMarkFailed.self)"
struct GetMarkFailed { static let Key = "\(CheckInRequestManagerError.Key).\(GetMarkFailed.self)"
static let String = NSLocalizedString(Key, comment: "")
}
struct GetTeamFailed { static let Key = "\(RequestManagerError.Key).\(GetTeamFailed.self)"
struct GetTeamFailed { static let Key = "\(CheckInRequestManagerError.Key).\(GetTeamFailed.self)"
static let String = NSLocalizedString(Key, comment: "")
}
struct PostCheckInFailed { static let Key = "\(RequestManagerError.Key).\(PostCheckInFailed.self)"
struct PostCheckInFailed { static let Key = "\(CheckInRequestManagerError.Key).\(PostCheckInFailed.self)"
static let String = NSLocalizedString(Key, comment: "")
}
struct PostCheckOutFailed { static let Key = "\(RequestManagerError.Key).\(PostCheckOutFailed.self)"
struct PostCheckOutFailed { static let Key = "\(CheckInRequestManagerError.Key).\(PostCheckOutFailed.self)"
static let String = NSLocalizedString(Key, comment: "")
}
struct PostGPSFixFailed { static let Key = "\(RequestManagerError.Key).\(PostGPSFixFailed.self)"
struct PostGPSFixFailed { static let Key = "\(CheckInRequestManagerError.Key).\(PostGPSFixFailed.self)"
static let String = NSLocalizedString(Key, comment: "")
}
struct PostTeamImageFailed { static let Key = "\(RequestManagerError.Key).\(PostTeamImageFailed.self)"
struct PostTeamImageFailed { static let Key = "\(CheckInRequestManagerError.Key).\(PostTeamImageFailed.self)"
static let String = NSLocalizedString(Key, comment: "")
}
struct TeamImageURLIsInvalid { static let Key = "\(RequestManagerError.Key).\(TeamImageURLIsInvalid.self)"
struct TeamImageURLIsInvalid { static let Key = "\(CheckInRequestManagerError.Key).\(TeamImageURLIsInvalid.self)"
static let String = NSLocalizedString(Key, comment: "")
}
}