-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from fumito-ito/feature/admin-api
Admin API support
- Loading branch information
Showing
85 changed files
with
2,606 additions
and
171 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
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,106 @@ | ||
// | ||
// APIKeys.swift | ||
// AnthropicSwiftSDK | ||
// | ||
// Created by 伊藤史 on 2024/11/28. | ||
// | ||
import Foundation | ||
|
||
public struct APIKeys { | ||
private let apiKey: String | ||
private let session: URLSession | ||
|
||
init(adminAPIKey: String, session: URLSession) { | ||
self.apiKey = adminAPIKey | ||
self.session = session | ||
} | ||
|
||
public func get(apiKeyId: String) async throws -> APIKeyResponse { | ||
try await get( | ||
apiKeyId: apiKeyId, | ||
anthropicHeaderProvider: DefaultAnthropicHeaderProvider(), | ||
authenticationHeaderProvider: APIKeyAuthenticationHeaderProvider(apiKey: apiKey) | ||
) | ||
} | ||
|
||
public func get( | ||
apiKeyId: String, | ||
anthropicHeaderProvider: AnthropicHeaderProvider, | ||
authenticationHeaderProvider: AuthenticationHeaderProvider | ||
) async throws -> APIKeyResponse { | ||
let client = APIClient( | ||
session: session, | ||
anthropicHeaderProvider: anthropicHeaderProvider, | ||
authenticationHeaderProvider: authenticationHeaderProvider | ||
) | ||
|
||
return try await client.send(request: GetAPIKeyRequest(apiKeyId: apiKeyId)) | ||
} | ||
|
||
public func list( | ||
limit: Int = 20, | ||
beforeId: String? = nil, | ||
afterId: String? = nil, | ||
status: APIKeyStatus? = nil, | ||
workspaceId: String? = nil, | ||
createdByUserId: String? = nil | ||
) async throws -> ObjectListResponse<APIKeyResponse> { | ||
fatalError("not implemented") | ||
} | ||
|
||
public func list( | ||
limit: Int = 20, | ||
beforeId: String? = nil, | ||
afterId: String? = nil, | ||
status: APIKeyStatus? = nil, | ||
workspaceId: String? = nil, | ||
createdByUserId: String? = nil, | ||
anthropicHeaderProvider: AnthropicHeaderProvider, | ||
authenticationHeaderProvider: AuthenticationHeaderProvider | ||
) async throws -> ObjectListResponse<APIKeyResponse> { | ||
try await list( | ||
session: session, | ||
type: .apiKey, | ||
limit: limit, | ||
beforeId: beforeId, | ||
afterId: afterId, | ||
anthropicHeaderProvider: anthropicHeaderProvider, | ||
authenticationHeaderProvider: authenticationHeaderProvider | ||
) | ||
} | ||
|
||
public func update(apiKeyId: String, name: String, status: APIKeyStatus? = nil) async throws -> APIKeyResponse { | ||
try await update( | ||
apiKeyId: apiKeyId, | ||
name: name, | ||
status: status, | ||
anthropicHeaderProvider: DefaultAnthropicHeaderProvider(), | ||
authenticationHeaderProvider: APIKeyAuthenticationHeaderProvider(apiKey: apiKey) | ||
) | ||
} | ||
|
||
public func update( | ||
apiKeyId: String, | ||
name: String, | ||
status: APIKeyStatus? = nil, | ||
anthropicHeaderProvider: AnthropicHeaderProvider, | ||
authenticationHeaderProvider: AuthenticationHeaderProvider | ||
) async throws -> APIKeyResponse { | ||
let client = APIClient( | ||
session: session, | ||
anthropicHeaderProvider: anthropicHeaderProvider, | ||
authenticationHeaderProvider: authenticationHeaderProvider | ||
) | ||
|
||
return try await client.send( | ||
request: UpdateAPIKeyRequest( | ||
body: .init(name: name, status: status), | ||
apiKeyId: apiKeyId | ||
) | ||
) | ||
} | ||
} | ||
|
||
extension APIKeys: ObjectListable { | ||
typealias Object = APIKeyResponse | ||
} |
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,23 @@ | ||
// | ||
// Admin.swift | ||
// AnthropicSwiftSDK | ||
// | ||
// Created by 伊藤史 on 2024/11/28. | ||
// | ||
import Foundation | ||
|
||
public struct Admin { | ||
public let organizationMembers: OrganizationMembers | ||
public let organizationInvites: OrganizationInvites | ||
public let workspaces: Workspaces | ||
public let workspaceMembers: WorkspaceMembers | ||
public let apiKeys: APIKeys | ||
|
||
public init(adminAPIKey apiKey: String, session: URLSession = .shared) { | ||
self.organizationMembers = OrganizationMembers(adminAPIKey: apiKey, session: session) | ||
self.organizationInvites = OrganizationInvites(adminAPIKey: apiKey, session: session) | ||
self.workspaces = Workspaces(adminAPIKey: apiKey, session: session) | ||
self.workspaceMembers = WorkspaceMembers(adminAPIKey: apiKey, session: session) | ||
self.apiKeys = APIKeys(adminAPIKey: apiKey, session: session) | ||
} | ||
} |
Oops, something went wrong.