-
-
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.
- Loading branch information
Showing
5 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
Sources/ATProtoKit/APIReference/AdminAndModeratorAPI/AddValuesAsAdmin.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,53 @@ | ||
// | ||
// AddValuesAsAdmin.swift | ||
// | ||
// Created by Christopher Jr Riley on 2024-10-19. | ||
// | ||
|
||
import Foundation | ||
|
||
extension ATProtoAdmin { | ||
|
||
/// Adds values to a specific set as an administrator. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: "Add values to a specific set. | ||
/// Attempting to add values to a set that does not exist will result in an error." | ||
/// | ||
/// - SeeAlso: This is based on the [`tools.ozone.set.addValues`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/set/addValues.json | ||
/// | ||
public func addValues(setName: String, values: [String]) 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.set.addValues") else { | ||
throw ATRequestPrepareError.invalidRequestURL | ||
} | ||
|
||
let requestBody = ToolsOzoneLexicon.Set.AddValuesRequestBody( | ||
name: setName, | ||
values: values | ||
) | ||
|
||
do { | ||
let request = APIClientService.createRequest( | ||
forRequest: requestURL, | ||
andMethod: .post, | ||
acceptValue: "application/json", | ||
contentTypeValue: "application/json", | ||
authorizationValue: "Bearer \(accessToken)" | ||
) | ||
|
||
try await APIClientService.shared.sendRequest( | ||
request, | ||
withEncodingBody: requestBody | ||
) | ||
} catch { | ||
throw error | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
Sources/ATProtoKit/APIReference/AdminAndModeratorAPI/GetRepositoriesAsAdmin.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,66 @@ | ||
// | ||
// GetRepositoriesAsAdmin.swift.swift | ||
// | ||
// Created by Christopher Jr Riley on 2024-10-19. | ||
// | ||
|
||
import Foundation | ||
|
||
extension ATProtoAdmin { | ||
|
||
/// Gets an array of repositories as a moderator. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: "Get details about some repositories." | ||
/// | ||
/// - SeeAlso: This is based on the [`tools.ozone.moderation.getRepos`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/moderation/getRepos.json | ||
/// | ||
/// - Parameter dids: An array of Decentralized Identifiers (DIDs) to extract the | ||
/// repository information. Limits to 100 items. | ||
/// - Returns: An aray of repositories based on the decentralized identifiers (DIDs) given. | ||
/// | ||
/// - Throws: An ``ATProtoError``-conforming error type, depending on the issue. Go to | ||
/// ``ATAPIError`` and ``ATRequestPrepareError`` for more details. | ||
public func getRepositories(from dids: [String]) async throws -> ToolsOzoneLexicon.Moderation.GetRepositoriesOutput { | ||
guard session != nil, | ||
let accessToken = session?.accessToken else { | ||
throw ATRequestPrepareError.missingActiveSession | ||
} | ||
|
||
guard let sessionURL = session?.pdsURL, | ||
let requestURL = URL(string: "\(sessionURL)/xrpc/tools.ozone.moderation.getRepos") else { | ||
throw ATRequestPrepareError.invalidRequestURL | ||
} | ||
|
||
var queryItems = [(String, String)]() | ||
|
||
let cappedDIDArray = dids.prefix(25) | ||
queryItems += cappedDIDArray.map { ("dids", $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.Moderation.GetRepositoriesOutput.self | ||
) | ||
|
||
return response | ||
} catch { | ||
throw error | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Sources/ATProtoKit/Models/Lexicons/tools.ozone/Moderation/ToolsOzoneModerationGetRepos.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,35 @@ | ||
// | ||
// ToolsOzoneModerationGetRepos.swift | ||
// | ||
// Created by Christopher Jr Riley on 2024-10-19. | ||
// | ||
|
||
import Foundation | ||
import ATMacro | ||
|
||
extension ToolsOzoneLexicon.Moderation { | ||
|
||
/// An output model for getting an array of repositories as a moderator. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: "Get details about some repositories." | ||
/// | ||
/// - SeeAlso: This is based on the [`tools.ozone.moderation.getRepos`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/moderation/getRepos.json | ||
public struct GetRepositoriesOutput: Codable { | ||
|
||
/// An array of repositories. | ||
public let repositories: [String] | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case repositories = "repos" | ||
} | ||
} | ||
} | ||
|
||
extension ATUnion { | ||
#ATUnionBuilder(named: "ModerationGetRepositoriesOutputUnion", containing: [ | ||
"repoViewDetail" : "ToolsOzoneLexicon.Moderation.RepositoryViewDetailDefinition", | ||
"repoViewNotFound" : "ToolsOzoneLexicon.Moderation.RepositoryViewNotFoundDefinition" | ||
]) | ||
} |
27 changes: 27 additions & 0 deletions
27
Sources/ATProtoKit/Models/Lexicons/tools.ozone/Set/ToolsOzoneModerationSetAddValues.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,27 @@ | ||
// | ||
// ToolsOzoneModerationSetAddValues.swift | ||
// | ||
// Created by Christopher Jr Riley on 2024-10-19. | ||
// | ||
|
||
import Foundation | ||
|
||
extension ToolsOzoneLexicon.Set { | ||
|
||
/// A request body model for adding values to a specific set as an administrator. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: "Add values to a specific set. | ||
/// Attempting to add values to a set that does not exist will result in an error." | ||
/// | ||
/// - SeeAlso: This is based on the [`tools.ozone.set.addValues`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/set/addValues.json | ||
public struct AddValuesRequestBody: Codable { | ||
|
||
/// The name of the set. | ||
public let name: String | ||
|
||
/// An array of values. Limited to 100 items. | ||
public let values: [String] | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
Sources/ATProtoKit/Models/Lexicons/tools.ozone/Set/ToolsOzoneSetDefs.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,65 @@ | ||
// | ||
// ToolsOzoneSetDefs.swift | ||
// | ||
// Created by Christopher Jr Riley on 2024-10-19. | ||
// | ||
|
||
import Foundation | ||
|
||
extension ToolsOzoneLexicon.Set { | ||
|
||
/// A definition model for a set. | ||
/// | ||
/// - SeeAlso: This is based on the [`tools.ozone.set.defs`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/set/defs.json | ||
public struct SetDefinition: Codable { | ||
|
||
/// The name of the set. | ||
/// | ||
/// A minimum of 3 characters and maximum of 128 characters is required. | ||
public let name: String | ||
|
||
/// The description of the set. | ||
/// | ||
/// A maximum of 1,024 characters can be made. | ||
public let description: String? | ||
} | ||
|
||
/// A definition model for a set view. | ||
/// | ||
/// - SeeAlso: This is based on the [`tools.ozone.set.defs`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/set/defs.json | ||
public struct SetViewDefinition: Codable { | ||
|
||
/// The name of the set. | ||
/// | ||
/// A minimum of 3 characters and maximum of 128 characters is required. | ||
public let name: String | ||
|
||
/// The description of the set. | ||
/// | ||
/// A maximum of 1,024 characters can be made. | ||
public let description: String? | ||
|
||
/// The size of the set. | ||
public let setSize: Int | ||
|
||
/// The date and time the set was created. | ||
@DateFormatting public var createdAt: Date | ||
|
||
/// The date and time the set was updated. | ||
@DateFormatting public var updatedAt: Date | ||
|
||
public func encode(to encoder: any Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
|
||
try container.encode(self.name, forKey: .name) | ||
try container.encodeIfPresent(self.description, forKey: .description) | ||
try container.encode(self.setSize, forKey: .setSize) | ||
try container.encode(self.createdAt, forKey: .createdAt) | ||
try container.encode(self.updatedAt, forKey: .updatedAt) | ||
} | ||
} | ||
} |