1
This commit is contained in:
@@ -7,8 +7,41 @@
|
||||
|
||||
#import "KBMyVM.h"
|
||||
#import "AppDelegate.h"
|
||||
#import "KBNetworkManager.h"
|
||||
#import "KBUser.h"
|
||||
|
||||
@implementation KBMyVM
|
||||
|
||||
- (void)fetchUserDetailWithCompletion:(KBMyUserDetailCompletion)completion {
|
||||
[KBHUD show];
|
||||
[[KBNetworkManager shared] GET:KB_API_USER_DETAIL
|
||||
parameters:nil
|
||||
headers:nil
|
||||
autoShowBusinessError:NO
|
||||
completion:^(NSDictionary *jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
[KBHUD dismiss];
|
||||
|
||||
if (error) {
|
||||
NSString *msg = KBBizMessageFromJSONObject(jsonOrData) ?: error.localizedDescription ?: KBLocalized(@"Network error");
|
||||
[KBHUD showInfo:msg];
|
||||
if (completion) completion(nil, error);
|
||||
return;
|
||||
}
|
||||
|
||||
id dataObj = jsonOrData[KBData] ?: jsonOrData[@"data"];
|
||||
if (![dataObj isKindOfClass:[NSDictionary class]]) {
|
||||
NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain
|
||||
code:KBNetworkErrorInvalidResponse
|
||||
userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Invalid response")}];
|
||||
[KBHUD showInfo:e.localizedDescription];
|
||||
if (completion) completion(nil, e);
|
||||
return;
|
||||
}
|
||||
|
||||
KBUser *user = [KBUser mj_objectWithKeyValues:(NSDictionary *)dataObj];
|
||||
if (completion) completion(user, nil);
|
||||
}];
|
||||
}
|
||||
- (void)logout{
|
||||
[KBHUD show];
|
||||
[[KBNetworkManager shared] GET:API_LOGOUT
|
||||
|
||||
Reference in New Issue
Block a user