// // Message.m // Juick // // Created by Vitaly Takmazov on 29.10.13. // Copyright (c) 2013 com.juick. All rights reserved. // #import "Message.h" #import "PDKeychainBindings.h" @implementation Message +(void) pullNextFromPath:(NSString *)path params:(NSDictionary *) params callback:(void(^)(NSArray *))callback { 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"]]; } 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) { NSLog(@"REST Error: %@", error); }]; [operation start]; } +(NSString *) messagesUrl { return @"https://api.juick.com/messages"; } +(NSString *) threadUrl { return @"https://api.juick.com/thread"; } +(NSString *) feedUrl { return @"https://api.juick.com/home"; } @end