|
|
|
|
@ -7,18 +7,22 @@ |
|
|
|
|
|
|
|
|
|
import Foundation |
|
|
|
|
|
|
|
|
|
protocol SomeCall: Storable { |
|
|
|
|
public protocol SomeCall: Identifiable, Storable { |
|
|
|
|
var id: String { get } |
|
|
|
|
var lastAttemptDate: Date { get } |
|
|
|
|
var attemptsCount: Int { get } |
|
|
|
|
|
|
|
|
|
var method: HTTPMethod { get } |
|
|
|
|
var dataId: String? { get } |
|
|
|
|
var dataContent: String? { get } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class ApiCall<T: Storable>: ModelObject, Storable, SomeCall { |
|
|
|
|
public class ApiCall<T: Storable>: ModelObject, Storable, SomeCall { |
|
|
|
|
|
|
|
|
|
static func resourceName() -> String { return "apicalls_" + T.resourceName() } |
|
|
|
|
public static func resourceName() -> String { return "apicalls_" + T.resourceName() } |
|
|
|
|
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } |
|
|
|
|
|
|
|
|
|
var id: String = Store.randomId() |
|
|
|
|
public var id: String = Store.randomId() |
|
|
|
|
|
|
|
|
|
/// The transactionId to group calls together |
|
|
|
|
var transactionId: String = Store.randomId() |
|
|
|
|
@ -27,16 +31,16 @@ class ApiCall<T: Storable>: ModelObject, Storable, SomeCall { |
|
|
|
|
var creationDate: Date? = Date() |
|
|
|
|
|
|
|
|
|
/// The HTTP method of the call |
|
|
|
|
var method: HTTPMethod |
|
|
|
|
public var method: HTTPMethod |
|
|
|
|
|
|
|
|
|
/// The content of the call |
|
|
|
|
var data: T? |
|
|
|
|
|
|
|
|
|
/// The number of times the call has been executed |
|
|
|
|
var attemptsCount: Int = 0 |
|
|
|
|
public var attemptsCount: Int = 0 |
|
|
|
|
|
|
|
|
|
/// The date of the last execution |
|
|
|
|
var lastAttemptDate: Date = Date() |
|
|
|
|
public var lastAttemptDate: Date = Date() |
|
|
|
|
|
|
|
|
|
/// The parameters to add in the URL to obtain : "?p1=v1&p2=v2" |
|
|
|
|
var urlParameters: [String : String]? = nil |
|
|
|
|
@ -49,7 +53,7 @@ class ApiCall<T: Storable>: ModelObject, Storable, SomeCall { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func copy(from other: any Storable) { |
|
|
|
|
public func copy(from other: any Storable) { |
|
|
|
|
fatalError("should not happen") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -72,10 +76,20 @@ class ApiCall<T: Storable>: ModelObject, Storable, SomeCall { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static func relationships() -> [Relationship] { return [] } |
|
|
|
|
public var dataId: String? { |
|
|
|
|
return self.data?.stringId |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public var dataContent: String? { |
|
|
|
|
if let data = self.data { |
|
|
|
|
return try? data.jsonString() |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static func relationships() -> [Relationship] { return [] } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OldApiCall<T: Storable>: ModelObject, Storable, SomeCall { |
|
|
|
|
|
|
|
|
|
static func resourceName() -> String { return "apicalls_" + T.resourceName() } |
|
|
|
|
@ -148,6 +162,8 @@ class OldApiCall<T: Storable>: ModelObject, Storable, SomeCall { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var dataContent: String? { return self.body } |
|
|
|
|
|
|
|
|
|
static func relationships() -> [Relationship] { return [] } |
|
|
|
|
|
|
|
|
|
func toNewApiCall() -> ApiCall<T>? { |
|
|
|
|
|