Skip to content

Commit 823b948

Browse files
committed
Add ListAppPasswords and fix docs
The last commit forgot about adding the documentation for the arguements of the method. This commit fixes this.
1 parent 3ab6153 commit 823b948

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// AtprotoServerListAppPasswords.swift
3+
//
4+
//
5+
// Created by Christopher Jr Riley on 2024-02-25.
6+
//
7+
8+
import Foundation
9+
10+
/// A data model definition of the of listing App Passwords.
11+
///
12+
/// - Note: According to the AT Protocol specifications: "List all App Passwords"
13+
///
14+
/// - SeeAlso: This is based on the [`com.atproto.server.listAppPasswords`][github] lexicon.
15+
///
16+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/com/atproto/server/listAppPasswords.json
17+
public struct ServerListAppPasswordsOutput: Codable {
18+
/// An array of App Passwords.
19+
public let passwords: [ServerAppPassword]
20+
}
21+
22+
/// A data model definition of App Password information.
23+
///
24+
/// - SeeAlso: This is based on the [`com.atproto.server.listAppPasswords`][github] lexicon.
25+
///
26+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/com/atproto/server/listAppPasswords.json
27+
public struct ServerAppPassword: Codable {
28+
/// The name associated with the App Password.
29+
public let name: String
30+
/// The date and date the App Password was created.
31+
@DateFormatting public let createdAt: Date
32+
33+
public init(name: String, createdAt: Date) {
34+
self.name = name
35+
self._createdAt = DateFormatting(wrappedValue: createdAt)
36+
}
37+
38+
public init(from decoder: Decoder) throws {
39+
let container = try decoder.container(keyedBy: CodingKeys.self)
40+
41+
self.name = try container.decode(String.self, forKey: .name)
42+
self.createdAt = try container.decode(DateFormatting.self, forKey: .createdAt).wrappedValue
43+
}
44+
45+
public func encode(to encoder: Encoder) throws {
46+
var container = encoder.container(keyedBy: CodingKeys.self)
47+
48+
try container.encode(self.name, forKey: .name)
49+
try container.encode(self._createdAt, forKey: .createdAt)
50+
}
51+
52+
enum CodingKeys: CodingKey {
53+
case name
54+
case createdAt
55+
}
56+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// ListAppPasswords.swift
3+
//
4+
//
5+
// Created by Christopher Jr Riley on 2024-02-25.
6+
//
7+
8+
import Foundation
9+
10+
extension ATProtoKit {
11+
/// Lists all of the App Passwords in a user's account.
12+
///
13+
/// - Returns: A `Result`, containing either a ``ServerListAppPasswordsOutput`` if successful, or an `Error` if not.
14+
public func listAppPasswords() async throws -> Result<ServerListAppPasswordsOutput, Error> {
15+
guard let sessionURL = session.pdsURL,
16+
let requestURL = URL(string: "\(requestURL)/xrpc/com.atproto.server.listAppPasswords") else {
17+
return .failure(NSError(domain: "", code: -1, userInfo: [NSLocalizedDescriptionKey : "Invalid URL"]))
18+
}
19+
20+
do {
21+
let request = APIClientService.createRequest(forRequest: requestURL, andMethod: .get, acceptValue: "application/json", contentTypeValue: nil, authorizationValue: "Bearer \(session.accessToken)")
22+
let response = APIClientService.sendRequest(request, decodeTo: ServerListAppPasswordsOutput.self)
23+
24+
return .success(response)
25+
} catch {
26+
return .failure(error)
27+
}
28+
}
29+
}

Sources/ATProtoKit/Networking/CoreAPI/ReserveSigningKey.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import Foundation
99

1010
extension ATProtoKit {
1111
/// Reserves a signing key for the respository.
12-
///
12+
///
13+
/// - Parameters:
14+
/// - repositoryDID: The decentalized identifier (DID) of the repository.
15+
/// - pdsURL: The URL of the Personal Data Server (PDS). Defaults to `https://bsky.social`.
16+
/// - Returns: A `Result`, containing either a ``ServerReserveSigningKeyOutput`` if successful, or an `Error` if not.
1317
public static func reserveSigningKey(_ repositoryDID: String, pdsURL: String = "https://bsky.social") async throws -> Result<ServerReserveSigningKeyOutput, Error> {
1418
let finalPDSURL = determinePDSURL(accessToken: nil, customPDSURL: pdsURL)
1519
guard let requestURL = URL(string: "\(finalPDSURL)/xrpc/com.atproto.server.reserveSigningKey") else {

0 commit comments

Comments
 (0)