Skip to content

Commit d08a28b

Browse files
committed
Copy WordPressKit source code
1 parent e5759b3 commit d08a28b

File tree

312 files changed

+33602
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

312 files changed

+33602
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import Foundation
2+
3+
@frozen public enum SocialServiceName: String {
4+
case google
5+
case apple
6+
}
7+
8+
extension AccountServiceRemoteREST {
9+
10+
/// Connect to the specified social service via its OpenID Connect (JWT) token.
11+
///
12+
/// - Parameters:
13+
/// - service The name of the social service.
14+
/// - token The OpenID Connect (JWT) ID token identifying the user on the social service.
15+
/// - connectParameters Dictionary containing additional endpoint parameters. Currently only used for the Apple service.
16+
/// - oAuthClientID The WPCOM REST API client ID.
17+
/// - oAuthClientSecret The WPCOM REST API client secret.
18+
/// - success The block that will be executed on success.
19+
/// - failure The block that will be executed on failure.
20+
public func connectToSocialService(_ service: SocialServiceName,
21+
serviceIDToken token: String,
22+
connectParameters: [String: AnyObject]? = nil,
23+
oAuthClientID: String,
24+
oAuthClientSecret: String,
25+
success: @escaping (() -> Void),
26+
failure: @escaping ((Error) -> Void)) {
27+
let path = self.path(forEndpoint: "me/social-login/connect", withVersion: ._1_1)
28+
29+
var params = [
30+
"client_id": oAuthClientID,
31+
"client_secret": oAuthClientSecret,
32+
"service": service.rawValue,
33+
"id_token": token
34+
] as [String: AnyObject]
35+
36+
if let connectParameters = connectParameters {
37+
params.merge(connectParameters, uniquingKeysWith: { (current, _) in current })
38+
}
39+
40+
wordPressComRESTAPI.post(path, parameters: params, success: { (_, _) in
41+
success()
42+
}, failure: { (error, _) in
43+
failure(error)
44+
})
45+
}
46+
47+
/// Get Apple connect parameters from provided account information.
48+
///
49+
/// - Parameters:
50+
/// - email Email from Apple account.
51+
/// - fullName User's full name from Apple account.
52+
/// - Returns: Dictionary with endpoint parameters, to be used when connecting to social service.
53+
static public func appleSignInParameters(email: String, fullName: String) -> [String: AnyObject] {
54+
return [
55+
"user_email": email as AnyObject,
56+
"user_name": fullName as AnyObject
57+
]
58+
}
59+
60+
/// Disconnect fromm the specified social service.
61+
///
62+
/// - Parameters:
63+
/// - service The name of the social service.
64+
/// - oAuthClientID The WPCOM REST API client ID.
65+
/// - oAuthClientSecret The WPCOM REST API client secret.
66+
/// - success The block that will be executed on success.
67+
/// - failure The block that will be executed on failure.
68+
public func disconnectFromSocialService(_ service: SocialServiceName, oAuthClientID: String, oAuthClientSecret: String, success: @escaping(() -> Void), failure: @escaping((Error) -> Void)) {
69+
let path = self.path(forEndpoint: "me/social-login/disconnect", withVersion: ._1_1)
70+
let params = [
71+
"client_id": oAuthClientID,
72+
"client_secret": oAuthClientSecret,
73+
"service": service.rawValue
74+
] as [String: AnyObject]
75+
76+
wordPressComRESTAPI.post(path, parameters: params, success: { (_, _) in
77+
success()
78+
}, failure: { (error, _) in
79+
failure(error)
80+
})
81+
}
82+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import Foundation
2+
3+
public struct AccountSettings {
4+
// MARK: - My Profile
5+
public let firstName: String // first_name
6+
public let lastName: String // last_name
7+
public let displayName: String // display_name
8+
public let aboutMe: String // description
9+
10+
// MARK: - Account Settings
11+
public let username: String // user_login
12+
public let usernameCanBeChanged: Bool // user_login_can_be_changed
13+
public let email: String // user_email
14+
public let emailPendingAddress: String? // new_user_email
15+
public let emailPendingChange: Bool // user_email_change_pending
16+
public let primarySiteID: Int // primary_site_ID
17+
public let webAddress: String // user_URL
18+
public let language: String // language
19+
public let tracksOptOut: Bool
20+
public let blockEmailNotifications: Bool
21+
public let twoStepEnabled: Bool // two_step_enabled
22+
23+
public init(firstName: String,
24+
lastName: String,
25+
displayName: String,
26+
aboutMe: String,
27+
username: String,
28+
usernameCanBeChanged: Bool,
29+
email: String,
30+
emailPendingAddress: String?,
31+
emailPendingChange: Bool,
32+
primarySiteID: Int,
33+
webAddress: String,
34+
language: String,
35+
tracksOptOut: Bool,
36+
blockEmailNotifications: Bool,
37+
twoStepEnabled: Bool) {
38+
self.firstName = firstName
39+
self.lastName = lastName
40+
self.displayName = displayName
41+
self.aboutMe = aboutMe
42+
self.username = username
43+
self.usernameCanBeChanged = usernameCanBeChanged
44+
self.email = email
45+
self.emailPendingAddress = emailPendingAddress
46+
self.emailPendingChange = emailPendingChange
47+
self.primarySiteID = primarySiteID
48+
self.webAddress = webAddress
49+
self.language = language
50+
self.tracksOptOut = tracksOptOut
51+
self.blockEmailNotifications = blockEmailNotifications
52+
self.twoStepEnabled = twoStepEnabled
53+
}
54+
}
55+
56+
@frozen public enum AccountSettingsChange {
57+
case firstName(String)
58+
case lastName(String)
59+
case displayName(String)
60+
case aboutMe(String)
61+
case email(String)
62+
case emailRevertPendingChange
63+
case primarySite(Int)
64+
case webAddress(String)
65+
case language(String)
66+
case tracksOptOut(Bool)
67+
68+
var stringValue: String {
69+
switch self {
70+
case .firstName(let value):
71+
return value
72+
case .lastName(let value):
73+
return value
74+
case .displayName(let value):
75+
return value
76+
case .aboutMe(let value):
77+
return value
78+
case .email(let value):
79+
return value
80+
case .emailRevertPendingChange:
81+
return String(false)
82+
case .primarySite(let value):
83+
return String(value)
84+
case .webAddress(let value):
85+
return value
86+
case .language(let value):
87+
return value
88+
case .tracksOptOut(let value):
89+
return String(value)
90+
}
91+
}
92+
}
93+
94+
public typealias AccountSettingsChangeWithString = (String) -> AccountSettingsChange
95+
public typealias AccountSettingsChangeWithInt = (Int) -> AccountSettingsChange

0 commit comments

Comments
 (0)