| 148 | | [request addValue:@"WSSE profile=\"UsernameToken\"" forHTTPHeaderField:@"Authorization"]; |
| 149 | | NSString *wsse = [NSString stringWithFormat:@"UsernameToken Username=\"%@\", PasswordDigest=\"%@\", Created=\"%@\", Nonce=\"%@\"", login, passwordDigest, created, encodedNonce]; |
| 150 | | // NSLog(@"X-WSSE set as '%@'\n", wsse); |
| 151 | | [request addValue:wsse forHTTPHeaderField:@"X-WSSE"]; |
| | 157 | // set auth if we need it. |
| | 158 | if ([self requiresAuth]) { |
| | 159 | NSLog(@" XXX Auth required\n"); |
| | 160 | NSString *login = [self authuser]; |
| | 161 | NSString *password = [self authpass]; |
| | 162 | NSString *nonce = [self makeNonce]; |
| | 163 | NSString *encodedNonce = [nonce stringUsingBase64Encoding]; |
| | 164 | NSString *created = [[NSDate date] descriptionWithCalendarFormat:@"%Y-%m-%dT%H:%M:%SZ" timeZone:nil locale:nil]; |
| | 165 | NSString *passwordDigest = [[[NSString stringWithFormat:@"%@%@%@", nonce, created, password] stringUsingSHA1RawHash] stringUsingBase64Encoding]; |
| | 166 | [request addValue:@"WSSE profile=\"UsernameToken\"" forHTTPHeaderField:@"Authorization"]; |
| | 167 | NSString *wsse = [NSString stringWithFormat:@"UsernameToken Username=\"%@\", PasswordDigest=\"%@\", Created=\"%@\", Nonce=\"%@\"", login, passwordDigest, created, encodedNonce]; |
| | 168 | [request addValue:wsse forHTTPHeaderField:@"X-WSSE"]; |
| | 169 | } |
| 171 | | // [self setfile:@"/path/to/file"]; |
| 172 | | // [self newpost:@"gallery"]; |
| 173 | | - (void) newpost:(NSString *) to args:(NSMutableDictionary *) args { |
| 174 | | /* NSLog(@"-(void) newpost:(NSString *)to - called\n"); */ |
| 175 | | NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; |
| 176 | | NSString *reqtype; |
| 177 | | if ([to isEqualToString:@"weblog"] || [to isEqualToString:@"0"]) { |
| 178 | | /* NSLog(@"set as weblog post type\n"); */ |
| 179 | | reqtype = @"POST"; |
| 180 | | [self setApiurl:[NSString stringWithFormat:@"%@weblog/blog_id=%@",@"http://www.typepad.com/t/atom/", [userDefaults objectForKey:@"selectedweblog"]]]; |
| 181 | | [self weblog_upload: dataarg]; |
| 182 | | } |
| 183 | | if ([to isEqualToString:@"gallery"] || [to isEqualToString:@"1"]) { |
| 184 | | /* NSLog(@"set as gallery post type\n"); */ |
| 185 | | reqtype = @"POST"; |
| 186 | | [self setApiurl:[NSString stringWithFormat:@"%@gallery/set_id=%@", @"http://www.typepad.com/t/atom/", [userDefaults objectForKey:@"selectedgallery"]]]; |
| 187 | | [self gallery_upload: dataarg]; |
| 188 | | } |
| 189 | | if ([to isEqualToString:@"quickpost"] || [to isEqualToString:@"2"]) { |
| 190 | | /* NSLog(@"set as gallery post type\n"); */ |
| 191 | | reqtype = @"POST"; |
| 192 | | [self setApiurl:[NSString stringWithFormat:@"%@weblog/blog_id=%@", @"http://www.typepad.com/t/atom/", [userDefaults objectForKey:@"selectedweblog"]]]; |
| 193 | | [self weblog_newpost:@"Quick Post" content:dataarg]; |
| 194 | | } |
| 195 | | if ([to isEqualToString:@"weblogdiscovery"] || [to isEqualToString:@"3"]) { |
| 196 | | /* NSLog(@"set as gallery post type\n"); */ |
| 197 | | reqtype = @"GET"; |
| 198 | | [self setApiurl:[NSString stringWithFormat:@"%@weblog", @"http://www.typepad.com/t/atom/"]]; |
| 199 | | [self weblog_discover]; |
| 200 | | } |
| 201 | | if ([to isEqualToString:@"categorydiscovery"] || [to isEqualToString:@"4"]) { |
| 202 | | /* NSLog(@"set as gallery post type\n"); */ |
| 203 | | reqtype = @"GET"; |
| 204 | | [self setApiurl:[NSString stringWithFormat:@"%@categories/blog_id=%@", @"http://www.typepad.com/t/atom/", [args objectForKey:@"blog_id"] ]]; |
| 205 | | [self weblog_discover]; |
| 206 | | } |
| 207 | | if ([to isEqualToString:@"gallerydiscovery"] || [to isEqualToString:@"5"]) { |
| 208 | | /* NSLog(@"set as gallery post type\n"); */ |
| 209 | | reqtype = @"GET"; |
| 210 | | [self setApiurl:[NSString stringWithFormat:@"%@gallery", @"http://www.typepad.com/t/atom/"]]; |
| 211 | | [self weblog_discover]; |
| 212 | | } |
| 213 | | /* NSLog(@"Making request with request type %@\n", reqtype); */ |
| 214 | | [self makerequest:reqtype]; |
| 215 | | } |
| 216 | | |
| 217 | | - (NSString *) gallery_upload: (NSString *) file { |
| 218 | | /* NSLog(@"- (NSString *) gallery_newitem - called"); */ |
| 219 | | NSData *data = [NSData dataWithContentsOfFile:file]; |
| 220 | | NSString *encodedFile = [data base64Encoding]; |
| 221 | | atomdata = [NSString stringWithFormat:@"<entry xmlns=\"http://purl.org/atom/ns#\" xmlns:photo=\"http://sixapart.com/atom/photo#\"><title>%@</title><summary></summary><content mode=\"base64\" type=\"image/%@\">%@</content></entry>", [file lastPathComponent], [file pathExtension], encodedFile]; |
| 222 | | return atomdata; |
| 223 | | } |
| 224 | | |
| 225 | | - (NSString *) weblog_upload: (NSString *) file { |
| 226 | | /* NSLog(@"- (NSString *) weblog_newitem - called"); */ |
| 227 | | /* NSLog(@"Creating atom feed based on upload file %@\n", uploadfile); */ |
| 228 | | NSData *data = [NSData dataWithContentsOfFile:file]; |
| 229 | | NSString *encodedFile = [data base64Encoding]; |
| 230 | | atomdata = [NSString stringWithFormat:@"<entry xmlns=\"http://purl.org/atom/ns#\" xmlns:photo=\"http://sixapart.com/atom/photo#\"><title>Picture Post</title><summary></summary><photo:filename>%@</photo:filename><content mode=\"base64\" type=\"image/%@\">%@</content></entry>",[file lastPathComponent], [file pathExtension], encodedFile]; |
| 231 | | /* NSLog(@"Atom feed:\n%@\n", atomdata); */ |
| 232 | | return atomdata; |
| 233 | | } |
| 234 | | |
| 235 | | - (NSString *) weblog_newpost: (NSString *) title content: (NSString *) content { |
| 236 | | /* NSLog(@"- (NSString *) weblog_newitem - called"); */ |
| 237 | | /* NSLog(@"Creating atom feed based on upload file %@\n", uploadfile); */ |
| 238 | | atomdata = [NSString stringWithFormat:@"<entry xmlns=\"http://purl.org/atom/ns#\"><title>%@</title><summary></summary><content mode=\"xml\"><div xmlns=\"http://www.w3.org/1999/xhtml\">%@</div></content>%@</entry>", title, content, [self weblog_postcategories]]; |
| 239 | | /* NSLog(@"Atom feed:\n%@\n", atomdata); */ |
| 240 | | return atomdata; |
| 241 | | } |
| 242 | | |
| 243 | | - (NSString *) weblog_discover { |
| 244 | | /* NSLog(@"- (NSString *) weblog_newitem - called"); */ |
| 245 | | /* NSLog(@"Creating atom feed based on upload file %@\n", uploadfile); */ |
| 246 | | /* atomdata = [NSString stringWithFormat:@"<entry xmlns=\"http://purl.org/atom/ns#\"><title>%@</title><summary></summary><content mode=\"xml\"><div xmlns=\"http://www.w3.org/1999/xhtml\">%@</div></content></entry>", title, content]; */ |
| 247 | | atomdata = @""; |
| 248 | | /* NSLog(@"Atom feed:\n%@\n", atomdata); */ |
| 249 | | return @""; |
| 250 | | } |
| 251 | | |
| 252 | | - (NSString *) weblog_postcategories { |
| 253 | | NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; |
| 254 | | NSArray *lines = [[userDefaults objectForKey:@"blogcategories"] componentsSeparatedByString:@","]; |
| 255 | | int i, count = [lines count]; |
| 256 | | NSString *output = @""; |
| 257 | | for (i = 0; i < count; i++) { |
| 258 | | [output stringByAppendingString:[NSString stringWithFormat:@"<category scheme=\"http://sixapart.com/ns/category#\" term\"%@\" />", [lines objectAtIndex:i]]]; |
| 259 | | } |
| 260 | | return output; |
| 261 | | } |
| 262 | | |
| 263 | | |