|
|
|
|
@ -33,7 +33,7 @@ let changePasswordCall: ServiceCall = ServiceCall( |
|
|
|
|
let postDeviceTokenCall: ServiceCall = ServiceCall( |
|
|
|
|
path: "device-token/", method: .post, requiresToken: true) |
|
|
|
|
let getUserDataAccessCall: ServiceCall = ServiceCall( |
|
|
|
|
path: "user-data-access/", method: .get, requiresToken: true) |
|
|
|
|
path: "data-access/", method: .get, requiresToken: true) |
|
|
|
|
let userNamesCall: ServiceCall = ServiceCall( |
|
|
|
|
path: "user-names/", method: .get, requiresToken: true) |
|
|
|
|
|
|
|
|
|
@ -52,6 +52,8 @@ public class Services { |
|
|
|
|
Logger.log("create keystore with id: \(url)") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static let storeIdURLParameter = "store_id" |
|
|
|
|
|
|
|
|
|
// MARK: - Base |
|
|
|
|
|
|
|
|
|
/// Runs a request using a configuration object |
|
|
|
|
@ -80,7 +82,7 @@ public class Services { |
|
|
|
|
/// - Parameters: |
|
|
|
|
/// - request: the URLRequest to run |
|
|
|
|
/// - apiCallId: the id of the ApiCall to delete in case of success, or to schedule for a rerun in case of failure |
|
|
|
|
fileprivate func _runRequest<T: SyncedStorable, V: Decodable>( |
|
|
|
|
fileprivate func _runGetApiCallRequest<T: SyncedStorable, V: Decodable>( |
|
|
|
|
_ request: URLRequest, apiCall: ApiCall<T> |
|
|
|
|
) async throws -> V { |
|
|
|
|
let debugURL = request.url?.absoluteString ?? "" |
|
|
|
|
@ -242,14 +244,12 @@ public class Services { |
|
|
|
|
/// - identifier: an optional StoreIdentifier that allows to filter GET requests with the StoreIdentifier values |
|
|
|
|
fileprivate func _baseRequest( |
|
|
|
|
servicePath: String, method: HTTPMethod, requiresToken: Bool? = nil, |
|
|
|
|
identifier: String? = nil, getArguments: [String: String]? = nil |
|
|
|
|
identifier: String? = nil, getArguments: [String : String]? = nil |
|
|
|
|
) throws -> URLRequest { |
|
|
|
|
var urlString = baseURL + servicePath |
|
|
|
|
var arguments: [String:String] = getArguments ?? [:] |
|
|
|
|
var arguments: [String : String] = getArguments ?? [:] |
|
|
|
|
if let identifier { |
|
|
|
|
arguments["store_id"] = identifier |
|
|
|
|
// let component = "?store_id=\(identifier)" |
|
|
|
|
// urlString.append(component) |
|
|
|
|
arguments[Services.storeIdURLParameter] = identifier |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
urlString.append(arguments.toQueryString()) |
|
|
|
|
@ -369,7 +369,7 @@ public class Services { |
|
|
|
|
/// - apiCall: An ApiCall instance to configure the returned request |
|
|
|
|
fileprivate func _syncGetRequest<T: SyncedStorable>(from apiCall: ApiCall<T>) throws -> URLRequest { |
|
|
|
|
|
|
|
|
|
var urlString = baseURL + "data/" |
|
|
|
|
var urlString = "\(baseURL)\(T.resourceName())/" // baseURL + T.resourceName() // "data/" |
|
|
|
|
if let urlParameters = apiCall.formattedURLParameters() { |
|
|
|
|
urlString.append(urlParameters) |
|
|
|
|
} |
|
|
|
|
@ -547,7 +547,7 @@ public class Services { |
|
|
|
|
/// Executes an ApiCall |
|
|
|
|
func runGetApiCall<T: SyncedStorable, V: Decodable>(_ apiCall: ApiCall<T>) async throws -> V { |
|
|
|
|
let request = try self._syncGetRequest(from: apiCall) |
|
|
|
|
return try await self._runRequest(request, apiCall: apiCall) |
|
|
|
|
return try await self._runGetApiCallRequest(request, apiCall: apiCall) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Executes an ApiCall |
|
|
|
|
|