root/trunk/TypePadAtomAPI.m @ 35

Revision 35, 4.9 kB (checked in by ngerakines, 3 years ago)

Fixing what I broke in the last checkin -- removed url drag support -- added VoxAccount and VoxCollection classes and gut code

Line 
1//
2//  TypePadAtomAPI.m
3//  Fence
4//
5//  Created by Nicholas Gerakines on 6/11/06.
6//  Copyright 2006 __MyCompanyName__. All rights reserved.
7//
8
9#import "TypePadAtomAPI.h"
10#import "AtomExtensions.h"
11#import "NSDataAdditions.h"
12
13@implementation TypePadAtomAPI
14
15- (void) newpost:(NSString *) to args:(NSMutableDictionary *) args {
16        NSLog(@"-(void) newpost:(NSString *)to - called\n");
17        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
18        NSString *reqtype;
19        if ([to isEqualToString:@"weblog"] || [to isEqualToString:@"0"]) {
20                NSLog(@"set as weblog post type\n");
21                reqtype = @"POST";
22                [self setApiurl:[NSString stringWithFormat:@"%@weblog/blog_id=%@",@"http://www.typepad.com/t/atom/", [args objectForKey:@"destinationid"]]];
23                [self weblog_upload: dataarg];
24        }
25        if ([to isEqualToString:@"gallery"] || [to isEqualToString:@"1"]) {
26                NSLog(@"set as gallery post type\n");
27                reqtype = @"POST";
28                [self setApiurl:[NSString stringWithFormat:@"%@gallery/set_id=%@", @"http://www.typepad.com/t/atom/", [args objectForKey:@"destinationid"]]];
29                [self gallery_upload: dataarg];
30        }
31        if ([to isEqualToString:@"quickpost"] || [to isEqualToString:@"2"]) {
32                NSLog(@"set as quickpost post type\n");
33                reqtype = @"POST";
34                [self setApiurl:[NSString stringWithFormat:@"%@weblog/blog_id=%@", @"http://www.typepad.com/t/atom/", [args objectForKey:@"destinationid"]]];
35                [self weblog_newpost:@"Quick Post" content:dataarg];
36        }
37        if ([to isEqualToString:@"weblogdiscovery"] || [to isEqualToString:@"3"]) {
38                NSLog(@"set as weblogdiscovery post type\n");
39                reqtype = @"GET";
40                [self setApiurl:[NSString stringWithFormat:@"%@weblog", @"http://www.typepad.com/t/atom/"]];
41                [self weblog_discover];
42        }
43        if ([to isEqualToString:@"categorydiscovery"] || [to isEqualToString:@"4"]) {
44                NSLog(@"set as categorydiscovery post type\n");
45                reqtype = @"GET";
46                [self setApiurl:[NSString stringWithFormat:@"%@categories/blog_id=%@", @"http://www.typepad.com/t/atom/", [args objectForKey:@"blog_id"] ]];
47                [self weblog_discover];
48        }
49        if ([to isEqualToString:@"gallerydiscovery"] || [to isEqualToString:@"5"]) {
50                NSLog(@"set as gallerydiscovery post type\n");
51                reqtype = @"GET";
52                [self setApiurl:[NSString stringWithFormat:@"%@gallery", @"http://www.typepad.com/t/atom/"]];
53                [self weblog_discover];
54        }
55        NSLog(@"Making request with request type %@\n", reqtype);
56        [self makerequest:reqtype];
57}
58
59- (NSString *) gallery_upload: (NSString *) file {
60        NSLog(@"- (NSString *) gallery_newitem - called");
61        NSData *data = [NSData dataWithContentsOfFile:file];
62        NSString *encodedFile = [data base64Encoding];
63        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];
64        // NSLog(@"Atom feed:\n%@\n", atomdata);
65        return atomdata;
66}
67
68- (NSString *) weblog_upload: (NSString *) file {
69        NSLog(@"- (NSString *) weblog_upload - called");
70        NSData *data = [NSData dataWithContentsOfFile:file];
71        NSString *encodedFile = [data base64Encoding];
72        // TODO: enable standalone mode - <standalone xmlns=\"http://sixapart.com/atom/typepad#\">1</standalone>
73        atomdata = [NSString stringWithFormat:@"<entry xmlns=\"http://purl.org/atom/ns#\" xmlns:photo=\"http://sixapart.com/atom/photo#\"><title>%@</title><summary></summary><photo:filename>%@</photo:filename><content mode=\"base64\" type=\"image/%@\">%@</content></entry>",[file lastPathComponent],[file lastPathComponent], [file pathExtension], encodedFile];
74        // NSLog(@"Atom feed:\n%@\n", atomdata);
75        return atomdata;
76}
77
78- (NSString *) weblog_newpost: (NSString *) title content: (NSString *) content {
79        NSLog(@"- (NSString *) weblog_newpost - called");
80        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]];
81        // NSLog(@"Atom feed:\n%@\n", atomdata);
82        return atomdata;
83}
84
85- (NSString *) weblog_discover {
86        NSLog(@"- (NSString *) weblog_newitem - called");
87        /* 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]; */
88        atomdata = @"";
89        // NSLog(@"Atom feed:\n%@\n", atomdata);
90        return @"";
91}
92
93- (NSString *) weblog_postcategories {
94        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
95        NSArray *lines = [[userDefaults objectForKey:@"blogcategories"] componentsSeparatedByString:@","];
96        int i, count = [lines count];
97        NSString *output = @"";
98        for (i = 0; i < count; i++) {
99                [output stringByAppendingString:[NSString stringWithFormat:@"<category scheme=\"http://sixapart.com/ns/category#\" term\"%@\" />", [lines objectAtIndex:i]]];
100        }
101        return output;
102}
103
104@end
Note: See TracBrowser for help on using the browser.