-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge Bunch of secondary features #9
- Loading branch information
Showing
18 changed files
with
942 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Foundation | ||
|
||
public struct Alias { | ||
var apiCall: ApiCall | ||
let RESOURCEPATH = "aliases" | ||
var config: Configuration | ||
|
||
public init(config: Configuration) { | ||
apiCall = ApiCall(config: config) | ||
self.config = config | ||
} | ||
|
||
public func upsert(name: String, collection: CollectionAliasSchema) async throws -> (CollectionAlias?, URLResponse?) { | ||
let schemaData: Data? | ||
|
||
schemaData = try encoder.encode(collection) | ||
|
||
if let validSchema = schemaData { | ||
let (data, response) = try await apiCall.put(endPoint: "\(RESOURCEPATH)/\(name)", body: validSchema) | ||
if let result = data { | ||
let alias = try decoder.decode(CollectionAlias.self, from: result) | ||
return (alias, response) | ||
} | ||
} | ||
return (nil, nil) | ||
} | ||
|
||
public func retrieve(name: String) async throws -> (CollectionAlias?, URLResponse?) { | ||
let (data, response) = try await apiCall.get(endPoint: "\(RESOURCEPATH)/\(name)") | ||
if let result = data { | ||
if let notExists = try? decoder.decode(ApiResponse.self, from: result) { | ||
throw ResponseError.aliasNotFound(desc: "Alias \(notExists.message)") | ||
} | ||
let alias = try decoder.decode(CollectionAlias.self, from: result) | ||
return (alias, response) | ||
} | ||
return (nil, nil) | ||
} | ||
|
||
public func retrieve() async throws -> (CollectionAliasesResponse?, URLResponse?) { | ||
let (data, response) = try await apiCall.get(endPoint: "\(RESOURCEPATH)") | ||
if let result = data { | ||
let aliases = try decoder.decode(CollectionAliasesResponse.self, from: result) | ||
return (aliases, response) | ||
} | ||
return (nil, nil) | ||
} | ||
|
||
public func delete(name: String) async throws -> (CollectionAlias?, URLResponse?) { | ||
let (data, response) = try await apiCall.delete(endPoint: "\(RESOURCEPATH)/\(name)") | ||
if let result = data { | ||
if let notExists = try? decoder.decode(ApiResponse.self, from: result) { | ||
throw ResponseError.aliasNotFound(desc: "Alias \(notExists.message)") | ||
} | ||
let alias = try decoder.decode(CollectionAlias.self, from: result) | ||
return (alias, response) | ||
} | ||
return (nil, nil) | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Foundation | ||
|
||
public struct ApiKeys { | ||
var apiCall: ApiCall | ||
let RESOURCEPATH = "keys" | ||
|
||
public init(config: Configuration) { | ||
apiCall = ApiCall(config: config) | ||
} | ||
|
||
public func create(_ keySchema: ApiKeySchema) async throws -> (ApiKey?, URLResponse?) { | ||
var schemaData: Data? = nil | ||
|
||
schemaData = try encoder.encode(keySchema) | ||
|
||
if let validSchema = schemaData { | ||
let (data, response) = try await apiCall.post(endPoint: "\(RESOURCEPATH)", body: validSchema) | ||
if let result = data { | ||
let keyResponse = try decoder.decode(ApiKey.self, from: result) | ||
return (keyResponse, response) | ||
} | ||
} | ||
|
||
return (nil, nil) | ||
} | ||
|
||
public func retrieve(id: Int) async throws -> (ApiKey?, URLResponse?) { | ||
|
||
let (data, response) = try await apiCall.get(endPoint: "\(RESOURCEPATH)/\(id)") | ||
if let result = data { | ||
if let notFound = try? decoder.decode(ApiResponse.self, from: result) { | ||
throw ResponseError.apiKeyNotFound(desc: notFound.message) | ||
} | ||
let keyResponse = try decoder.decode(ApiKey.self, from: result) | ||
return (keyResponse, response) | ||
} | ||
|
||
return (nil, nil) | ||
} | ||
|
||
public func retrieve() async throws -> (ApiKeysResponse?, URLResponse?) { | ||
|
||
let (data, response) = try await apiCall.get(endPoint: "\(RESOURCEPATH)") | ||
if let result = data { | ||
let keyResponse = try decoder.decode(ApiKeysResponse.self, from: result) | ||
return (keyResponse, response) | ||
} | ||
|
||
return (nil, nil) | ||
} | ||
|
||
public func delete(id: Int) async throws -> (Data?, URLResponse?) { | ||
|
||
let (data, response) = try await apiCall.delete(endPoint: "\(RESOURCEPATH)/\(id)") | ||
if let result = data { | ||
if let notFound = try? decoder.decode(ApiResponse.self, from: result) { | ||
throw ResponseError.apiKeyNotFound(desc: notFound.message) | ||
} | ||
} | ||
return (data, response) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import Foundation | ||
|
||
public struct Operations { | ||
var apiCall: ApiCall | ||
var RESOURCEPATH = "operations" | ||
|
||
public init(config: Configuration) { | ||
apiCall = ApiCall(config: config) | ||
} | ||
|
||
public func getHealth() async throws -> (HealthStatus?, URLResponse?) { | ||
let (data, response) = try await apiCall.get(endPoint: "health") | ||
if let result = data { | ||
let health = try decoder.decode(HealthStatus.self, from: result) | ||
return (health, response) | ||
} | ||
return (nil, nil) | ||
} | ||
|
||
public func getStats() async throws -> (Data?, URLResponse?) { | ||
let (data, response) = try await apiCall.get(endPoint: "stats.json") | ||
return (data, response) | ||
} | ||
|
||
public func getMetrics() async throws -> (Data?, URLResponse?) { | ||
let (data, response) = try await apiCall.get(endPoint: "metrics.json") | ||
return (data, response) | ||
} | ||
|
||
public func vote() async throws -> (SuccessStatus?, URLResponse?) { | ||
let (data, response) = try await apiCall.post(endPoint: "\(RESOURCEPATH)/vote", body: Data()) | ||
if let result = data { | ||
let success = try decoder.decode(SuccessStatus.self, from: result) | ||
return (success, response) | ||
} | ||
return (nil, nil) | ||
} | ||
|
||
public func snapshot(path: String? = "/tmp/typesense-data-snapshot") async throws -> (SuccessStatus?, URLResponse?) { | ||
let snapshotQueryParam = URLQueryItem(name: "snapshot_path", value: path) | ||
let (data, response) = try await apiCall.post(endPoint: "\(RESOURCEPATH)/snapshot", body: Data(), queryParameters: [snapshotQueryParam]) | ||
if let result = data { | ||
let success = try decoder.decode(SuccessStatus.self, from: result) | ||
return (success, response) | ||
} | ||
return (nil, nil) | ||
} | ||
|
||
public func toggleSlowRequestLog(seconds: Float) async throws -> (SuccessStatus?, URLResponse?) { | ||
let durationInMs = seconds * 1000 | ||
let slowReq = SlowRequest(durationInMs) | ||
let slowReqData = try encoder.encode(slowReq) | ||
let (data, response) = try await apiCall.post(endPoint: "/config", body: slowReqData) | ||
if let result = data { | ||
let success = try decoder.decode(SuccessStatus.self, from: result) | ||
return (success, response) | ||
} | ||
return (nil, nil) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.