Revision 3ebe9884 asi-http-request-with-pithos/Classes/Pithos/ASIPithosRequest.m
b/asi-http-request-with-pithos/Classes/Pithos/ASIPithosRequest.m | ||
---|---|---|
38 | 38 |
#import "ASIPithosRequest.h" |
39 | 39 |
#import "ASIPithos.h" |
40 | 40 |
#import "ASIPithosAccount.h" |
41 |
#import "SBJson.h" |
|
41 | 42 |
|
42 | 43 |
@implementation ASIPithosRequest |
43 | 44 |
@synthesize currentElement, currentContent, currentAccount; |
... | ... | |
100 | 101 |
} |
101 | 102 |
|
102 | 103 |
#pragma mark - |
104 |
#pragma mark User Catalog |
|
105 |
|
|
106 |
// POST userCatalogURL |
|
107 |
+ (id)userCatalogRequestWithPithos:(ASIPithos *)pithos displaynames:(NSArray *)displaynames UUIDs:(NSArray *)UUIDs { |
|
108 |
NSString *urlString = [NSString stringWithString:pithos.userCatalogURL]; |
|
109 |
|
|
110 |
ASIPithosRequest *request = [self requestWithURL:[NSURL URLWithString:urlString]]; |
|
111 |
[request setRequestMethod:@"POST"]; |
|
112 |
[request addRequestHeader:@"X-Auth-Token" value:pithos.authToken]; |
|
113 |
[request addRequestHeader:@"Content-Type" value:@"application/json"]; |
|
114 |
|
|
115 |
NSMutableString *dataString = [NSMutableString stringWithString:@"{\"displaynames\":["]; |
|
116 |
if (displaynames) { |
|
117 |
for (NSUInteger index = 0 ; index < displaynames.count ; index++) { |
|
118 |
[dataString appendFormat:@"\"%@\"%@", |
|
119 |
[[[displaynames objectAtIndex:index] stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"] |
|
120 |
stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""], |
|
121 |
((index == displaynames.count - 1) ? @"" : @",")]; |
|
122 |
} |
|
123 |
} |
|
124 |
[dataString appendFormat:@"],\"uuids\":["]; |
|
125 |
if (UUIDs) { |
|
126 |
for (NSUInteger index = 0 ; index < UUIDs.count ; index++) { |
|
127 |
[dataString appendFormat:@"\"%@\"%@", [UUIDs objectAtIndex:index], ((index == UUIDs.count - 1) ? @"" : @",")]; |
|
128 |
} |
|
129 |
} |
|
130 |
[dataString appendFormat:@"]}"]; |
|
131 |
[request appendPostData:[dataString dataUsingEncoding:NSUTF8StringEncoding]]; |
|
132 |
|
|
133 |
return request; |
|
134 |
} |
|
135 |
|
|
136 |
- (NSDictionary *)catalogs { |
|
137 |
SBJsonParser *parser = [[SBJsonParser alloc] init]; |
|
138 |
NSDictionary *catalogs = [parser objectWithString:[self responseString]]; |
|
139 |
return catalogs; |
|
140 |
} |
|
141 |
|
|
142 |
- (NSDictionary *)displaynameCatalog { |
|
143 |
return [[self catalogs] objectForKey:@"displayname_catalog"]; |
|
144 |
} |
|
145 |
|
|
146 |
- (NSDictionary *)UUIDCatalog { |
|
147 |
return [[self catalogs] objectForKey:@"uuid_catalog"]; |
|
148 |
} |
|
149 |
|
|
150 |
#pragma mark - |
|
103 | 151 |
#pragma mark GET |
104 | 152 |
|
105 | 153 |
// GET authURL |
Also available in: Unified diff