root/trunk/TypePadAtomAPI.m @ 41

Revision 41, 5.3 kB (checked in by ngerakines, 3 years ago)

* Put into place the real icons that Wiley sent over
* Fixed the prefs on login
* Removed the TypePadSuper class
* General code cleanup

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        if ([to isEqualToString:@"commentlist"] || [to isEqualToString:@"6"]) {
56                // NSLog(@"set as gallerydiscovery post type\n");
57                reqtype = @"GET";
58                [self setApiurl:[NSString stringWithFormat:@"%@comments/blog_id=%@", @"http://www.typepad.com/t/atom/", [args objectForKey:@"blog_id"]]];
59                [self weblog_discover];
60        }
61// NSLog(@"Making request with request type %@\n", reqtype);
62        [self makerequest:reqtype];
63}
64
65- (NSString *) gallery_upload: (NSString *) file {
66// NSLog(@"- (NSString *) gallery_newitem - called");
67        NSData *data = [NSData dataWithContentsOfFile:file];
68        NSString *encodedFile = [data base64Encoding];
69        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];
70        // NSLog(@"Atom feed:\n%@\n", atomdata);
71        return atomdata;
72}
73
74- (NSString *) weblog_upload: (NSString *) file {
75// NSLog(@"- (NSString *) weblog_upload - called");
76        NSData *data = [NSData dataWithContentsOfFile:file];
77        NSString *encodedFile = [data base64Encoding];
78        // TODO: enable standalone mode - <standalone xmlns=\"http://sixapart.com/atom/typepad#\">1</standalone>
79        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];
80        // NSLog(@"Atom feed:\n%@\n", atomdata);
81        return atomdata;
82}
83
84- (NSString *) weblog_newpost: (NSString *) title content: (NSString *) content {
85// NSLog(@"- (NSString *) weblog_newpost - called");
86        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]];
87        // NSLog(@"Atom feed:\n%@\n", atomdata);
88        return atomdata;
89}
90
91- (NSString *) weblog_discover {
92// NSLog(@"- (NSString *) weblog_newitem - called");
93        /* 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]; */
94        atomdata = @"";
95        // NSLog(@"Atom feed:\n%@\n", atomdata);
96        return @"";
97}
98
99- (NSString *) weblog_postcategories {
100        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
101        NSArray *lines = [[userDefaults objectForKey:@"blogcategories"] componentsSeparatedByString:@","];
102        int i, count = [lines count];
103        NSString *output = @"";
104        for (i = 0; i < count; i++) {
105                [output stringByAppendingString:[NSString stringWithFormat:@"<category scheme=\"http://sixapart.com/ns/category#\" term\"%@\" />", [lines objectAtIndex:i]]];
106        }
107        return output;
108}
109
110- (NSString *) comments_get {
111        atomdata = @"";
112        return @"";
113}
114
115@end
Note: See TracBrowser for help on using the browser.