-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tools.ozone.setting lexicons; fix DocC
- Loading branch information
Showing
16 changed files
with
578 additions
and
3 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
Sources/ATProtoKit/APIReference/AdminAndModeratorAPI/ListOptionsAsAdmin.swift
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,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 | ||
} | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
Sources/ATProtoKit/APIReference/AdminAndModeratorAPI/RemoveOptionsAsAdmin.swift
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,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 | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
Sources/ATProtoKit/APIReference/AdminAndModeratorAPI/UpsertOptionAsAdmin.swift
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,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 | ||
} | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...Kit/ATProtoKit.docc/Extensions/Lexicons/Models/tools.ozone/ToolsOzoneSetting.md
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,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`` |
Oops, something went wrong.