diff --git a/Sources/File.swift b/Sources/File.swift index ae917cc..df14fce 100644 --- a/Sources/File.swift +++ b/Sources/File.swift @@ -91,9 +91,9 @@ public struct VOFile { } } - public func fetchProbe(_ id: String, options: ProbeOptions) async throws -> Probe { + public func fetchProbe(_ id: String, options: ListOptions) async throws -> Probe { try await withCheckedThrowingContinuation { continuation in - var request = URLRequest(url: urlForProbe(id, options: options)) + var request = URLRequest(url: urlForList(id, options: options)) request.httpMethod = "GET" request.appendAuthorizationHeader(accessToken) let task = URLSession.shared.dataTask(with: request) { data, response, error in @@ -509,14 +509,6 @@ public struct VOFile { } } - public func urlForProbe(_ id: String, options: ProbeOptions) -> URL { - if let query = options.urlQuery { - URL(string: "\(urlForID(id))/list?\(query)")! - } else { - urlForID(id) - } - } - public func urlForCreateFile(_ options: CreateFileOptions) -> URL { var urlComponents = URLComponents() urlComponents.queryItems = [ @@ -608,24 +600,6 @@ public struct VOFile { } } - public struct ProbeOptions { - public let size: Int? - - public init(size: Int? = nil) { - self.size = size - } - - var urlQuery: String? { - var items: [URLQueryItem] = [] - if let size { - items.append(.init(name: "size", value: String(size))) - } - var components = URLComponents() - components.queryItems = items - return components.url?.query - } - } - public struct ListOptions { public let query: Query? public let page: Int? diff --git a/Sources/Group.swift b/Sources/Group.swift index 371b092..1bce307 100644 --- a/Sources/Group.swift +++ b/Sources/Group.swift @@ -55,6 +55,24 @@ public struct VOGroup { } } + public func fetchProbe(_ options: ListOptions) async throws -> Probe { + try await withCheckedThrowingContinuation { continuation in + var request = URLRequest(url: urlForList(options)) + request.httpMethod = "GET" + request.appendAuthorizationHeader(accessToken) + let task = URLSession.shared.dataTask(with: request) { data, response, error in + handleJSONResponse( + continuation: continuation, + response: response, + data: data, + error: error, + type: Probe.self + ) + } + task.resume() + } + } + public func create(_ options: CreateOptions) async throws -> Entity { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: url()) @@ -347,4 +365,14 @@ public struct VOGroup { self.size = size } } + + public struct Probe: Codable, Equatable, Hashable { + public let totalPages: Int + public let totalElements: Int + + public init(totalPages: Int, totalElements: Int) { + self.totalPages = totalPages + self.totalElements = totalElements + } + } } diff --git a/Sources/Insights.swift b/Sources/Insights.swift index 60c4cdb..19087c1 100644 --- a/Sources/Insights.swift +++ b/Sources/Insights.swift @@ -55,6 +55,24 @@ public struct VOInsights { } } + public func fetchEntityProbe(_ id: String, options: ListEntitiesOptions) async throws -> EntityProbe { + try await withCheckedThrowingContinuation { continuation in + var request = URLRequest(url: urlForEntities(id, options: options)) + request.httpMethod = "GET" + request.appendAuthorizationHeader(accessToken) + let task = URLSession.shared.dataTask(with: request) { data, response, error in + handleJSONResponse( + continuation: continuation, + response: response, + data: data, + error: error, + type: EntityProbe.self + ) + } + task.resume() + } + } + public func fetchLanguages() async throws -> [Language] { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: urlForLanguages()) @@ -280,4 +298,14 @@ public struct VOInsights { self.size = size } } + + public struct EntityProbe: Codable, Equatable, Hashable { + public let totalPages: Int + public let totalElements: Int + + public init(totalPages: Int, totalElements: Int) { + self.totalPages = totalPages + self.totalElements = totalElements + } + } } diff --git a/Sources/Invitation.swift b/Sources/Invitation.swift index d1af8cb..753e91a 100644 --- a/Sources/Invitation.swift +++ b/Sources/Invitation.swift @@ -19,7 +19,7 @@ public struct VOInvitation { // MARK: - Requests - public func fetchIncoming(_ options: ListIncomingOptions) async throws -> List { + public func fetchIncomingList(_ options: ListIncomingOptions) async throws -> List { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: urlForListIncoming(urlForIncoming(), options: options)) request.httpMethod = "GET" @@ -37,6 +37,24 @@ public struct VOInvitation { } } + public func fetchIncomingProbe(_ options: ListIncomingOptions) async throws -> Probe { + try await withCheckedThrowingContinuation { continuation in + var request = URLRequest(url: urlForListIncoming(urlForIncoming(), options: options)) + request.httpMethod = "GET" + request.appendAuthorizationHeader(accessToken) + let task = URLSession.shared.dataTask(with: request) { data, response, error in + handleJSONResponse( + continuation: continuation, + response: response, + data: data, + error: error, + type: Probe.self + ) + } + task.resume() + } + } + public func fetchIncomingCount() async throws -> Int { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: urlForIncomingCount()) @@ -55,7 +73,7 @@ public struct VOInvitation { } } - public func fetchOutgoing(_ options: ListOutgoingOptions) async throws -> List { + public func fetchOutgoingList(_ options: ListOutgoingOptions) async throws -> List { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: urlForListOutgoing(urlForOutgoing(), options: options)) request.httpMethod = "GET" @@ -73,6 +91,24 @@ public struct VOInvitation { } } + public func fetchOutgoingProbe(_ options: ListOutgoingOptions) async throws -> Probe { + try await withCheckedThrowingContinuation { continuation in + var request = URLRequest(url: urlForListOutgoing(urlForOutgoing(), options: options)) + request.httpMethod = "GET" + request.appendAuthorizationHeader(accessToken) + let task = URLSession.shared.dataTask(with: request) { data, response, error in + handleJSONResponse( + continuation: continuation, + response: response, + data: data, + error: error, + type: Probe.self + ) + } + task.resume() + } + } + public func create(_ options: CreateOptions) async throws -> [Entity] { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: url()) @@ -401,4 +437,14 @@ public struct VOInvitation { self.size = size } } + + public struct Probe: Codable, Equatable, Hashable { + public let totalPages: Int + public let totalElements: Int + + public init(totalPages: Int, totalElements: Int) { + self.totalPages = totalPages + self.totalElements = totalElements + } + } } diff --git a/Sources/Organization.swift b/Sources/Organization.swift index 23fbc4e..4a6c8af 100644 --- a/Sources/Organization.swift +++ b/Sources/Organization.swift @@ -55,6 +55,24 @@ public struct VOOrganization { } } + public func fetchProbe(_ options: ListOptions) async throws -> Probe { + try await withCheckedThrowingContinuation { continuation in + var request = URLRequest(url: urlForList(options)) + request.httpMethod = "GET" + request.appendAuthorizationHeader(accessToken) + let task = URLSession.shared.dataTask(with: request) { data, response, error in + handleJSONResponse( + continuation: continuation, + response: response, + data: data, + error: error, + type: Probe.self + ) + } + task.resume() + } + } + public func create(_ options: CreateOptions) async throws -> Entity { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: url()) @@ -312,4 +330,14 @@ public struct VOOrganization { self.size = size } } + + public struct Probe: Codable, Equatable, Hashable { + public let totalPages: Int + public let totalElements: Int + + public init(totalPages: Int, totalElements: Int) { + self.totalPages = totalPages + self.totalElements = totalElements + } + } } diff --git a/Sources/Snapshot.swift b/Sources/Snapshot.swift index 02d1761..8a48b3c 100644 --- a/Sources/Snapshot.swift +++ b/Sources/Snapshot.swift @@ -55,6 +55,24 @@ public struct VOSnapshot { } } + public func fetchProbe(_ options: ListOptions) async throws -> Probe { + try await withCheckedThrowingContinuation { continuation in + var request = URLRequest(url: urlForList(options)) + request.httpMethod = "GET" + request.appendAuthorizationHeader(accessToken) + let task = URLSession.shared.dataTask(with: request) { data, response, error in + handleJSONResponse( + continuation: continuation, + response: response, + data: data, + error: error, + type: Probe.self + ) + } + task.resume() + } + } + public func activate(_ id: String) async throws { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: urlForActivate(id)) @@ -293,6 +311,16 @@ public struct VOSnapshot { } } + public struct Probe: Codable, Equatable, Hashable { + public let totalPages: Int + public let totalElements: Int + + public init(totalPages: Int, totalElements: Int) { + self.totalPages = totalPages + self.totalElements = totalElements + } + } + public enum Status: String, Codable { case waiting case processing diff --git a/Sources/Task.swift b/Sources/Task.swift index ca6b2e9..8926b1f 100644 --- a/Sources/Task.swift +++ b/Sources/Task.swift @@ -55,6 +55,24 @@ public struct VOTask { } } + public func fetchProbe(_ options: ListOptions) async throws -> Probe { + try await withCheckedThrowingContinuation { continuation in + var request = URLRequest(url: urlForList(options)) + request.httpMethod = "GET" + request.appendAuthorizationHeader(accessToken) + let task = URLSession.shared.dataTask(with: request) { data, response, error in + handleJSONResponse( + continuation: continuation, + response: response, + data: data, + error: error, + type: Probe.self + ) + } + task.resume() + } + } + public func fetchCount() async throws -> Int { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: urlForCount()) @@ -287,6 +305,16 @@ public struct VOTask { } } + public struct Probe: Codable, Equatable, Hashable { + public let totalPages: Int + public let totalElements: Int + + public init(totalPages: Int, totalElements: Int) { + self.totalPages = totalPages + self.totalElements = totalElements + } + } + public struct DismissAllResult: Codable, Equatable, Hashable { public let succeeded: [String] public let failed: [String] diff --git a/Sources/User.swift b/Sources/User.swift index 3c0a0cc..57604c6 100644 --- a/Sources/User.swift +++ b/Sources/User.swift @@ -37,6 +37,24 @@ public struct VOUser { } } + public func fetchProbe(_ options: ListOptions) async throws -> Probe { + try await withCheckedThrowingContinuation { continuation in + var request = URLRequest(url: urlForList(options)) + request.httpMethod = "GET" + request.appendAuthorizationHeader(accessToken) + let task = URLSession.shared.dataTask(with: request) { data, response, error in + handleJSONResponse( + continuation: continuation, + response: response, + data: data, + error: error, + type: Probe.self + ) + } + task.resume() + } + } + // MARK: - URLs public func url() -> URL { @@ -185,4 +203,14 @@ public struct VOUser { self.size = size } } + + public struct Probe: Codable { + public let totalPages: Int + public let totalElements: Int + + public init(totalPages: Int, totalElements: Int) { + self.totalPages = totalPages + self.totalElements = totalElements + } + } } diff --git a/Sources/Workspace.swift b/Sources/Workspace.swift index 70ad2e2..b6072ec 100644 --- a/Sources/Workspace.swift +++ b/Sources/Workspace.swift @@ -55,6 +55,24 @@ public struct VOWorkspace { } } + public func fetchProbe(_ options: ListOptions) async throws -> Probe { + try await withCheckedThrowingContinuation { continuation in + var request = URLRequest(url: urlForList(options)) + request.httpMethod = "GET" + request.appendAuthorizationHeader(accessToken) + let task = URLSession.shared.dataTask(with: request) { data, response, error in + handleJSONResponse( + continuation: continuation, + response: response, + data: data, + error: error, + type: Probe.self + ) + } + task.resume() + } + } + public func create(_ options: CreateOptions) async throws -> Entity { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: url()) @@ -319,4 +337,14 @@ public struct VOWorkspace { self.size = size } } + + public struct Probe: Codable, Equatable, Hashable { + public let totalPages: Int + public let totalElements: Int + + public init(totalPages: Int, totalElements: Int) { + self.totalPages = totalPages + self.totalElements = totalElements + } + } } diff --git a/Tests/InvitationTests.swift b/Tests/InvitationTests.swift index 09f22b0..c9d57a5 100644 --- a/Tests/InvitationTests.swift +++ b/Tests/InvitationTests.swift @@ -31,7 +31,7 @@ final class InvitationTests: XCTestCase { _ = try await client.create(.init(organizationID: organization.id, emails: [otherUser.email])) - let incoming = try await otherClient.fetchIncoming(.init(organizationID: organization.id)) + let incoming = try await otherClient.fetchIncomingList(.init(organizationID: organization.id)) XCTAssertEqual(incoming.totalElements, 1) } @@ -55,7 +55,7 @@ final class InvitationTests: XCTestCase { _ = try await client.create(.init(organizationID: organization.id, emails: [otherUser.email])) - let outgoing = try await client.fetchOutgoing(.init(organizationID: organization.id)) + let outgoing = try await client.fetchOutgoingList(.init(organizationID: organization.id)) XCTAssertEqual(outgoing.totalElements, 1) } @@ -83,7 +83,7 @@ final class InvitationTests: XCTestCase { emails: [otherUser.email] )) try await client.delete(invitations[0].id) - let outgoing = try await otherClient.fetchIncoming(.init()) + let outgoing = try await otherClient.fetchIncomingList(.init()) XCTAssertEqual(outgoing.totalElements, 0) } @@ -147,10 +147,10 @@ final class InvitationTests: XCTestCase { )) try await otherClient.decline(invitations[0].id) - let incoming = try await otherClient.fetchIncoming(.init()) + let incoming = try await otherClient.fetchIncomingList(.init()) XCTAssertEqual(incoming.totalElements, 0) - let outgoing = try await client.fetchOutgoing(.init(organizationID: organization.id)) + let outgoing = try await client.fetchOutgoingList(.init(organizationID: organization.id)) XCTAssertEqual(outgoing.totalElements, 1) }