Created
January 8, 2024 17:42
-
-
Save kyleroche/4c4867dec4dcb8eb664a57922926e5fd to your computer and use it in GitHub Desktop.
GriptapeCloudClient iOS Example
This file contains hidden or 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
| // | |
| // GriptapeCloudClient.swift | |
| // GriptapeCloudClient | |
| // | |
| // Created by Kyle Roche on 1/7/24. | |
| // | |
| import Foundation | |
| import OpenAPIRuntime | |
| import OpenAPIURLSession | |
| import HTTPTypes | |
| struct AuthMiddleware: ClientMiddleware { | |
| let apiKey: String | |
| func intercept(_ request: HTTPRequest, body: HTTPBody?, baseURL: URL, operationID: String, next: (HTTPRequest, HTTPBody?, URL) async throws -> (HTTPResponse, HTTPBody?)) async throws -> (HTTPResponse, HTTPBody?) { | |
| var request = request | |
| request.headerFields.append( | |
| //.init(name: HTTPField.Name.authorization, value: apiKey) | |
| .init(name: HTTPField.Name.authorization, value: "Bearer \(apiKey)") | |
| ) | |
| return try await next(request, body, baseURL) | |
| } | |
| } | |
| public struct GriptapeCloudClient{ | |
| let client: Client | |
| public init(apiKey: String) { | |
| self.client = Client( | |
| serverURL: try! Servers.server1(stageSuffix: "-staging"), | |
| transport: URLSessionTransport(), | |
| middlewares: [AuthMiddleware(apiKey: apiKey)] | |
| ) | |
| } | |
| public func listOrganizations() async throws -> String { | |
| let test = "string" | |
| let response = try await client.ListOrganizations() | |
| switch response { | |
| //implement | |
| } | |
| } | |
| } | |
| extension String: LocalizedError { | |
| public var errorDescription: String? { self } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment