Changeset 782
- Timestamp:
- 07/26/08 22:28:39 (4 months ago)
- Location:
- trunk/TwitterFon
- Files:
-
- 2 removed
- 6 modified
- 2 moved
-
Classes/Controllers/PostViewController.h (modified) (2 diffs)
-
Classes/Controllers/PostViewController.m (modified) (3 diffs)
-
Classes/Controllers/TimelineViewController.m (modified) (1 diff)
-
Classes/Network/PostTweet.h (deleted)
-
Classes/Network/PostTweet.m (deleted)
-
Classes/Network/TwitterClient.h (moved) (moved from trunk/TwitterFon/Classes/Network/TimelineDownloader.h) (1 diff)
-
Classes/Network/TwitterClient.m (moved) (moved from trunk/TwitterFon/Classes/Network/TimelineDownloader.m) (5 diffs)
-
Classes/Twitter/Timeline.h (modified) (2 diffs)
-
Classes/Twitter/Timeline.m (modified) (5 diffs)
-
TwitterFon.xcodeproj/project.pbxproj (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/TwitterFon/Classes/Controllers/PostViewController.h
r781 r782 8 8 9 9 #import <UIKit/UIKit.h> 10 #import " PostTweet.h"10 #import "TwitterClient.h" 11 11 #import "Message.h" 12 12 #import "SendingWindow.h" … … 18 18 IBOutlet NSObject* delegate; 19 19 IBOutlet NSObject* appDelegate; 20 PostTweet*post;20 TwitterClient* post; 21 21 BOOL didPost; 22 22 NSRange textRange; -
trunk/TwitterFon/Classes/Controllers/PostViewController.m
r781 r782 121 121 - (IBAction) send: (id) sender 122 122 { 123 post = [[ PostTweet alloc] initWithDelegate:self];123 post = [[TwitterClient alloc] initWithDelegate:self]; 124 124 [post post:text.text]; 125 125 [sendingWindow show]; … … 143 143 } 144 144 145 - (void)postTweetDidSucceed:(NSDictionary*)dic 146 { 145 - (void)twitterClientDidSucceed:(TwitterClient*)sender messages:(NSObject*)obj; 146 { 147 NSDictionary *dic = nil; 148 if ([obj isKindOfClass:[NSDictionary class]]) { 149 dic = (NSDictionary*)obj; 150 } 151 147 152 [sendingWindow hide]; 148 153 … … 156 161 [post autorelease]; 157 162 [self cancel:self]; 158 didPost = true;159 } 160 161 - (void) postTweetDidFail:(NSString*)error163 didPost = (dic) ? true : false; 164 } 165 166 - (void)twitterClientDidFail:(TwitterClient*)sender error:(NSString*)error 162 167 { 163 168 [sendingWindow fail:error]; -
trunk/TwitterFon/Classes/Controllers/TimelineViewController.m
r775 r782 244 244 245 245 // 246 // TimelineD ownloaderDelegate246 // TimelineDelegate 247 247 // 248 248 - (void)timelineDidReceiveNewMessage:(Message*)msg -
trunk/TwitterFon/Classes/Network/TwitterClient.h
r771 r782 3 3 #import "Message.h" 4 4 5 @interface T imelineDownloader: TFConnection5 @interface TwitterClient : TFConnection 6 6 { 7 7 } 8 8 9 9 - (void)get:(MessageType)type since:(NSString*)since; 10 - (void)post:(NSString*)tweet; 10 11 11 12 @end -
trunk/TwitterFon/Classes/Network/TwitterClient.m
r780 r782 1 1 // 2 // T imelineDownloader.m3 // Twitter Phox2 // TwitterClient.m 3 // TwitterFon 4 4 // 5 5 // Created by kaz on 7/13/08. … … 7 7 // 8 8 9 #import "TimelineDownloader.h" 9 #import "TwitterClient.h" 10 #import "StringUtil.h" 10 11 #import "JSON.h" 11 12 #import "Message.h" … … 20 21 //#define DEBUG_WITH_PUBLIC_TIMELINE 21 22 22 @interface NSObject (T imelineDownloaderDelegate)23 - (void)t imelineDownloaderDidSucceed:(TimelineDownloader*)sender messages:(NSArray*)messages;24 - (void)t imelineDownloaderDidFail:(TimelineDownloader*)sender error:(NSError*)error;23 @interface NSObject (TwitterClientDelegate) 24 - (void)twitterClientDidSucceed:(TwitterClient*)sender messages:(NSObject*)messages; 25 - (void)twitterClientDidFail:(TwitterClient*)sender error:(NSString*)error; 25 26 @end 26 27 27 @implementation T imelineDownloader28 @implementation TwitterClient 28 29 29 30 - (void)get:(MessageType)type since:(NSString*)since … … 57 58 } 58 59 60 - (void)post:(NSString*)tweet 61 { 62 63 NSString *username = [[NSUserDefaults standardUserDefaults] stringForKey:@"username"]; 64 NSString *password = [[NSUserDefaults standardUserDefaults] stringForKey:@"password"]; 65 66 NSString* url = [NSString stringWithFormat:@"https://%@:%@@twitter.com/statuses/update.json", 67 username, password]; 68 69 NSLog(@"%@", url); 70 71 NSString *postString = [NSString stringWithFormat:@"status=%@&source=TwitterFon", [tweet encodeAsURIComponent]]; 72 73 [self post:url body:postString]; 74 75 } 76 59 77 - (void)TFConnectionDidFailWithError:(NSError*)error 60 78 { 61 79 [self alertError:@"Connection Failed" withMessage:[error localizedDescription]]; 62 [delegate t imelineDownloaderDidFail:self error:error];80 [delegate twitterClientDidFail:self error:[error localizedDescription]]; 63 81 } 64 82 … … 93 111 94 112 if ([obj isKindOfClass:[NSDictionary class]]) { 113 NSDictionary* dic = (NSDictionary*)obj; 114 NSString *msg = [dic objectForKey:@"error"]; 115 if (msg) { 116 NSLog(@"Twitter returns an error: %@", msg); 117 [self alertError:@"Server error" withMessage:msg]; 118 [delegate twitterClientDidFail:self error:msg]; 119 } 120 else { 121 [delegate twitterClientDidSucceed:self messages:obj]; 122 } 123 } 124 else if ([obj isKindOfClass:[NSArray class]]) { 125 [delegate twitterClientDidSucceed:self messages:obj]; 126 } 127 else { 128 NSLog(@"Null or wrong response: %@", content); 129 [delegate twitterClientDidSucceed:self messages:nil]; 130 } 131 132 #if 0 133 if ([obj isKindOfClass:[NSDictionary class]]) { 95 134 NSLog(@"%@", content); 96 135 NSDictionary* dic = (NSDictionary*)obj; 97 136 NSString *msg = [dic objectForKey:@"error"]; 98 if (msg == nil) msg = @""; 137 if (msg == nil) { 138 msg = @""; 139 } 99 140 NSLog(@"Twitter returns an error: %@", msg); 100 [self alertError:@"Server error" withMessage:msg];101 [delegate t imelineDownloaderDidFail:self error:nil];141 // [self alertError:@"Server error" withMessage:msg]; 142 [delegate twitterClientDidFail:self error:nil]; 102 143 } 103 144 else if ([obj isKindOfClass:[NSArray class]]) { 104 145 NSArray *ary = (NSArray*)obj; 105 146 NSLog(@"received %d objects", [ary count]); 106 [delegate t imelineDownloaderDidSucceed:self messages:ary];147 [delegate twitterClientDidSucceed:self messages:ary]; 107 148 } 108 149 else { 109 150 NSLog(@"Null or wrong response: %@", content); 110 [delegate t imelineDownloaderDidSucceed:self messages:nil];151 [delegate twitterClientDidSucceed:self messages:nil]; 111 152 } 153 #endif 112 154 } 113 155 -
trunk/TwitterFon/Classes/Twitter/Timeline.h
r721 r782 1 1 #import <UIKit/UIKit.h> 2 2 #import "Message.h" 3 #import "T imelineDownloader.h"3 #import "TwitterClient.h" 4 4 5 5 @interface Timeline : NSObject … … 7 7 IBOutlet NSObject* delegate; 8 8 NSMutableArray* messages; 9 T imelineDownloader* timelineConn;9 TwitterClient* twitterClient; 10 10 MessageType type; 11 11 } -
trunk/TwitterFon/Classes/Twitter/Timeline.m
r771 r782 26 26 { 27 27 [messages release]; 28 [t imelineConnrelease];28 [twitterClient release]; 29 29 [super dealloc]; 30 30 } … … 47 47 - (void)update:(MessageType)aType 48 48 { 49 if (t imelineConn) return;49 if (twitterClient) return; 50 50 51 51 type = aType; 52 52 53 t imelineConn = [[TimelineDownloaderalloc] initWithDelegate:self];53 twitterClient = [[TwitterClient alloc] initWithDelegate:self]; 54 54 55 55 NSString* lastMessageDate = nil; … … 57 57 lastMessageDate = ((Message*)[messages lastObject]).createdAt; 58 58 } 59 [t imelineConnget:type since:lastMessageDate];59 [twitterClient get:type since:lastMessageDate]; 60 60 } 61 61 … … 80 80 } 81 81 82 - (void)t imelineDownloaderDidSucceed:(TimelineDownloader*)sender messages:(NSArray*)ary82 - (void)twitterClientDidSucceed:(TwitterClient*)sender messages:(NSObject*)obj 83 83 { 84 [timelineConn autorelease]; 85 timelineConn = nil; 84 [twitterClient autorelease]; 85 twitterClient = nil; 86 87 if (obj == nil) return; 86 88 87 if (ary == nil) { 89 NSArray *ary = nil; 90 if ([obj isKindOfClass:[NSArray class]]) { 91 ary = (NSArray*)obj; 92 } 93 else { 88 94 return; 89 95 } … … 115 121 } 116 122 117 - (void)t imelineDownloaderDidFail:(TimelineDownloader*)sender error:(NSError*)error123 - (void)twitterClientDidFail:(TwitterClient*)sender error:(NSString*)error 118 124 { 119 [t imelineConnautorelease];120 t imelineConn= nil;125 [twitterClient autorelease]; 126 twitterClient = nil; 121 127 } 122 128 -
trunk/TwitterFon/TwitterFon.xcodeproj/project.pbxproj
r775 r782 16 16 6E2BD0C10E35AE04003A8F69 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E2BD0C00E35AE04003A8F69 /* QuartzCore.framework */; }; 17 17 6E2BD11F0E35B3D2003A8F69 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 6E2BD11E0E35B3D2003A8F69 /* Default.png */; }; 18 6E335EA40E3BBE0C008B15BB /* TwitterClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E335EA30E3BBE0C008B15BB /* TwitterClient.m */; }; 18 19 6EAF29400E36F97E00129692 /* alert.png in Resources */ = {isa = PBXBuildFile; fileRef = 6EAF293F0E36F97E00129692 /* alert.png */; }; 19 20 6ED17FA70E38D3A0006E8AB7 /* forward.png in Resources */ = {isa = PBXBuildFile; fileRef = 6ED17FA50E38D3A0006E8AB7 /* forward.png */; }; … … 25 26 6EDD27740E3B5429002E09A0 /* TinyURL.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EDD27730E3B5429002E09A0 /* TinyURL.m */; }; 26 27 6EEBF7000E3B1F390003EA63 /* ImageDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EEBF6FA0E3B1F390003EA63 /* ImageDownloader.m */; }; 27 6EEBF7010E3B1F390003EA63 /* PostTweet.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EEBF6FC0E3B1F390003EA63 /* PostTweet.m */; };28 6EEBF7020E3B1F390003EA63 /* TimelineDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EEBF6FE0E3B1F390003EA63 /* TimelineDownloader.m */; };29 28 6EEBF70C0E3B1FD40003EA63 /* ColorUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EEBF7040E3B1FD40003EA63 /* ColorUtils.m */; }; 30 29 6EEBF70D0E3B1FD40003EA63 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EEBF7050E3B1FD40003EA63 /* main.m */; }; … … 71 70 6E2BD0C00E35AE04003A8F69 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 72 71 6E2BD11E0E35B3D2003A8F69 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; }; 72 6E335EA20E3BBE0C008B15BB /* TwitterClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TwitterClient.h; path = Network/TwitterClient.h; sourceTree = "<group>"; }; 73 6E335EA30E3BBE0C008B15BB /* TwitterClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TwitterClient.m; path = Network/TwitterClient.m; sourceTree = "<group>"; }; 73 74 6EAF293F0E36F97E00129692 /* alert.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = alert.png; sourceTree = "<group>"; }; 74 75 6ED17FA50E38D3A0006E8AB7 /* forward.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = forward.png; sourceTree = "<group>"; }; … … 83 84 6EEBF6F90E3B1F390003EA63 /* ImageDownloader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ImageDownloader.h; path = Network/ImageDownloader.h; sourceTree = "<group>"; }; 84 85 6EEBF6FA0E3B1F390003EA63 /* ImageDownloader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ImageDownloader.m; path = Network/ImageDownloader.m; sourceTree = "<group>"; }; 85 6EEBF6FB0E3B1F390003EA63 /* PostTweet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PostTweet.h; path = Network/PostTweet.h; sourceTree = "<group>"; };86 6EEBF6FC0E3B1F390003EA63 /* PostTweet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PostTweet.m; path = Network/PostTweet.m; sourceTree = "<group>"; };87 6EEBF6FD0E3B1F390003EA63 /* TimelineDownloader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TimelineDownloader.h; path = Network/TimelineDownloader.h; sourceTree = "<group>"; };88 6EEBF6FE0E3B1F390003EA63 /* TimelineDownloader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TimelineDownloader.m; path = Network/TimelineDownloader.m; sourceTree = "<group>"; };89 86 6EEBF7030E3B1FD40003EA63 /* ColorUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ColorUtils.h; path = Classes/OtherSources/ColorUtils.h; sourceTree = "<group>"; }; 90 87 6EEBF7040E3B1FD40003EA63 /* ColorUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ColorUtils.m; path = Classes/OtherSources/ColorUtils.m; sourceTree = "<group>"; }; … … 301 298 6EEBF6F90E3B1F390003EA63 /* ImageDownloader.h */, 302 299 6EEBF6FA0E3B1F390003EA63 /* ImageDownloader.m */, 303 6EEBF6FB0E3B1F390003EA63 /* PostTweet.h */,304 6EEBF6FC0E3B1F390003EA63 /* PostTweet.m */,305 6EEBF6FD0E3B1F390003EA63 /* TimelineDownloader.h */,306 6EEBF6FE0E3B1F390003EA63 /* TimelineDownloader.m */,307 300 6E092C390E3B41D40039FEE3 /* TFConnection.h */, 308 301 6E092C3A0E3B41D40039FEE3 /* TFConnection.m */, 302 6E335EA20E3BBE0C008B15BB /* TwitterClient.h */, 303 6E335EA30E3BBE0C008B15BB /* TwitterClient.m */, 309 304 6EDD27720E3B5429002E09A0 /* TinyURL.h */, 310 305 6EDD27730E3B5429002E09A0 /* TinyURL.m */, … … 450 445 6EDC01D10E344B5600FF142E /* DBConnection.m in Sources */, 451 446 6EEBF7000E3B1F390003EA63 /* ImageDownloader.m in Sources */, 452 6EEBF7010E3B1F390003EA63 /* PostTweet.m in Sources */,453 6EEBF7020E3B1F390003EA63 /* TimelineDownloader.m in Sources */,454 447 6EEBF70C0E3B1FD40003EA63 /* ColorUtils.m in Sources */, 455 448 6EEBF70D0E3B1FD40003EA63 /* main.m in Sources */, … … 467 460 6E092C3B0E3B41D40039FEE3 /* TFConnection.m in Sources */, 468 461 6EDD27740E3B5429002E09A0 /* TinyURL.m in Sources */, 462 6E335EA40E3BBE0C008B15BB /* TwitterClient.m in Sources */, 469 463 ); 470 464 runOnlyForDeploymentPostprocessing = 0;
