|
| 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 | +} |
0 commit comments