From 8d7eb910da46bb2a54fee35d3a5fd33a0512edbe Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 10 Dec 2017 13:57:38 -0800 Subject: [PATCH] Make APICall delegate based rather than defining a bunch of protocols. --- .../RSWeb/RSWeb.xcodeproj/project.pbxproj | 18 ------------------ .../RSWeb/RSWeb/WebServices/APICall.swift | 15 +++++---------- .../RSWeb/WebServices/APIResultParser.swift | 14 -------------- 3 files changed, 5 insertions(+), 42 deletions(-) delete mode 100644 Frameworks/RSWeb/RSWeb/WebServices/APIResultParser.swift diff --git a/Frameworks/RSWeb/RSWeb.xcodeproj/project.pbxproj b/Frameworks/RSWeb/RSWeb.xcodeproj/project.pbxproj index efd688b03..1d0c96a5b 100755 --- a/Frameworks/RSWeb/RSWeb.xcodeproj/project.pbxproj +++ b/Frameworks/RSWeb/RSWeb.xcodeproj/project.pbxproj @@ -13,12 +13,6 @@ 84245C5E1FDC697A0074AFBB /* Credentials.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C5C1FDC697A0074AFBB /* Credentials.swift */; }; 84245C601FDC69F20074AFBB /* APICall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C5F1FDC69F20074AFBB /* APICall.swift */; }; 84245C611FDC69F20074AFBB /* APICall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C5F1FDC69F20074AFBB /* APICall.swift */; }; - 84245C631FDC6A060074AFBB /* APIRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C621FDC6A060074AFBB /* APIRequest.swift */; }; - 84245C641FDC6A060074AFBB /* APIRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C621FDC6A060074AFBB /* APIRequest.swift */; }; - 84245C691FDC6A1E0074AFBB /* APIResultParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C681FDC6A1E0074AFBB /* APIResultParser.swift */; }; - 84245C6A1FDC6A1E0074AFBB /* APIResultParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C681FDC6A1E0074AFBB /* APIResultParser.swift */; }; - 84245C6C1FDC6A6D0074AFBB /* APIAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C6B1FDC6A6D0074AFBB /* APIAction.swift */; }; - 84245C6D1FDC6A6D0074AFBB /* APIAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C6B1FDC6A6D0074AFBB /* APIAction.swift */; }; 84245C6F1FDDCD8C0074AFBB /* HTTPResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C6E1FDDCD8C0074AFBB /* HTTPResult.swift */; }; 84245C701FDDCD8C0074AFBB /* HTTPResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C6E1FDDCD8C0074AFBB /* HTTPResult.swift */; }; 842ED2E71E12FB8A000CF738 /* HTTPRequestHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842ED2E61E12FB8A000CF738 /* HTTPRequestHeader.swift */; }; @@ -70,9 +64,6 @@ 84245C591FDC690A0074AFBB /* WebServiceProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebServiceProvider.swift; sourceTree = ""; }; 84245C5C1FDC697A0074AFBB /* Credentials.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Credentials.swift; path = RSWeb/Credentials.swift; sourceTree = ""; }; 84245C5F1FDC69F20074AFBB /* APICall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APICall.swift; sourceTree = ""; }; - 84245C621FDC6A060074AFBB /* APIRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIRequest.swift; sourceTree = ""; }; - 84245C681FDC6A1E0074AFBB /* APIResultParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIResultParser.swift; sourceTree = ""; }; - 84245C6B1FDC6A6D0074AFBB /* APIAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIAction.swift; sourceTree = ""; }; 84245C6E1FDDCD8C0074AFBB /* HTTPResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = HTTPResult.swift; path = RSWeb/HTTPResult.swift; sourceTree = ""; }; 842ED2E61E12FB8A000CF738 /* HTTPRequestHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HTTPRequestHeader.swift; path = RSWeb/HTTPRequestHeader.swift; sourceTree = ""; }; 842ED2E91E12FB91000CF738 /* HTTPMethod.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HTTPMethod.swift; path = RSWeb/HTTPMethod.swift; sourceTree = ""; }; @@ -130,9 +121,6 @@ children = ( 84245C591FDC690A0074AFBB /* WebServiceProvider.swift */, 84245C5F1FDC69F20074AFBB /* APICall.swift */, - 84245C621FDC6A060074AFBB /* APIRequest.swift */, - 84245C681FDC6A1E0074AFBB /* APIResultParser.swift */, - 84245C6B1FDC6A6D0074AFBB /* APIAction.swift */, ); name = WebServices; path = RSWeb/WebServices; @@ -377,7 +365,6 @@ 842ED2F61E12FBAF000CF738 /* OneShotDownload.swift in Sources */, 842ED2F31E12FBAA000CF738 /* DownloadSession.swift in Sources */, 842ED3081E12FBD2000CF738 /* URLRequest+RSWeb.swift in Sources */, - 84245C691FDC6A1E0074AFBB /* APIResultParser.swift in Sources */, 842ED3051E12FBCC000CF738 /* NSMutableURLRequest+RSWeb.swift in Sources */, 842ED2E71E12FB8A000CF738 /* HTTPRequestHeader.swift in Sources */, 842ED3111E12FBE1000CF738 /* MacWebBrowser.swift in Sources */, @@ -387,10 +374,8 @@ 84245C601FDC69F20074AFBB /* APICall.swift in Sources */, 842ED30B1E12FBD8000CF738 /* URL+RSWeb.swift in Sources */, 842ED2F91E12FBB5000CF738 /* DownloadProgress.swift in Sources */, - 84245C6C1FDC6A6D0074AFBB /* APIAction.swift in Sources */, 842ED2EA1E12FB91000CF738 /* HTTPMethod.swift in Sources */, 842ED3021E12FBC7000CF738 /* HTTPConditionalGetInfo.swift in Sources */, - 84245C631FDC6A060074AFBB /* APIRequest.swift in Sources */, 842ED2ED1E12FB97000CF738 /* HTTPResponseCode.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -411,15 +396,12 @@ 842ED2F71E12FBAF000CF738 /* OneShotDownload.swift in Sources */, 842ED30F1E12FBDD000CF738 /* URLResponse+RSWeb.swift in Sources */, 842ED2E81E12FB8A000CF738 /* HTTPRequestHeader.swift in Sources */, - 84245C6D1FDC6A6D0074AFBB /* APIAction.swift in Sources */, 842ED3001E12FBC1000CF738 /* UserAgent.swift in Sources */, 842ED2FA1E12FBB5000CF738 /* DownloadProgress.swift in Sources */, - 84245C641FDC6A060074AFBB /* APIRequest.swift in Sources */, 842ED2EB1E12FB91000CF738 /* HTTPMethod.swift in Sources */, 84245C701FDDCD8C0074AFBB /* HTTPResult.swift in Sources */, 842ED2F11E12FB9B000CF738 /* HTTPResponseHeader.swift in Sources */, 84245C611FDC69F20074AFBB /* APICall.swift in Sources */, - 84245C6A1FDC6A1E0074AFBB /* APIResultParser.swift in Sources */, 842ED3061E12FBCC000CF738 /* NSMutableURLRequest+RSWeb.swift in Sources */, 842ED2F41E12FBAA000CF738 /* DownloadSession.swift in Sources */, 84245C5E1FDC697A0074AFBB /* Credentials.swift in Sources */, diff --git a/Frameworks/RSWeb/RSWeb/WebServices/APICall.swift b/Frameworks/RSWeb/RSWeb/WebServices/APICall.swift index cc69293b5..f3aeac026 100644 --- a/Frameworks/RSWeb/RSWeb/WebServices/APICall.swift +++ b/Frameworks/RSWeb/RSWeb/WebServices/APICall.swift @@ -14,28 +14,23 @@ public protocol APICallDelegate { func apiCallURLRequest(_ call: APICall) -> URLRequest? func apiCall(_ call: APICall, parseReturnedObjectWith: HTTPResult) -> Any? - func apiCall(_ call: APICall, handleErrorWith: HTTPResult) - func apiCall(_ call: APICall, performActionWith: HTTPResult) + func apiCall(_ call: APICall, handleErrorWith: HTTPResult, returnedObject: Any?) + func apiCall(_ call: APICall, performActionWith: HTTPResult, returnedObject: Any?) } -public final class APICall { - - // Create request. Call server. Create result. Create returned object. Run action. +public struct APICall { public let provider: WebServiceProvider - public let url: URL - public let credentials: Credentials? public let methodName: String public let identifier: Int private let delegate: APICallDelegate private static var incrementingIdentifier = 0 - init(provider: WebServiceProvider, url: URL, credentials: Credentials?, methodName: String, delegate: APICallDelegate) { + init(provider: WebServiceProvider, methodName: String, delegate: APICallDelegate) { self.provider = provider - self.url = url - self.credentials = credentials self.methodName = methodName + self.delegate = delegate self.identifier = APICall.incrementingIdentifier APICall.incrementingIdentifier += 1 diff --git a/Frameworks/RSWeb/RSWeb/WebServices/APIResultParser.swift b/Frameworks/RSWeb/RSWeb/WebServices/APIResultParser.swift deleted file mode 100644 index 7e7f497b1..000000000 --- a/Frameworks/RSWeb/RSWeb/WebServices/APIResultParser.swift +++ /dev/null @@ -1,14 +0,0 @@ -// -// APIResultParser.swift -// RSWeb -// -// Created by Brent Simmons on 12/9/17. -// Copyright © 2017 Ranchero Software. All rights reserved. -// - -import Foundation - -public protocol APIResultParser { - - func parsedObject(with: APIResult) -> Any? -}