-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The last commit didn't have the CodingKeys implemented in order to maintain the consistency of the JSON name when renaming the property in the Swift model. This commit fixes that.
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
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
24 changes: 24 additions & 0 deletions
24
Sources/ATProtoKit/Models/Lexicons/com.atproto/Server/AtprotoServerUpdateEmail.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,24 @@ | ||
// | ||
// AtprotoServerUpdateEmail.swift | ||
// | ||
// | ||
// Created by Christopher Jr Riley on 2024-02-27. | ||
// | ||
|
||
import Foundation | ||
|
||
/// The main data model definition for updating the user's email address. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: "Update an account's email." | ||
/// | ||
/// - SeeAlso: This is based on the [`com.atproto.server.updateEmail`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/com/atproto/server/updateEmail.json | ||
public struct ServerUpdateEmail: Codable { | ||
/// The email associated with the user's account. | ||
public let email: String | ||
/// The token that's used if the email has been confirmed. Optional. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: "Requires a token from com.atproto.sever.requestEmailUpdate if the account's email has been confirmed." | ||
public let token: String? | ||
} |
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,29 @@ | ||
// | ||
// UpdateEmail.swift | ||
// | ||
// | ||
// Created by Christopher Jr Riley on 2024-02-27. | ||
// | ||
|
||
import Foundation | ||
|
||
extension ATProtoKit { | ||
/// Updates the email address associated with the user's account. | ||
/// | ||
public func updateEmail(_ email: String, token: String? = nil) async throws { | ||
guard let sessionURL = session.pdsURL, | ||
let requestURL = URL(string: "\(sessionURL)/xrpc/om.atproto.server.updateEmail") else { | ||
throw NSError(domain: "", code: -1, userInfo: [NSLocalizedDescriptionKey : "Invalid URL"]) | ||
} | ||
|
||
let requestBody = ServerUpdateEmail(email: email, token: token) | ||
|
||
do { | ||
let request = APIClientService.createRequest(forRequest: requestURL, andMethod: .post, acceptValue: nil, contentTypeValue: "application/json", authorizationValue: "Bearer \(session.accessToken)") | ||
|
||
try await APIClientService.sendRequest(request, withEncodingBody: requestBody) | ||
} catch { | ||
throw error | ||
} | ||
} | ||
} |