diff options
Diffstat (limited to 'Juick/Model')
-rw-r--r-- | Juick/Model/DeviceRegistration.h | 9 | ||||
-rw-r--r-- | Juick/Model/DeviceRegistration.m | 19 | ||||
-rw-r--r-- | Juick/Model/User.h | 4 | ||||
-rw-r--r-- | Juick/Model/User.m | 22 |
4 files changed, 19 insertions, 35 deletions
diff --git a/Juick/Model/DeviceRegistration.h b/Juick/Model/DeviceRegistration.h index d5b620c..bd786ef 100644 --- a/Juick/Model/DeviceRegistration.h +++ b/Juick/Model/DeviceRegistration.h @@ -14,12 +14,3 @@ -(NSDictionary *) toJSON; @end - -@implementation DeviceRegistration --(NSDictionary *) toJSON { - return @{ - @"type": self.type, - @"token": self.token - }; -} -@end diff --git a/Juick/Model/DeviceRegistration.m b/Juick/Model/DeviceRegistration.m new file mode 100644 index 0000000..c1728f4 --- /dev/null +++ b/Juick/Model/DeviceRegistration.m @@ -0,0 +1,19 @@ +// +// DeviceRegistration.m +// Juick +// +// Created by Vitaly Takmazov on 20/03/2019. +// Copyright © 2019 com.juick. All rights reserved. +// + +#import <Foundation/Foundation.h> +#import "DeviceRegistration.h" + +@implementation DeviceRegistration +-(NSDictionary *) toJSON { + return @{ + @"type": self.type, + @"token": self.token + }; +} +@end diff --git a/Juick/Model/User.h b/Juick/Model/User.h index 59b010d..92a6333 100644 --- a/Juick/Model/User.h +++ b/Juick/Model/User.h @@ -15,12 +15,8 @@ + (User *) fromJSON:(NSDictionary *)jsonData; -+ (void) get:(NSString *)name callback:(void(^)(User *))callback; - + (BOOL) isAuthenticated; -+ (void) checkIsValid:(void(^)(BOOL))callback; - + (void) throwUnableToLogin:(UIViewController *)view; @end diff --git a/Juick/Model/User.m b/Juick/Model/User.m index 7f97e34..6d5e818 100644 --- a/Juick/Model/User.m +++ b/Juick/Model/User.m @@ -38,26 +38,4 @@ [view presentViewController:alert animated:YES completion:nil]; } -+(void) checkIsValid:(void (^)(BOOL))callback { - AFHTTPSessionManager *manager = [APIClient sharedClient].manager; - [manager POST:@"post" parameters:nil progress:nil success:nil failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { - NSInteger statusCode = ((NSHTTPURLResponse *)task.response).statusCode; - if (statusCode == 400) { - callback(YES); - } else { - [manager.requestSerializer clearAuthorizationHeader]; - callback(NO); - } - }];} - -+(void) get:(NSString *) name callback:(void(^)(User *))callback { - AFHTTPSessionManager *manager = [APIClient sharedClient].manager; - NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:name, @"uname", nil]; - [manager GET:@"users" parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { - callback([User fromJSON:[(NSArray *)responseObject firstObject]]); - } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { - callback(nil); - }]; -} - @end |