Commit 30e9bfe4 authored by Jose Blaya's avatar Jose Blaya
Browse files

Get account information without refresh the token

parent 5d20258e
......@@ -62,6 +62,16 @@ public protocol AccountProvider: class {
*/
func refreshAccountInfo(force: Bool, _ callback: LibraryCallback<AccountInfo>?)
/**
Retrieves information associated with the account currently logged in.
- Precondition: `isLoggedIn` is `true`.
- Postcondition:
- Posts `Notification.Name.PIAAccountDidRefresh` on success.
- Parameter callback: Returns a refreshed `AccountInfo`.
*/
func accountInformation(_ callback: ((AccountInfo?, Error?) -> Void)?)
/**
Updates the account currently logged in.
......
......@@ -215,6 +215,14 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
}
public func accountInformation(_ callback: ((AccountInfo?, Error?) -> Void)?) {
guard let token = self.token else {
callback?(nil, ClientError.unauthorized)
return
}
accountInfoWith(token, callback)
}
private func accountInfoWith(_ token: String, _ callback: ((AccountInfo?, Error?) -> Void)?) {
webServices.info(token: token) { (accountInfo, error) in
guard let accountInfo = accountInfo else {
......
......@@ -164,6 +164,15 @@ public class MockAccountProvider: AccountProvider, WebServicesConsumer {
delegate.refreshAccountInfo(force: false, callback)
}
/// :nodoc:
public func accountInformation(_ callback: ((AccountInfo?, Error?) -> Void)?) {
guard !mockIsUnauthorized else {
callback?(nil, ClientError.unauthorized)
return
}
delegate.accountInformation(callback)
}
/// :nodoc:
public func update(with request: UpdateAccountRequest, andPassword password: String, _ callback: LibraryCallback<AccountInfo>?) {
delegate.update(with: request, andPassword: password, callback)
......
......@@ -368,6 +368,10 @@ class EphemeralAccountProvider: AccountProvider, ProvidersAccess, InAppAccess {
fatalError("Not implemented")
}
func accountInformation(_ callback: ((AccountInfo?, Error?) -> Void)?) {
fatalError("Not implemented")
}
func update(with request: UpdateAccountRequest, andPassword password: String, _ callback: ((AccountInfo?, Error?) -> Void)?) {
fatalError("Not implemented")
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment