Make APICall delegate based rather than defining a bunch of protocols.
This commit is contained in:
parent
de883ce082
commit
8d7eb910da
|
@ -13,12 +13,6 @@
|
||||||
84245C5E1FDC697A0074AFBB /* Credentials.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C5C1FDC697A0074AFBB /* Credentials.swift */; };
|
84245C5E1FDC697A0074AFBB /* Credentials.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C5C1FDC697A0074AFBB /* Credentials.swift */; };
|
||||||
84245C601FDC69F20074AFBB /* APICall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C5F1FDC69F20074AFBB /* APICall.swift */; };
|
84245C601FDC69F20074AFBB /* APICall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C5F1FDC69F20074AFBB /* APICall.swift */; };
|
||||||
84245C611FDC69F20074AFBB /* 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 */; };
|
84245C6F1FDDCD8C0074AFBB /* HTTPResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84245C6E1FDDCD8C0074AFBB /* HTTPResult.swift */; };
|
||||||
84245C701FDDCD8C0074AFBB /* 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 */; };
|
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 = "<group>"; };
|
84245C591FDC690A0074AFBB /* WebServiceProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebServiceProvider.swift; sourceTree = "<group>"; };
|
||||||
84245C5C1FDC697A0074AFBB /* Credentials.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Credentials.swift; path = RSWeb/Credentials.swift; sourceTree = "<group>"; };
|
84245C5C1FDC697A0074AFBB /* Credentials.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Credentials.swift; path = RSWeb/Credentials.swift; sourceTree = "<group>"; };
|
||||||
84245C5F1FDC69F20074AFBB /* APICall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APICall.swift; sourceTree = "<group>"; };
|
84245C5F1FDC69F20074AFBB /* APICall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APICall.swift; sourceTree = "<group>"; };
|
||||||
84245C621FDC6A060074AFBB /* APIRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIRequest.swift; sourceTree = "<group>"; };
|
|
||||||
84245C681FDC6A1E0074AFBB /* APIResultParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIResultParser.swift; sourceTree = "<group>"; };
|
|
||||||
84245C6B1FDC6A6D0074AFBB /* APIAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIAction.swift; sourceTree = "<group>"; };
|
|
||||||
84245C6E1FDDCD8C0074AFBB /* HTTPResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = HTTPResult.swift; path = RSWeb/HTTPResult.swift; sourceTree = "<group>"; };
|
84245C6E1FDDCD8C0074AFBB /* HTTPResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = HTTPResult.swift; path = RSWeb/HTTPResult.swift; sourceTree = "<group>"; };
|
||||||
842ED2E61E12FB8A000CF738 /* HTTPRequestHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HTTPRequestHeader.swift; path = RSWeb/HTTPRequestHeader.swift; sourceTree = "<group>"; };
|
842ED2E61E12FB8A000CF738 /* HTTPRequestHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HTTPRequestHeader.swift; path = RSWeb/HTTPRequestHeader.swift; sourceTree = "<group>"; };
|
||||||
842ED2E91E12FB91000CF738 /* HTTPMethod.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HTTPMethod.swift; path = RSWeb/HTTPMethod.swift; sourceTree = "<group>"; };
|
842ED2E91E12FB91000CF738 /* HTTPMethod.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HTTPMethod.swift; path = RSWeb/HTTPMethod.swift; sourceTree = "<group>"; };
|
||||||
|
@ -130,9 +121,6 @@
|
||||||
children = (
|
children = (
|
||||||
84245C591FDC690A0074AFBB /* WebServiceProvider.swift */,
|
84245C591FDC690A0074AFBB /* WebServiceProvider.swift */,
|
||||||
84245C5F1FDC69F20074AFBB /* APICall.swift */,
|
84245C5F1FDC69F20074AFBB /* APICall.swift */,
|
||||||
84245C621FDC6A060074AFBB /* APIRequest.swift */,
|
|
||||||
84245C681FDC6A1E0074AFBB /* APIResultParser.swift */,
|
|
||||||
84245C6B1FDC6A6D0074AFBB /* APIAction.swift */,
|
|
||||||
);
|
);
|
||||||
name = WebServices;
|
name = WebServices;
|
||||||
path = RSWeb/WebServices;
|
path = RSWeb/WebServices;
|
||||||
|
@ -377,7 +365,6 @@
|
||||||
842ED2F61E12FBAF000CF738 /* OneShotDownload.swift in Sources */,
|
842ED2F61E12FBAF000CF738 /* OneShotDownload.swift in Sources */,
|
||||||
842ED2F31E12FBAA000CF738 /* DownloadSession.swift in Sources */,
|
842ED2F31E12FBAA000CF738 /* DownloadSession.swift in Sources */,
|
||||||
842ED3081E12FBD2000CF738 /* URLRequest+RSWeb.swift in Sources */,
|
842ED3081E12FBD2000CF738 /* URLRequest+RSWeb.swift in Sources */,
|
||||||
84245C691FDC6A1E0074AFBB /* APIResultParser.swift in Sources */,
|
|
||||||
842ED3051E12FBCC000CF738 /* NSMutableURLRequest+RSWeb.swift in Sources */,
|
842ED3051E12FBCC000CF738 /* NSMutableURLRequest+RSWeb.swift in Sources */,
|
||||||
842ED2E71E12FB8A000CF738 /* HTTPRequestHeader.swift in Sources */,
|
842ED2E71E12FB8A000CF738 /* HTTPRequestHeader.swift in Sources */,
|
||||||
842ED3111E12FBE1000CF738 /* MacWebBrowser.swift in Sources */,
|
842ED3111E12FBE1000CF738 /* MacWebBrowser.swift in Sources */,
|
||||||
|
@ -387,10 +374,8 @@
|
||||||
84245C601FDC69F20074AFBB /* APICall.swift in Sources */,
|
84245C601FDC69F20074AFBB /* APICall.swift in Sources */,
|
||||||
842ED30B1E12FBD8000CF738 /* URL+RSWeb.swift in Sources */,
|
842ED30B1E12FBD8000CF738 /* URL+RSWeb.swift in Sources */,
|
||||||
842ED2F91E12FBB5000CF738 /* DownloadProgress.swift in Sources */,
|
842ED2F91E12FBB5000CF738 /* DownloadProgress.swift in Sources */,
|
||||||
84245C6C1FDC6A6D0074AFBB /* APIAction.swift in Sources */,
|
|
||||||
842ED2EA1E12FB91000CF738 /* HTTPMethod.swift in Sources */,
|
842ED2EA1E12FB91000CF738 /* HTTPMethod.swift in Sources */,
|
||||||
842ED3021E12FBC7000CF738 /* HTTPConditionalGetInfo.swift in Sources */,
|
842ED3021E12FBC7000CF738 /* HTTPConditionalGetInfo.swift in Sources */,
|
||||||
84245C631FDC6A060074AFBB /* APIRequest.swift in Sources */,
|
|
||||||
842ED2ED1E12FB97000CF738 /* HTTPResponseCode.swift in Sources */,
|
842ED2ED1E12FB97000CF738 /* HTTPResponseCode.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
@ -411,15 +396,12 @@
|
||||||
842ED2F71E12FBAF000CF738 /* OneShotDownload.swift in Sources */,
|
842ED2F71E12FBAF000CF738 /* OneShotDownload.swift in Sources */,
|
||||||
842ED30F1E12FBDD000CF738 /* URLResponse+RSWeb.swift in Sources */,
|
842ED30F1E12FBDD000CF738 /* URLResponse+RSWeb.swift in Sources */,
|
||||||
842ED2E81E12FB8A000CF738 /* HTTPRequestHeader.swift in Sources */,
|
842ED2E81E12FB8A000CF738 /* HTTPRequestHeader.swift in Sources */,
|
||||||
84245C6D1FDC6A6D0074AFBB /* APIAction.swift in Sources */,
|
|
||||||
842ED3001E12FBC1000CF738 /* UserAgent.swift in Sources */,
|
842ED3001E12FBC1000CF738 /* UserAgent.swift in Sources */,
|
||||||
842ED2FA1E12FBB5000CF738 /* DownloadProgress.swift in Sources */,
|
842ED2FA1E12FBB5000CF738 /* DownloadProgress.swift in Sources */,
|
||||||
84245C641FDC6A060074AFBB /* APIRequest.swift in Sources */,
|
|
||||||
842ED2EB1E12FB91000CF738 /* HTTPMethod.swift in Sources */,
|
842ED2EB1E12FB91000CF738 /* HTTPMethod.swift in Sources */,
|
||||||
84245C701FDDCD8C0074AFBB /* HTTPResult.swift in Sources */,
|
84245C701FDDCD8C0074AFBB /* HTTPResult.swift in Sources */,
|
||||||
842ED2F11E12FB9B000CF738 /* HTTPResponseHeader.swift in Sources */,
|
842ED2F11E12FB9B000CF738 /* HTTPResponseHeader.swift in Sources */,
|
||||||
84245C611FDC69F20074AFBB /* APICall.swift in Sources */,
|
84245C611FDC69F20074AFBB /* APICall.swift in Sources */,
|
||||||
84245C6A1FDC6A1E0074AFBB /* APIResultParser.swift in Sources */,
|
|
||||||
842ED3061E12FBCC000CF738 /* NSMutableURLRequest+RSWeb.swift in Sources */,
|
842ED3061E12FBCC000CF738 /* NSMutableURLRequest+RSWeb.swift in Sources */,
|
||||||
842ED2F41E12FBAA000CF738 /* DownloadSession.swift in Sources */,
|
842ED2F41E12FBAA000CF738 /* DownloadSession.swift in Sources */,
|
||||||
84245C5E1FDC697A0074AFBB /* Credentials.swift in Sources */,
|
84245C5E1FDC697A0074AFBB /* Credentials.swift in Sources */,
|
||||||
|
|
|
@ -14,28 +14,23 @@ public protocol APICallDelegate {
|
||||||
|
|
||||||
func apiCallURLRequest(_ call: APICall) -> URLRequest?
|
func apiCallURLRequest(_ call: APICall) -> URLRequest?
|
||||||
func apiCall(_ call: APICall, parseReturnedObjectWith: HTTPResult) -> Any?
|
func apiCall(_ call: APICall, parseReturnedObjectWith: HTTPResult) -> Any?
|
||||||
func apiCall(_ call: APICall, handleErrorWith: HTTPResult)
|
func apiCall(_ call: APICall, handleErrorWith: HTTPResult, returnedObject: Any?)
|
||||||
func apiCall(_ call: APICall, performActionWith: HTTPResult)
|
func apiCall(_ call: APICall, performActionWith: HTTPResult, returnedObject: Any?)
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class APICall {
|
public struct APICall {
|
||||||
|
|
||||||
// Create request. Call server. Create result. Create returned object. Run action.
|
|
||||||
|
|
||||||
public let provider: WebServiceProvider
|
public let provider: WebServiceProvider
|
||||||
public let url: URL
|
|
||||||
public let credentials: Credentials?
|
|
||||||
public let methodName: String
|
public let methodName: String
|
||||||
public let identifier: Int
|
public let identifier: Int
|
||||||
private let delegate: APICallDelegate
|
private let delegate: APICallDelegate
|
||||||
private static var incrementingIdentifier = 0
|
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.provider = provider
|
||||||
self.url = url
|
|
||||||
self.credentials = credentials
|
|
||||||
self.methodName = methodName
|
self.methodName = methodName
|
||||||
|
self.delegate = delegate
|
||||||
|
|
||||||
self.identifier = APICall.incrementingIdentifier
|
self.identifier = APICall.incrementingIdentifier
|
||||||
APICall.incrementingIdentifier += 1
|
APICall.incrementingIdentifier += 1
|
||||||
|
|
|
@ -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?
|
|
||||||
}
|
|
Loading…
Reference in New Issue