-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.m
More file actions
44 lines (31 loc) · 1.48 KB
/
main.m
File metadata and controls
44 lines (31 loc) · 1.48 KB
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
// © 2010 Mirek Rusin
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
#import <Foundation/Foundation.h>
#import "NSMutableDictionary+REST.h"
@interface UserPrinter : NSObject
@end
@implementation UserPrinter
- (void) didFinishElement: (id) element withPath: (NSString *) path {
if ([path isEqualToString: @"/users/user"]) {
NSDictionary *user = (NSDictionary *)element;
printf("- %s (%s)\n", [[user objectForKey: @"fullname"] UTF8String],
[[user objectForKey: @"username"] UTF8String]);
}
}
@end
int main(int argc, char** argv) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *stringUrl = @"http://github.com/api/v2/xml/user/search/mirek";
NSURL *url = [NSURL URLWithString: stringUrl];
// Delegate gets objects asynchronously and the method returns synchronously
NSMutableDictionary *users = [NSMutableDictionary dictionaryWithRESTContentsOfURL: url
delegate: [[UserPrinter alloc] init]];
printf("Total users: %i\n", (int)[[users objectForKey: @"users"] count]);
id user = [[users objectForKey: @"users"] objectAtIndex: 0];
NSData *responseData = [user postRESTWithURL: @"http://localhost:3100/raw_post"];
printf("%s\n", [[[NSString alloc] initWithData: responseData
encoding: NSUTF8StringEncoding] UTF8String]),
[pool drain];
return 0;
}