Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: probe endpoints #5

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 2 additions & 28 deletions Sources/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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?
Expand Down
28 changes: 28 additions & 0 deletions Sources/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
}
}
}
28 changes: 28 additions & 0 deletions Sources/Insights.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
}
}
}
50 changes: 48 additions & 2 deletions Sources/Invitation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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())
Expand All @@ -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"
Expand All @@ -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())
Expand Down Expand Up @@ -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
}
}
}
28 changes: 28 additions & 0 deletions Sources/Organization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
}
}
}
28 changes: 28 additions & 0 deletions Sources/Snapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions Sources/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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]
Expand Down
28 changes: 28 additions & 0 deletions Sources/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
}
Loading
Loading