summaryrefslogtreecommitdiff
path: root/Juick/Model/User.m
blob: f5b41f5f0d0bb380e4c060b294aa33b5e647ffd7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
//  User.m
//  Juick
//
//  Created by Vitaly on 01.02.14.
//  Copyright (c) 2014 com.juick. All rights reserved.
//

#import "User.h"
#import "APIClient.h"

@implementation User

+ (User *) fromJSON:(NSDictionary *)jsonData {
    User *user = [User new];
    user.uid = jsonData[@"uid"];
    user.uname = jsonData[@"uname"];
    user.avatar = jsonData[@"avatar"];
    user.unreadCount = [jsonData[@"messagesCount"] integerValue];
    return user;
}

+(void) throwUnableToLogin:(UIViewController *)view error:(NSError *)error {
    UIAlertController *alert = [UIAlertController new];
    [alert setTitle:@"Something went wrong"];
    [alert setMessage:error.localizedDescription];
    [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]];
    UIPopoverPresentationController *popover = [alert popoverPresentationController];
    if (popover) {
        popover.sourceView = view.view;
        popover.sourceRect = CGRectMake(CGRectGetMidX(view.view.bounds), CGRectGetMidY(view.view.bounds), 0, 0);
        popover.permittedArrowDirections = UIPopoverArrowDirectionDown;
    }
    [view presentViewController:alert animated:YES completion:nil];
}

@end