diff options
Diffstat (limited to 'Juick/Message.m')
-rw-r--r-- | Juick/Message.m | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/Juick/Message.m b/Juick/Message.m index 5ba12d2..de08e98 100644 --- a/Juick/Message.m +++ b/Juick/Message.m @@ -11,37 +11,30 @@ @implementation Message ++ (NSDictionary *)modelCustomPropertyMapper { + return @{@"text" : @"body", + @"MID" : @"mid", + @"RID" : @"rid", + @"attach" : @"photo.small", + @"repliesCount": @"replies", + @"repliesBy": @"repliesby"}; +} + +(void) pullNextFromPath:(NSString *)path params:(NSDictionary *) params callback:(void(^)(NSArray *))callback { + AFHTTPSessionManager *manager = [APIClient sharedClient].manager; if ([[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] != nil) { - RKObjectManager *manager = [RKObjectManager sharedManager]; - [manager.HTTPClient setAuthorizationHeaderWithUsername:[[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] password:[[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.password"]]; + [manager.requestSerializer setAuthorizationHeaderFieldWithUsername:[[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] password:[[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.password"]]; } - RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Message class]]; - [mapping addAttributeMappingsFromDictionary:@ - { - @"user.uname": @"user", - @"user.uid" : @"userID", - @"body" : @"text", - @"mid" : @"MID", - @"rid" : @"RID", - @"tags" : @"tags", - @"timestamp" : @"timestamp", - @"photo.small" : @"attach", - @"replies" : @"repliesCount", - @"repliesby": @"repliesBy" - - }]; - RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping method:RKRequestMethodAny pathPattern:nil keyPath:nil statusCodes:nil]; - NSURLRequest *request = [[RKObjectManager sharedManager] requestWithObject:nil method:RKRequestMethodGET path:path parameters:params]; - RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request - responseDescriptors:@[responseDescriptor]]; - [operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { - callback([mappingResult array]); - } failure:^(RKObjectRequestOperation *operation, NSError *error) { + [manager GET:path parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + NSMutableArray *messages = [NSMutableArray new]; + [((NSArray *)responseObject) enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + [messages addObject:[Message yy_modelWithJSON:obj]]; + }]; + callback(messages); + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"REST Error: %@", error); }]; - [operation start]; } +(NSString *) messagesUrl { |