Make APICall delegate based rather than defining a bunch of protocols.

This commit is contained in:
Brent Simmons
2017-12-10 13:57:38 -08:00
parent de883ce082
commit 8d7eb910da
3 changed files with 5 additions and 42 deletions

View File

@@ -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

View File

@@ -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?
}