Skip to content

Commit 076bcd6

Browse files
committed
StoresManager: New Public API
1 parent c34ec08 commit 076bcd6

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

WooCommerce/Classes/Yosemite/StoresManager.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,17 @@ class StoresManager {
4949

5050
/// Switches the internal state to Authenticated.
5151
///
52-
func authenticate(credentials: Credentials, onCompletion: ((Error?) -> Void)? = nil) {
52+
func authenticate(credentials: Credentials) -> StoresManager {
5353
state = AuthenticatedState(credentials: credentials)
5454
sessionManager.defaultCredentials = credentials
5555

56+
return self
57+
}
58+
59+
/// Synchronizes all of the Session's Entities.
60+
///
61+
func synchronizeEntities(onCompletion: ((Error?) -> Void)? = nil) {
62+
synchronizeAccount(onCompletion: onCompletion)
5663
}
5764

5865
/// Switches the state to a Deauthenticated one.
@@ -91,6 +98,19 @@ private extension StoresManager {
9198

9299
dispatch(action)
93100
}
101+
102+
/// Synchronizes the WordPress.com Account, associated with the current credentials.
103+
///
104+
func synchronizeAccount(onCompletion: ((Error?) -> Void)?) {
105+
let action = AccountAction.synchronizeAccount { [weak self] (account, error) in
106+
if let `self` = self, let account = account, self.isAuthenticated {
107+
self.sessionManager.defaultAccount = account
108+
}
109+
110+
onCompletion?(error)
111+
}
112+
113+
dispatch(action)
94114
}
95115
}
96116

0 commit comments

Comments
 (0)