Permalink
Browse files

new view from stefan

  • Loading branch information...
1 parent c7feb8a commit 5eb7d7935e6b2b83e7b98e6be064f4e9781bded9 xdamman committed Aug 22, 2010
View
@@ -18,18 +18,21 @@
NSDate *timestamp;
NSURL *image;
NSURL *thumbnail;
+ NSDictionary *user;
float id;
}
- (id) initWithDictionary:(NSDictionary *)tweetData;
+- (void) getUserInfoThread;
-@property (copy) NSString *screenName;
-@property (copy) NSString *content;
-@property (copy) NSString *type;
-@property (copy) NSURL *permalink;
-@property (copy) NSURL *avatar;
-@property (copy) NSDate *timestamp;
-@property (copy) NSURL *image;
-@property (copy) NSURL *thumbnail;
+@property (nonatomic,retain) NSString *screenName;
+@property (nonatomic,retain) NSDictionary *user;
+@property (nonatomic,retain) NSString *content;
+@property (nonatomic,retain) NSString *type;
+@property (nonatomic,retain) NSURL *permalink;
+@property (nonatomic,retain) NSURL *avatar;
+@property (nonatomic,retain) NSDate *timestamp;
+@property (nonatomic,retain) NSURL *image;
+@property (nonatomic,retain) NSURL *thumbnail;
@end
View
@@ -9,6 +9,7 @@
#import <Foundation/Foundation.h>
#import "Tweet.h"
#import "RegexKitLite.h"
+#import "Twitter.h"
@implementation Tweet
@@ -20,6 +21,7 @@ @implementation Tweet
@synthesize image;
@synthesize thumbnail;
@synthesize type;
+@synthesize user;
- (id) initWithDictionary:(NSDictionary *)tweetData {
if(self == [super init])
@@ -55,11 +57,23 @@ - (id) initWithDictionary:(NSDictionary *)tweetData {
}
+ [NSThread detachNewThreadSelector:@selector(getUserInfoThread) toTarget:self withObject:nil];
}
return self;
}
+- (void) getUserInfoThread {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSLog(@"New thread");
+ Twitter *twitter = [[Twitter alloc] init];
+ user = [twitter getUserInfo:self.screenName];
+ NSLog(@"Fetching user %@: %@",self.screenName,user);
+// [self performSelectorOnMainThread:@selector(searchTwitterDidFinish) withObject:nil waitUntilDone:NO];
+ [twitter release];
+ [pool release];
+}
+
- (void)dealloc {
[screenName release];
[avatar release];
View
@@ -13,7 +13,6 @@
@interface Twitter : NSObject
- (NSArray *)searchByKeyword:(NSString *)keyword limit:(int)limit;
-- (NSArray *)searchByScreenName:(NSString *)screenName since:(NSDate *)since until:(NSDate *)until limit:(int)limit;
-- (NSArray *)searchImages:(NSString *)keyword since:(NSDate *)since until:(NSDate *)until limit:(int)limit;
+- (NSDictionary *)getUserInfo:(NSString *)screenName;
@end
View
@@ -57,15 +57,30 @@ - (NSArray *)searchByKeyword:(NSString *)keyword limit:(int)limit
//NSLog(@"Tweets: %@",tweets);
}
-- (NSArray *)searchByScreenName:(NSString *)screenName since:(NSDate *)since until:(NSDate *)until limit:(int)limit
-{
- return [self searchByKeyword:[NSString stringWithFormat:@"from:%@",screenName] limit:limit];
+- (NSDictionary *)getUserInfo:(NSString *)screenName {
+
+ NSString *queryString = [[NSString stringWithFormat:@"http://api.twitter.com/1/users/show/%@.json",screenName] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+
+ NSLog(@"Requesting %@",queryString);
+
+ NSError *error = nil;
+ NSString *json = [NSString stringWithContentsOfURL:[NSURL URLWithString:queryString]
+ encoding:NSUTF8StringEncoding
+ error:&error];
+
+ NSString *jsonObj = [NSString stringWithFormat:@"{\"root\":%@}",json];
+
+
+ NSData *jsonData = [jsonObj dataUsingEncoding:NSUTF32BigEndianStringEncoding];
+ error = nil;
+
+ NSDictionary *userData = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
+
+ //NSLog(@"Error received: %@",error);
+ return [userData objectForKey:@"root"];
+
}
-- (NSArray *)searchImages:(NSString *)keyword since:(NSDate *)since until:(NSDate *)until limit:(int)limit
-{
- return [self searchByKeyword:[NSString stringWithFormat:@"%@ AND (twitpic OR yfrog OR tweetphoto)",keyword] limit:limit];
-}
- (NSArray *) processTweets:(NSDictionary *)tweetsData {
View
@@ -30,7 +30,7 @@
- (Tweet *) getNext;
- (void) setSearchKeyword: (NSString *)aKeyword;
-
+- (void) searchTwitterThread;
@property (nonatomic, retain) NSString *keyword;
@property (nonatomic, retain) id delegate;
View
@@ -55,11 +55,11 @@ - (void) setSearchKeyword: (NSString *)aKeyword {
self.keyword = aKeyword;
// Thread
NSLog(@"Searching for %@",aKeyword);
- [NSThread detachNewThreadSelector:@selector(searchTwitter) toTarget:self withObject:nil];
+ [NSThread detachNewThreadSelector:@selector(searchTwitterThread) toTarget:self withObject:nil];
}
-- (void) searchTwitter {
+- (void) searchTwitterThread {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"New thread");
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit 5eb7d79

Please sign in to comment.