Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 64a002f

Browse files
authored
Merge pull request #172 from wordpress-mobile/feature/9705-update-username
[Update Username] Map new property in account settings GET and new method
2 parents 8e34c17 + cbacefc commit 64a002f

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

WordPressKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "WordPressKit"
3-
s.version = "4.3.0-beta.3"
3+
s.version = "4.3.0-beta.4"
44
s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API."
55

66
s.description = <<-DESC

WordPressKit/AccountSettings.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public struct AccountSettings {
99

1010
// MARK: - Account Settings
1111
public let username: String // user_login
12+
public let usernameCanBeChanged: Bool // user_login_can_be_changed
1213
public let email: String // user_email
1314
public let emailPendingAddress: String? // new_user_email
1415
public let emailPendingChange: Bool // user_email_change_pending
@@ -22,6 +23,7 @@ public struct AccountSettings {
2223
displayName: String,
2324
aboutMe: String,
2425
username: String,
26+
usernameCanBeChanged: Bool,
2527
email: String,
2628
emailPendingAddress: String?,
2729
emailPendingChange: Bool,
@@ -34,6 +36,7 @@ public struct AccountSettings {
3436
self.displayName = displayName
3537
self.aboutMe = aboutMe
3638
self.username = username
39+
self.usernameCanBeChanged = usernameCanBeChanged
3740
self.email = email
3841
self.emailPendingAddress = emailPendingAddress
3942
self.emailPendingChange = emailPendingChange

WordPressKit/AccountSettingsRemote.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,29 @@ public class AccountSettingsRemote: ServiceRemoteWordPressComREST {
9090
})
9191
}
9292

93+
/// Validate the current user's username
94+
///
95+
/// - Parameters:
96+
/// - username: The new username
97+
/// - success: block for success
98+
/// - failure: block for failure
99+
public func validateUsername(to username: String, success: @escaping () -> Void, failure: @escaping (Error) -> Void) {
100+
let endpoint = "me/username/validate/\(username)"
101+
let path = self.path(forEndpoint: endpoint, withVersion: ._1_1)
102+
103+
wordPressComRestApi.GET(path,
104+
parameters: nil,
105+
success: { responseObject, httpResponse in
106+
// The success block needs to be changed if
107+
// any allowed_actions is required
108+
// by the changeUsername API
109+
success()
110+
},
111+
failure: { error, httpResponse in
112+
failure(error)
113+
})
114+
}
115+
93116
public func suggestUsernames(base: String, finished: @escaping ([String]) -> Void) {
94117
let endpoint = "wpcom/v2/users/username/suggestions"
95118
let parameters = ["name": base]
@@ -131,6 +154,7 @@ public class AccountSettingsRemote: ServiceRemoteWordPressComREST {
131154
let displayName = response["display_name"] as? String,
132155
let aboutMe = response["description"] as? String,
133156
let username = response["user_login"] as? String,
157+
let usernameCanBeChanged = response["user_login_can_be_changed"] as? Bool,
134158
let email = response["user_email"] as? String,
135159
let emailPendingAddress = response["new_user_email"] as? String?,
136160
let emailPendingChange = response["user_email_change_pending"] as? Bool,
@@ -149,6 +173,7 @@ public class AccountSettingsRemote: ServiceRemoteWordPressComREST {
149173
displayName: displayName,
150174
aboutMe: aboutMeText!,
151175
username: username,
176+
usernameCanBeChanged: usernameCanBeChanged,
152177
email: email,
153178
emailPendingAddress: emailPendingAddress,
154179
emailPendingChange: emailPendingChange,

WordPressKitTests/AccountSettingsRemoteTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class AccountSettingsRemoteTests: RemoteTestCase, RESTTestable {
6262
stubRemoteResponse(meSettingsEndpoint, filename: getAccountSettingsSuccessMockFilename, contentType: .ApplicationJSON)
6363
remote.getSettings(success: { settings in
6464
XCTAssertEqual(settings.username, self.username, "The usernames should be equal.")
65+
XCTAssertEqual(settings.usernameCanBeChanged, false, "The usernames can't be changed and its value must be false")
6566
XCTAssertEqual(settings.email, self.email, "The email addresses should be equal.")
6667
XCTAssertEqual(settings.webAddress, self.userURL, "The web addresses should be equal.")
6768
XCTAssertEqual(settings.primarySiteID, self.siteID, "The primary site ID's should be equal.")

0 commit comments

Comments
 (0)