blob: 5ba12d2c3c9b0737a054e17112b5ad2fbd47cdcf (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
//
// 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
|