|
|
|
|
@ -352,9 +352,9 @@ public class Services { |
|
|
|
|
|
|
|
|
|
return request |
|
|
|
|
} |
|
|
|
|
//======= |
|
|
|
|
// |
|
|
|
|
// /// Executes a PUT request |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// /// Executes a PUT request |
|
|
|
|
// public func put<T: Storable>(_ instance: T) async throws -> T { |
|
|
|
|
// var postRequest = try self._putRequest(type: T.self, id: instance.stringId) |
|
|
|
|
// postRequest.httpBody = try jsonEncoder.encode(instance) |
|
|
|
|
@ -749,6 +749,48 @@ public class Services { |
|
|
|
|
try self._storeToken(username: userName, token: services.keychainStore.getValue()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Tests |
|
|
|
|
|
|
|
|
|
/// Executes a POST request |
|
|
|
|
public func post<T: Storable>(_ instance: T) async throws -> T { |
|
|
|
|
var postRequest = try self._postRequest(type: T.self) |
|
|
|
|
postRequest.httpBody = try JSON.encoder.encode(instance) |
|
|
|
|
return try await self._runRequest(postRequest) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Executes a PUT request |
|
|
|
|
public func put<T: Storable>(_ instance: T) async throws -> T { |
|
|
|
|
var postRequest = try self._putRequest(type: T.self, id: instance.stringId) |
|
|
|
|
postRequest.httpBody = try JSON.encoder.encode(instance) |
|
|
|
|
return try await self._runRequest(postRequest) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public func delete<T: Storable>(_ instance: T) async throws -> T { |
|
|
|
|
let deleteRequest = try self._deleteRequest(type: T.self, id: instance.stringId) |
|
|
|
|
return try await self._runRequest(deleteRequest) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns a POST request for the resource |
|
|
|
|
/// - Parameters: |
|
|
|
|
/// - type: the type of the request resource |
|
|
|
|
fileprivate func _postRequest<T: Storable>(type: T.Type) throws -> URLRequest { |
|
|
|
|
return try self._baseRequest(servicePath: T.path(), method: .post, requiresToken: true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns a PUT request for the resource |
|
|
|
|
/// - Parameters: |
|
|
|
|
/// - type: the type of the request resource |
|
|
|
|
fileprivate func _putRequest<T: Storable>(type: T.Type, id: String) throws -> URLRequest { |
|
|
|
|
return try self._baseRequest(servicePath: T.path(id: id), method: .put, requiresToken: true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns a DELETE request for the resource |
|
|
|
|
/// - Parameters: |
|
|
|
|
/// - type: the type of the request resource |
|
|
|
|
fileprivate func _deleteRequest<T: Storable>(type: T.Type, id: String) throws -> URLRequest { |
|
|
|
|
return try self._baseRequest(servicePath: T.path(id: id), method: .delete, requiresToken: true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct SyncPayload<T: Encodable>: Encodable { |
|
|
|
|
|