-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPostController.m
149 lines (123 loc) · 5.05 KB
/
PostController.m
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// PostController.m
// Tumblor
//
// Created by orta on 20/07/2008.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "PostController.h"
#import "ORHTTPWrapper.h"
@implementation PostController
-(IBAction) post:(id) sender{
[[NSNotificationCenter defaultCenter] postNotificationName:@"ORDoingNetworkStuffYah" object:self];
switch ([tumblrController currentViewIndex]) {
case 0:
case 2:
case 3:
case 4:
[self postWithType:@"text"];
break;
case 1:
case 5:
case 6:
[self postWithType:@"file"];
break;
default:
log(@"***should not get here");
break;
}
}
-(void) postWithType: (NSString *) postType {
NSString* username = [connectionController email];
NSString* password = [connectionController password];
id <ViewController> currentViewController = [tumblrController currentViewController];
log(@"controller = %@", [currentViewController class]);
NSArray* postTypes = [NSArray arrayWithObjects: @"regular", @"photo", @"quote", @"link", @"conversation", @"audio", @"video" , nil];
NSString* type = [postTypes objectAtIndex:[tumblrController currentViewIndex]];
NSString* generator = @"Tumblg";
NSString* private = @"0";
if([privatePostButton state] == 1) private = @"1";
NSString* tagsAsCSV = [[tagTokenView stringValue] urlEncodeValue];
NSString* group = [blogController group];
NSLog(@"GROUP = %@", group);
NSMutableDictionary * postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
username, @"email",
password, @"password",
type, @"type",
generator, @"generator",
private, @"private",
group, @"group",
tagsAsCSV, @"tags", nil];
log(@"%@ - params from CVC", [currentViewController values]);
[postParams addEntriesFromDictionary: [currentViewController values] ];
[growlController startedPosting];
_HTTPReq = [[ORHTTPRequest alloc] initWithDelegate:self];
_HTTPReq.requestPath = @"http://www.tumblr.com/api/write";
if([postType compare:@"text"] == NSOrderedSame ){
[_HTTPReq postRequestWithParams:postParams];
}
if([postType compare:@"file"] == NSOrderedSame ){
[_HTTPReq multiPartPostRequestWithPath: [postParams objectForKey:@"filepath"] params:postParams];
}
}
//
//-(void) _silentPostWithType: (NSString *) type email: (NSString *)email password:(NSString *)password{
// NSString* username = [connectionController email];
// NSString* password = [connectionController password];
//
// id <ViewController> currentViewController = [tumblrController currentViewController];
//
// log(@"controller = %@", [currentViewController class]);
//
// NSString* generator = @"Tumblg";
//
// NSString* private = @"0";
// if([privatePostButton state] == 1) private = @"1";
//
// NSString* tagsAsCSV = [[tagTokenView stringValue] urlEncodeValue];
// NSString* group = [[groupTextField stringValue] urlEncodeValue];
//
// NSMutableDictionary * postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
// username, @"email",
// password, @"password",
// type, @"type",
// generator, @"generator",
// private, @"private",
// group, @"group",
// tagsAsCSV, @"tags", nil];
// log(@"%@ - params from CVC", [currentViewController values]);
// [postParams addEntriesFromDictionary: [currentViewController values] ];
//
// ORHTTPRequest * httpReq = [[ORHTTPRequest alloc] initWithDelegate:self];
// httpReq.requestPath = @"http://www.tumblr.com/api/write";
//
// if([postType compare:@"text"] == NSOrderedSame ){
// [httpReq postRequestWithParams:postParams];
// }
//
// if([postType compare:@"file"] == NSOrderedSame ){
// [httpReq multiPartPostRequestWithPath: [postParams objectForKey:@"filepath"] params:postParams];
// }
//}
- (void) httpRequest:(ORHTTPRequest *) httpReq ConnectionDidSucceedWithString: (NSString *) data{
log(@"httpReq succeded with string = %@", data);
}
- (void) httpRequest:(ORHTTPRequest *) httpReq connectionDidFailWithResponseCode: (NSString *) code{
log(@"httpRequest connectionDidFailWithResponseCode: %@", code);
if([code compare:@"201"] == NSOrderedSame){
log(@"cool success");
[[NSNotificationCenter defaultCenter] postNotificationName:@"ORPostedSuccessfully" object:code];
[growlController postSuccess];
id <ViewController> currentViewController = [tumblrController currentViewController];
[currentViewController clear];
}
}
- (void) HTTPConnectionFailed: (ORHTTPRequest *) httpReq{
log(@"failed!");
[growlController postFailed];
}
- (void) httpRequest:(ORHTTPRequest *) httpReq DidFailWithError: (NSError *) error{
log(@"request failed!");
[growlController networkDown];
}
@end