Skip to content

Commit

Permalink
Add tools.ozone.setting lexicons; fix DocC
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterJ93 committed Jan 1, 2025
1 parent e79528d commit 18146f7
Show file tree
Hide file tree
Showing 16 changed files with 578 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//
// ListOptionsAsAdmin.swift
//
//
// Created by Christopher Jr Riley on 2025-01-01.
//

import Foundation

extension ATProtoAdmin {

/// Lists settings that can be filtered.
///
/// - Note: According to the AT Protocol specifications: "List settings with optional filtering."
///
/// - SeeAlso: This is based on the [`tools.ozone.setting.listOptions`][github] lexicon.
///
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/setting/listOptions.json
///
/// - Parameters:
/// - limit: The number of invite codes in the list. Optional. Defaults to `50`.
/// - cursor: The mark used to indicate the starting point for the next set
/// of results. Optional.
/// - scope: The scope of the options. Optional. Defaults to `.instance`.
/// - prefix: Filter keys by prefix. Optional.
/// - key: Filters the data to include only the specified keys, ignoring any provided prefix.
/// Optional.
/// - Returns: An array of options, with an optional cursor to expand the array.
///
/// - Throws: An ``ATProtoError``-conforming error type, depending on the issue. Go to
/// ``ATAPIError`` and ``ATRequestPrepareError`` for more details.
public func listOptions(
withLimitOf limit: Int? = 50,
cursor: String? = nil,
scope: ToolsOzoneLexicon.Setting.ListOptions.Scope? = .instance,
prefix: String? = nil,
key: [String]? = []
) async throws -> ToolsOzoneLexicon.Setting.ListOptionsOutput {
guard session != nil,
let accessToken = session?.accessToken else {
throw ATRequestPrepareError.missingActiveSession
}

guard let sessionURL = session?.pdsURL,
let requestURL = URL(string: "\(sessionURL)/xrpc/tools.ozone.setting.listOptions") else {
throw ATRequestPrepareError.invalidRequestURL
}

var queryItems = [(String, String)]()

if let cursor {
queryItems.append(("cursor", cursor))
}

if let limit {
let finalLimit = max(1, min(limit, 100))
queryItems.append(("limit", "\(finalLimit)"))
}

if let scope {
queryItems.append(("scope", "\(scope)"))
}

if let prefix {
queryItems.append(("prefix", prefix))
}

if let key {
queryItems += key.map { ("removedLabels", $0) }
}

let queryURL: URL

do {
queryURL = try APIClientService.setQueryItems(
for: requestURL,
with: queryItems
)

let request = APIClientService.createRequest(
forRequest: queryURL,
andMethod: .get,
acceptValue: "application/json",
contentTypeValue: nil,
authorizationValue: "Bearer \(accessToken)"
)
let response = try await APIClientService.shared.sendRequest(
request,
decodeTo: ToolsOzoneLexicon.Setting.ListOptionsOutput.self
)

return response
} catch {
throw error
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ extension ATProtoAdmin {
}

// removeTags
if let addedTags {
queryItems += addedTags.map { ("removedLabels", $0) }
if let removedTags {
queryItems += removedTags.map { ("removedLabels", $0) }
}

// reportTypes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// RemoveOptionsAsAdmin.swift
//
//
// Created by Christopher Jr Riley on 2025-01-01.
//

import Foundation

extension ATProtoAdmin {

/// Deletes a setting options by their keys.
///
/// - Note: According to the AT Protocol specifications: "Delete settings by key."
///
/// - SeeAlso: This is based on the [`tools.ozone.setting.removeOptions`][github] lexicon.
///
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/setting/removeOptions.json
///
public func removeOption(
by keys: [String],
scope: ToolsOzoneLexicon.Setting.RemoveOptions.Scope
) async throws {
guard session != nil,
let accessToken = session?.accessToken else {
throw ATRequestPrepareError.missingActiveSession
}

guard let sessionURL = session?.pdsURL,
let requestURL = URL(string: "\(sessionURL)/xrpc/tools.ozone.setting.removeOptions") else {
throw ATRequestPrepareError.invalidRequestURL
}

let requestBody = ToolsOzoneLexicon.Setting.RemoveOptionsRequestBody(
keys: keys,
scope: scope
)

do {
let request = APIClientService.createRequest(
forRequest: requestURL,
andMethod: .get,
acceptValue: "application/json",
contentTypeValue: nil,
authorizationValue: "Bearer \(accessToken)"
)

_ = try await APIClientService.shared.sendRequest(
request,
withEncodingBody: requestBody
)
} catch {
throw error
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// UpsertOptionAsAdmin.swift
//
//
// Created by Christopher Jr Riley on 2025-01-01.
//

import Foundation

extension ATProtoAdmin {

/// Creates or updates a setting option.
///
/// - Note: According to the AT Protocol specifications: "Create or update setting option."
///
/// - SeeAlso: This is based on the [`tools.ozone.setting.upsertOption`][github] lexicon.
///
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/setting/upsertOption.json
///
/// - Parameters:
/// - key: The key of the option.
/// - scope: The scope of the option. Defaults to `.instance`.
/// - value: The option's value.
/// - description: The option's description. Optional. Current maximum is
/// - managerRole: The manager role of the option. Optional.
/// - Returns: The newly upserted option.
public func upsertOption(
by key: String,
scope: ToolsOzoneLexicon.Setting.UpsertOption.Scope = .instance,
value: UnknownType,
description: String? = nil,
managerRole: ToolsOzoneLexicon.Team.MemberDefinition.Role?
) async throws -> ToolsOzoneLexicon.Setting.UpsertOptionOutput {
guard session != nil,
let accessToken = session?.accessToken else {
throw ATRequestPrepareError.missingActiveSession
}

guard let sessionURL = session?.pdsURL,
let requestURL = URL(string: "\(sessionURL)/xrpc/tools.ozone.setting.upsertOption") else {
throw ATRequestPrepareError.invalidRequestURL
}

let requestBody = ToolsOzoneLexicon.Setting.UpsertOptionRequestBody(
key: key,
scope: scope,
value: value,
description: description,
managerRole: managerRole
)

do {
let request = APIClientService.createRequest(
forRequest: requestURL,
andMethod: .post,
acceptValue: "application/json",
contentTypeValue: "application/json",
authorizationValue: "Bearer \(accessToken)"
)
let response = try await APIClientService.shared.sendRequest(
request,
withEncodingBody: requestBody,
decodeTo: ToolsOzoneLexicon.Setting.UpsertOptionOutput.self
)

return response
} catch {
throw error
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- ``ComAtprotoLexicon/Admin/AccountViewDefinition``
- ``ComAtprotoLexicon/Admin/RepositoryReferenceDefinition``
- ``ComAtprotoLexicon/Admin/RepositoryBlobReferenceDefinition``
- ``ComAtprotoLexicon/Admin/ThreatSignatureDefinition``

### com.atproto.admin.deleteAccount

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

### com.atproto.repo.listRecords

- ``ComAtprotoLexicon/Repository/ListRecords``
- ``ComAtprotoLexicon/Repository/ListRecordsOutput``

### com.atproto.repo.putRecord
Expand All @@ -57,5 +58,5 @@

- ``ComAtprotoLexicon/Repository/UploadBlobRequestBody``
- ``ComAtprotoLexicon/Repository/BlobContainer``
- ``ComAtprotoLexicon/Repository/BlobContainer``
- ``ComAtprotoLexicon/Repository/UploadBlobOutput``
- ``ComAtprotoLexicon/Repository/BlobReference``
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
### com.atproto.server.createAccount

- ``ComAtprotoLexicon/Server/CreateAccountRequestBody``
- ``ComAtprotoLexicon/Server/CreateAccountOutput``

### com.atproto.server.createAppPassword

Expand All @@ -30,13 +31,16 @@

### com.atproto.server.createInviteCodes

- ``ComAtprotoLexicon/Server/CreateInviteCodes``
- ``ComAtprotoLexicon/Server/CreateInviteCodes/AccountCodes``
- ``ComAtprotoLexicon/Server/CreateInviteCodesRequestBody``
- ``ComAtprotoLexicon/Server/CreateInviteCodesOutput``

### com.atproto.server.createSession

- ``ComAtprotoLexicon/Server/CreateSession``
- ``ComAtprotoLexicon/Server/CreateSessionRequestBody``
- ``ComAtprotoLexicon/Server/CreateSessionOutput``

### com.atproto.server.deactiviateAccount

Expand Down Expand Up @@ -64,10 +68,20 @@

- ``ComAtprotoLexicon/Server/GetServiceAuthOutput``

### com.atproto.server.getSession

- ``ComAtprotoLexicon/Server/GetSession``
- ``ComAtprotoLexicon/Server/GetSessionOutput``

### com.atproto.server.listAppPasswords

- ``ComAtprotoLexicon/Server/ListAppPasswordsOutput``

### com.atproto.server.refreshSession

- ``ComAtprotoLexicon/Server/RefreshSession``
- ``ComAtprotoLexicon/Server/RefreshSessionOutput``

### com.atproto.server.requestEmailUpdate

- ``ComAtprotoLexicon/Server/RequestEmailUpdateOutput``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

### com.atproto.sync.listRepos

- ``ComAtprotoLexicon/Sync/ListRepositories``
- ``ComAtprotoLexicon/Sync/ListRepositoriesOutput``

### com.atproto.sync.subscribeRepos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Topics

### com.atproto.temp.addReservedHandle

- ``ComAtprotoLexicon/Temp/AddReservedHandleRequestBody``

### com.atproto.temp.checkSignupQueue

- ``ComAtprotoLexicon/Temp/CheckSignupQueueOutput``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
- ``ToolsOzoneLexicon/Moderation/EventEmailDefinition``
- ``ToolsOzoneLexicon/Moderation/EventDivertDefinition``
- ``ToolsOzoneLexicon/Moderation/EventTagDefinition``
- ``ToolsOzoneLexicon/Moderation/AccountEventDefinition``
- ``ToolsOzoneLexicon/Moderation/IdentityEventDefinition``
- ``ToolsOzoneLexicon/Moderation/RecordEventDefinition``
- ``ToolsOzoneLexicon/Moderation/RepositoryViewDefinition``
- ``ToolsOzoneLexicon/Moderation/RepositoryViewDetailDefinition``
- ``ToolsOzoneLexicon/Moderation/RepositoryViewNotFoundDefinition``
Expand All @@ -34,6 +37,8 @@
- ``ToolsOzoneLexicon/Moderation/BlobViewDefinition``
- ``ToolsOzoneLexicon/Moderation/ImageDetailsDefinition``
- ``ToolsOzoneLexicon/Moderation/VideoDetailsDefinition``
- ``ToolsOzoneLexicon/Moderation/AccountHostingDefinition``
- ``ToolsOzoneLexicon/Moderation/RecordHostingDefinition``

### tools.ozone.moderation.emitEvent

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ``ATProtoKit/ToolsOzoneLexicon/Setting``

## Topics

### tools.ozone.setting.defs

- ``ToolsOzoneLexicon/Setting/OptionDefinition

### tools.ozone.setting.listOptions

- ``ToolsOzoneLexicon/Setting/ListOptions``
- ``ToolsOzoneLexicon/Setting/ListOptionsOutput``

### tools.ozone.setting.removeOptions

- ``ToolsOzoneLexicon/Setting/RemoveOptions``
- ``ToolsOzoneLexicon/Setting/RemoveOptionsRequestBody``

### tools.ozone.setting.upsertOption

- ``ToolsOzoneLexicon/Setting/UpsertOption``
- ``ToolsOzoneLexicon/Setting/UpsertOptionRequestBody``
Loading

0 comments on commit 18146f7

Please sign in to comment.