summaryrefslogtreecommitdiff
path: root/Juick/Message.m
blob: f6fae85cacf2cf55679b46260d7dd69b0f7e030a (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
//
//  Message.m
//  Juick
//
//  Created by Vitaly Takmazov on 29.10.13.
//  Copyright (c) 2013 com.juick. All rights reserved.
//

#import "Message.h"

@implementation Message


+(void) pullNextFromURL:(NSURL *)url callback:(void(^)(NSArray *))callback {
    RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Message class]];
    [mapping addAttributeMappingsFromDictionary:@
    {
        @"user.uname": @"user",
        @"user.uid" : @"userID",
        @"body" : @"text",
        @"mid" : @"MID",
        @"rid" : @"RID",
        @"tags" : @"tags"
    }];
    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping method:RKRequestMethodAny pathPattern:nil keyPath:nil statusCodes:nil];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    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];    
}

@end