Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge commit 'matt/master'

  • Loading branch information...
commit e62712cbdcf2dea397138a88602b57f9f35952eb 2 parents 8784e62 + f059aaa
@tarasis tarasis authored
View
38 MGTwitterEngine.h
@@ -11,7 +11,9 @@
#import "MGTwitterEngineDelegate.h"
#import "MGTwitterParserDelegate.h"
-@interface MGTwitterEngine : NSObject <MGTwitterParserDelegate> {
+
+@interface MGTwitterEngine : NSObject <MGTwitterParserDelegate>
+{
__weak NSObject <MGTwitterEngineDelegate> *_delegate;
NSString *_username;
NSString *_password;
@@ -87,21 +89,21 @@
- (NSString *)getPublicTimeline; // statuses/public_timeline
-- (NSString *)getFollowedTimelineSinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count:(int)count; // statuses/friends_timeline
-- (NSString *)getFollowedTimelineSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)pageNum count:(int)count; // statuses/friends_timeline
+- (NSString *)getFollowedTimelineSinceID:(MGTwitterEngineID)sinceID startingAtPage:(int)pageNum count:(int)count; // statuses/friends_timeline
+- (NSString *)getFollowedTimelineSinceID:(MGTwitterEngineID)sinceID withMaximumID:(MGTwitterEngineID)maxID startingAtPage:(int)pageNum count:(int)count; // statuses/friends_timeline
-- (NSString *)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count:(int)count; // statuses/user_timeline & statuses/user_timeline/user
-- (NSString *)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)pageNum count:(int)count; // statuses/user_timeline & statuses/user_timeline/user
+- (NSString *)getUserTimelineFor:(NSString *)username sinceID:(MGTwitterEngineID)sinceID startingAtPage:(int)pageNum count:(int)count; // statuses/user_timeline & statuses/user_timeline/user
+- (NSString *)getUserTimelineFor:(NSString *)username sinceID:(MGTwitterEngineID)sinceID withMaximumID:(MGTwitterEngineID)maxID startingAtPage:(int)pageNum count:(int)count; // statuses/user_timeline & statuses/user_timeline/user
-- (NSString *)getUpdate:(unsigned long)updateID; // statuses/show
+- (NSString *)getUpdate:(MGTwitterEngineID)updateID; // statuses/show
- (NSString *)sendUpdate:(NSString *)status; // statuses/update
-- (NSString *)sendUpdate:(NSString *)status inReplyTo:(unsigned long)updateID; // statuses/update
+- (NSString *)sendUpdate:(NSString *)status inReplyTo:(MGTwitterEngineID)updateID; // statuses/update
- (NSString *)getRepliesStartingAtPage:(int)pageNum; // statuses/mentions
-- (NSString *)getRepliesSinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count:(int)count; // statuses/mentions
-- (NSString *)getRepliesSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)pageNum count:(int)count; // statuses/mentions
+- (NSString *)getRepliesSinceID:(MGTwitterEngineID)sinceID startingAtPage:(int)pageNum count:(int)count; // statuses/mentions
+- (NSString *)getRepliesSinceID:(MGTwitterEngineID)sinceID withMaximumID:(MGTwitterEngineID)maxID startingAtPage:(int)pageNum count:(int)count; // statuses/mentions
-- (NSString *)deleteUpdate:(unsigned long)updateID; // statuses/destroy
+- (NSString *)deleteUpdate:(MGTwitterEngineID)updateID; // statuses/destroy
- (NSString *)getFeaturedUsers; // statuses/features (undocumented, returns invalid JSON data)
@@ -118,14 +120,14 @@
// Direct Message methods
-- (NSString *)getDirectMessagesSinceID:(unsigned long)sinceID startingAtPage:(int)pageNum; // direct_messages
-- (NSString *)getDirectMessagesSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)pageNum count:(int)count; // direct_messages
+- (NSString *)getDirectMessagesSinceID:(MGTwitterEngineID)sinceID startingAtPage:(int)pageNum; // direct_messages
+- (NSString *)getDirectMessagesSinceID:(MGTwitterEngineID)sinceID withMaximumID:(MGTwitterEngineID)maxID startingAtPage:(int)pageNum count:(int)count; // direct_messages
-- (NSString *)getSentDirectMessagesSinceID:(unsigned long)sinceID startingAtPage:(int)pageNum; // direct_messages/sent
-- (NSString *)getSentDirectMessagesSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)pageNum count:(int)count; // direct_messages/sent
+- (NSString *)getSentDirectMessagesSinceID:(MGTwitterEngineID)sinceID startingAtPage:(int)pageNum; // direct_messages/sent
+- (NSString *)getSentDirectMessagesSinceID:(MGTwitterEngineID)sinceID withMaximumID:(MGTwitterEngineID)maxID startingAtPage:(int)pageNum count:(int)count; // direct_messages/sent
- (NSString *)sendDirectMessage:(NSString *)message to:(NSString *)username; // direct_messages/new
-- (NSString *)deleteDirectMessage:(unsigned long)updateID;// direct_messages/destroy
+- (NSString *)deleteDirectMessage:(MGTwitterEngineID)updateID;// direct_messages/destroy
// Friendship methods
@@ -159,7 +161,7 @@
- (NSString *)getFavoriteUpdatesFor:(NSString *)username startingAtPage:(int)pageNum; // favorites
-- (NSString *)markUpdate:(unsigned long)updateID asFavorite:(BOOL)flag; // favorites/create, favorites/destroy
+- (NSString *)markUpdate:(MGTwitterEngineID)updateID asFavorite:(BOOL)flag; // favorites/create, favorites/destroy
// Notification methods
@@ -199,8 +201,8 @@
// Search method
- (NSString *)getSearchResultsForQuery:(NSString *)query;
-- (NSString *)getSearchResultsForQuery:(NSString *)query sinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count:(int)count; // search
-- (NSString *)getSearchResultsForQuery:(NSString *)query sinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count:(int)count geocode:(NSString *)geocode;
+- (NSString *)getSearchResultsForQuery:(NSString *)query sinceID:(MGTwitterEngineID)sinceID startingAtPage:(int)pageNum count:(int)count; // search
+- (NSString *)getSearchResultsForQuery:(NSString *)query sinceID:(MGTwitterEngineID)sinceID startingAtPage:(int)pageNum count:(int)count geocode:(NSString *)geocode;
// Trends method
View
123 MGTwitterEngine.m
@@ -8,6 +8,7 @@
#import "MGTwitterEngine.h"
#import "MGTwitterHTTPURLConnection.h"
+@class OAToken;
#import "NSData+Base64.h"
@@ -75,6 +76,10 @@ - (NSString *)_sendRequestWithMethod:(NSString *)method
requestType:(MGTwitterRequestType)requestType
responseType:(MGTwitterResponseType)responseType;
+-(NSString *)_sendRequest:(NSURLRequest *)theRequest
+ withRequestType:(MGTwitterRequestType)requestType
+ responseType:(MGTwitterResponseType)responseType;
+
// Parsing methods
- (void)_parseDataForConnection:(MGTwitterHTTPURLConnection *)connection;
@@ -92,7 +97,7 @@ @implementation MGTwitterEngine
+ (MGTwitterEngine *)twitterEngineWithDelegate:(NSObject *)theDelegate
{
- return [[[MGTwitterEngine alloc] initWithDelegate:theDelegate] autorelease];
+ return [[[self alloc] initWithDelegate:theDelegate] autorelease];
}
@@ -566,7 +571,13 @@ - (NSString *)_sendRequestWithMethod:(NSString *)method
}
}
-
+ return [self _sendRequest:theRequest withRequestType:requestType responseType:responseType];
+}
+
+-(NSString *)_sendRequest:(NSURLRequest *)theRequest
+ withRequestType:(MGTwitterRequestType)requestType
+ responseType:(MGTwitterResponseType)responseType
+{
// Create a connection using this request, with the default timeout and caching policy,
// and appropriate Twitter request and response types for parsing and error reporting.
MGTwitterHTTPURLConnection *connection;
@@ -574,25 +585,24 @@ - (NSString *)_sendRequestWithMethod:(NSString *)method
delegate:self
requestType:requestType
responseType:responseType];
-
- if (!connection) {
+
+ if (!connection) {
return nil;
} else {
[_connections setObject:connection forKey:[connection identifier]];
[connection release];
}
-
- return [connection identifier];
+
+ return [connection identifier];
}
-
#pragma mark Parsing methods
#if YAJL_AVAILABLE
- (void)_parseDataForConnection:(MGTwitterHTTPURLConnection *)connection
{
- NSString *identifier = [[[connection identifier] copy] autorelease];
NSData *jsonData = [[[connection data] copy] autorelease];
+ NSString *identifier = [[[connection identifier] copy] autorelease];
MGTwitterRequestType requestType = [connection requestType];
MGTwitterResponseType responseType = [connection responseType];
@@ -780,6 +790,7 @@ - (void)parsedObject:(NSDictionary *)dictionary forRequest:(NSString *)requestId
#endif
+
#pragma mark NSURLConnection delegate methods
@@ -858,12 +869,15 @@ - (void)connection:(MGTwitterHTTPURLConnection *)connection didReceiveData:(NSDa
- (void)connection:(MGTwitterHTTPURLConnection *)connection didFailWithError:(NSError *)error
{
+ NSString *connectionIdentifier = [connection identifier];
+
// Inform delegate.
- if ([self _isValidDelegateForSelector:@selector(requestFailed:withError:)])
- [_delegate requestFailed:[connection identifier] withError:error];
+ if ([self _isValidDelegateForSelector:@selector(requestFailed:withError:)]){
+ [_delegate requestFailed:connectionIdentifier
+ withError:error];
+ }
// Release the connection.
- NSString *connectionIdentifier = [connection identifier];
[_connections removeObjectForKey:connectionIdentifier];
if ([self _isValidDelegateForSelector:@selector(connectionFinished:)])
[_delegate connectionFinished:connectionIdentifier];
@@ -872,9 +886,14 @@ - (void)connection:(MGTwitterHTTPURLConnection *)connection didFailWithError:(NS
- (void)connectionDidFinishLoading:(MGTwitterHTTPURLConnection *)connection
{
+ NSString *connID = nil;
+ MGTwitterResponseType responseType = 0;
+ connID = [connection identifier];
+ responseType = [connection responseType];
+
// Inform delegate.
if ([self _isValidDelegateForSelector:@selector(requestSucceeded:)])
- [_delegate requestSucceeded:[connection identifier]];
+ [_delegate requestSucceeded:connID];
NSData *receivedData = [connection data];
if (receivedData) {
@@ -911,13 +930,11 @@ - (void)connectionDidFinishLoading:(MGTwitterHTTPURLConnection *)connection
}
// Release the connection.
- NSString *connectionIdentifier = [connection identifier];
- [_connections removeObjectForKey:connectionIdentifier];
+ [_connections removeObjectForKey:connID];
if ([self _isValidDelegateForSelector:@selector(connectionFinished:)])
- [_delegate connectionFinished:connectionIdentifier];
+ [_delegate connectionFinished:connID];
}
-
#pragma mark -
#pragma mark REST API methods
#pragma mark -
@@ -938,21 +955,21 @@ - (NSString *)getPublicTimeline
#pragma mark -
-- (NSString *)getFollowedTimelineSinceID:(unsigned long)sinceID startingAtPage:(int)page count:(int)count
+- (NSString *)getFollowedTimelineSinceID:(MGTwitterEngineID)sinceID startingAtPage:(int)page count:(int)count
{
return [self getFollowedTimelineSinceID:sinceID withMaximumID:0 startingAtPage:page count:count];
}
-- (NSString *)getFollowedTimelineSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)page count:(int)count
+- (NSString *)getFollowedTimelineSinceID:(MGTwitterEngineID)sinceID withMaximumID:(MGTwitterEngineID)maxID startingAtPage:(int)page count:(int)count
{
NSString *path = [NSString stringWithFormat:@"statuses/friends_timeline.%@", API_FORMAT];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
if (sinceID > 0) {
- [params setObject:[NSString stringWithFormat:@"%u", sinceID] forKey:@"since_id"];
+ [params setObject:[NSString stringWithFormat:@"%llu", sinceID] forKey:@"since_id"];
}
if (maxID > 0) {
- [params setObject:[NSString stringWithFormat:@"%u", maxID] forKey:@"max_id"];
+ [params setObject:[NSString stringWithFormat:@"%llu", maxID] forKey:@"max_id"];
}
if (page > 0) {
[params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
@@ -970,22 +987,22 @@ - (NSString *)getFollowedTimelineSinceID:(unsigned long)sinceID withMaximumID:(u
#pragma mark -
-- (NSString *)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sinceID startingAtPage:(int)page count:(int)count
+- (NSString *)getUserTimelineFor:(NSString *)username sinceID:(MGTwitterEngineID)sinceID startingAtPage:(int)page count:(int)count
{
return [self getUserTimelineFor:username sinceID:sinceID withMaximumID:0 startingAtPage:0 count:count];
}
-- (NSString *)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)page count:(int)count
+- (NSString *)getUserTimelineFor:(NSString *)username sinceID:(MGTwitterEngineID)sinceID withMaximumID:(MGTwitterEngineID)maxID startingAtPage:(int)page count:(int)count
{
NSString *path = [NSString stringWithFormat:@"statuses/user_timeline.%@", API_FORMAT];
MGTwitterRequestType requestType = MGTwitterUserTimelineRequest;
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
if (sinceID > 0) {
- [params setObject:[NSString stringWithFormat:@"%u", sinceID] forKey:@"since_id"];
+ [params setObject:[NSString stringWithFormat:@"%llu", sinceID] forKey:@"since_id"];
}
if (maxID > 0) {
- [params setObject:[NSString stringWithFormat:@"%u", maxID] forKey:@"max_id"];
+ [params setObject:[NSString stringWithFormat:@"%llu", maxID] forKey:@"max_id"];
}
if (page > 0) {
[params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
@@ -1007,9 +1024,9 @@ - (NSString *)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sin
#pragma mark -
-- (NSString *)getUpdate:(unsigned long)updateID
+- (NSString *)getUpdate:(MGTwitterEngineID)updateID
{
- NSString *path = [NSString stringWithFormat:@"statuses/show/%u.%@", updateID, API_FORMAT];
+ NSString *path = [NSString stringWithFormat:@"statuses/show/%llu.%@", updateID, API_FORMAT];
return [self _sendRequestWithMethod:nil path:path queryParameters:nil body:nil
requestType:MGTwitterUpdateGetRequest
@@ -1023,7 +1040,7 @@ - (NSString *)sendUpdate:(NSString *)status
}
-- (NSString *)sendUpdate:(NSString *)status inReplyTo:(unsigned long)updateID
+- (NSString *)sendUpdate:(NSString *)status inReplyTo:(MGTwitterEngineID)updateID
{
if (!status) {
return nil;
@@ -1039,7 +1056,7 @@ - (NSString *)sendUpdate:(NSString *)status inReplyTo:(unsigned long)updateID
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
[params setObject:trimmedText forKey:@"status"];
if (updateID > 0) {
- [params setObject:[NSString stringWithFormat:@"%u", updateID] forKey:@"in_reply_to_status_id"];
+ [params setObject:[NSString stringWithFormat:@"%llu", updateID] forKey:@"in_reply_to_status_id"];
}
NSString *body = [self _queryStringWithBase:nil parameters:params prefixed:NO];
@@ -1058,12 +1075,12 @@ - (NSString *)getRepliesStartingAtPage:(int)page
return [self getRepliesSinceID:0 startingAtPage:page count:0]; // zero means default
}
-- (NSString *)getRepliesSinceID:(unsigned long)sinceID startingAtPage:(int)page count:(int)count
+- (NSString *)getRepliesSinceID:(MGTwitterEngineID)sinceID startingAtPage:(int)page count:(int)count
{
return [self getRepliesSinceID:sinceID withMaximumID:0 startingAtPage:page count:count];
}
-- (NSString *)getRepliesSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)page count:(int)count
+- (NSString *)getRepliesSinceID:(MGTwitterEngineID)sinceID withMaximumID:(MGTwitterEngineID)maxID startingAtPage:(int)page count:(int)count
{
// NOTE: identi.ca can't handle mentions URL yet...
// NSString *path = [NSString stringWithFormat:@"statuses/mentions.%@", API_FORMAT];
@@ -1071,10 +1088,10 @@ - (NSString *)getRepliesSinceID:(unsigned long)sinceID withMaximumID:(unsigned l
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
if (sinceID > 0) {
- [params setObject:[NSString stringWithFormat:@"%u", sinceID] forKey:@"since_id"];
+ [params setObject:[NSString stringWithFormat:@"%llu", sinceID] forKey:@"since_id"];
}
if (maxID > 0) {
- [params setObject:[NSString stringWithFormat:@"%u", maxID] forKey:@"max_id"];
+ [params setObject:[NSString stringWithFormat:@"%llu", maxID] forKey:@"max_id"];
}
if (page > 0) {
[params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
@@ -1092,9 +1109,9 @@ - (NSString *)getRepliesSinceID:(unsigned long)sinceID withMaximumID:(unsigned l
#pragma mark -
-- (NSString *)deleteUpdate:(unsigned long)updateID
+- (NSString *)deleteUpdate:(MGTwitterEngineID)updateID
{
- NSString *path = [NSString stringWithFormat:@"statuses/destroy/%u.%@", updateID, API_FORMAT];
+ NSString *path = [NSString stringWithFormat:@"statuses/destroy/%llu.%@", updateID, API_FORMAT];
return [self _sendRequestWithMethod:HTTP_POST_METHOD path:path queryParameters:nil body:nil
requestType:MGTwitterUpdateDeleteRequest
@@ -1215,7 +1232,7 @@ - (NSString *)getUserInformationForEmail:(NSString *)email
} else {
return nil;
}
-
+
return [self _sendRequestWithMethod:nil path:path queryParameters:params body:nil
requestType:MGTwitterUserInformationRequest
responseType:MGTwitterUser];
@@ -1225,21 +1242,21 @@ - (NSString *)getUserInformationForEmail:(NSString *)email
#pragma mark Direct Message methods
-- (NSString *)getDirectMessagesSinceID:(unsigned long)sinceID startingAtPage:(int)page
+- (NSString *)getDirectMessagesSinceID:(MGTwitterEngineID)sinceID startingAtPage:(int)page
{
return [self getDirectMessagesSinceID:sinceID withMaximumID:0 startingAtPage:page count:0];
}
-- (NSString *)getDirectMessagesSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)page count:(int)count
+- (NSString *)getDirectMessagesSinceID:(MGTwitterEngineID)sinceID withMaximumID:(MGTwitterEngineID)maxID startingAtPage:(int)page count:(int)count
{
NSString *path = [NSString stringWithFormat:@"direct_messages.%@", API_FORMAT];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
if (sinceID > 0) {
- [params setObject:[NSString stringWithFormat:@"%u", sinceID] forKey:@"since_id"];
+ [params setObject:[NSString stringWithFormat:@"%llu", sinceID] forKey:@"since_id"];
}
if (maxID > 0) {
- [params setObject:[NSString stringWithFormat:@"%u", maxID] forKey:@"max_id"];
+ [params setObject:[NSString stringWithFormat:@"%llu", maxID] forKey:@"max_id"];
}
if (page > 0) {
[params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
@@ -1256,21 +1273,21 @@ - (NSString *)getDirectMessagesSinceID:(unsigned long)sinceID withMaximumID:(uns
#pragma mark -
-- (NSString *)getSentDirectMessagesSinceID:(unsigned long)sinceID startingAtPage:(int)page
+- (NSString *)getSentDirectMessagesSinceID:(MGTwitterEngineID)sinceID startingAtPage:(int)page
{
return [self getSentDirectMessagesSinceID:sinceID withMaximumID:0 startingAtPage:page count:0];
}
-- (NSString *)getSentDirectMessagesSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)page count:(int)count
+- (NSString *)getSentDirectMessagesSinceID:(MGTwitterEngineID)sinceID withMaximumID:(MGTwitterEngineID)maxID startingAtPage:(int)page count:(int)count
{
NSString *path = [NSString stringWithFormat:@"direct_messages/sent.%@", API_FORMAT];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
if (sinceID > 0) {
- [params setObject:[NSString stringWithFormat:@"%u", sinceID] forKey:@"since_id"];
+ [params setObject:[NSString stringWithFormat:@"%llu", sinceID] forKey:@"since_id"];
}
if (maxID > 0) {
- [params setObject:[NSString stringWithFormat:@"%u", maxID] forKey:@"max_id"];
+ [params setObject:[NSString stringWithFormat:@"%llu", maxID] forKey:@"max_id"];
}
if (page > 0) {
[params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
@@ -1313,9 +1330,9 @@ - (NSString *)sendDirectMessage:(NSString *)message to:(NSString *)username
}
-- (NSString *)deleteDirectMessage:(unsigned long)updateID
+- (NSString *)deleteDirectMessage:(MGTwitterEngineID)updateID
{
- NSString *path = [NSString stringWithFormat:@"direct_messages/destroy/%u.%@", updateID, API_FORMAT];
+ NSString *path = [NSString stringWithFormat:@"direct_messages/destroy/%llu.%@", updateID, API_FORMAT];
return [self _sendRequestWithMethod:HTTP_POST_METHOD path:path queryParameters:nil body:nil
requestType:MGTwitterDirectMessageDeleteRequest
@@ -1484,17 +1501,17 @@ - (NSString *)getFavoriteUpdatesFor:(NSString *)username startingAtPage:(int)pag
#pragma mark -
-- (NSString *)markUpdate:(unsigned long)updateID asFavorite:(BOOL)flag
+- (NSString *)markUpdate:(MGTwitterEngineID)updateID asFavorite:(BOOL)flag
{
NSString *path = nil;
MGTwitterRequestType requestType;
if (flag)
{
- path = [NSString stringWithFormat:@"favorites/create/%u.%@", updateID, API_FORMAT];
+ path = [NSString stringWithFormat:@"favorites/create/%llu.%@", updateID, API_FORMAT];
requestType = MGTwitterFavoritesEnableRequest;
}
else {
- path = [NSString stringWithFormat:@"favorites/destroy/%u.%@", updateID, API_FORMAT];
+ path = [NSString stringWithFormat:@"favorites/destroy/%llu.%@", updateID, API_FORMAT];
requestType = MGTwitterFavoritesDisableRequest;
}
@@ -1602,13 +1619,17 @@ - (NSString *)getSearchResultsForQuery:(NSString *)query
}
-- (NSString *)getSearchResultsForQuery:(NSString *)query sinceID:(unsigned long)sinceID startingAtPage:(int)page count:(int)count
+- (NSString *)getSearchResultsForQuery:(NSString *)query sinceID:(MGTwitterEngineID)sinceID startingAtPage:(int)page count:(int)count
{
return [self getSearchResultsForQuery:query sinceID:sinceID startingAtPage:0 count:0 geocode:nil]; // zero means default
}
-- (NSString *)getSearchResultsForQuery:(NSString *)query sinceID:(unsigned long)sinceID startingAtPage:(int)page count:(int)count geocode:(NSString *)geocode
+- (NSString *)getSearchResultsForQuery:(NSString *)query sinceID:(MGTwitterEngineID)sinceID startingAtPage:(int)page count:(int)count geocode:(NSString *)geocode
{
+#if LARGE_ID_TEST
+ if (sinceID > 0) sinceID -= 0x7fffffff;
+#endif
+
NSString *path = [NSString stringWithFormat:@"search.%@", API_FORMAT];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
@@ -1616,7 +1637,7 @@ - (NSString *)getSearchResultsForQuery:(NSString *)query sinceID:(unsigned long)
[params setObject:query forKey:@"q"];
}
if (sinceID > 0) {
- [params setObject:[NSString stringWithFormat:@"%u", sinceID] forKey:@"since_id"];
+ [params setObject:[NSString stringWithFormat:@"%llu", sinceID] forKey:@"since_id"];
}
if (page > 0) {
[params setObject:[NSString stringWithFormat:@"%d", page] forKey:@"page"];
View
1  MGTwitterEngineDelegate.h
@@ -54,6 +54,7 @@ typedef enum _MGTwitterEngineDeliveryOptions {
#endif
// This delegate method is called whenever a connection has finished.
+- (void)connectionStarted:(NSString *)connectionIdentifier;
- (void)connectionFinished:(NSString *)connectionIdentifier;
@end
View
25 MGTwitterEngineGlobalHeader.h
@@ -49,3 +49,28 @@
*/
#define YAJL_AVAILABLE 0
+
+#if YAJL_AVAILABLE
+ /*
+ When enabled, this definition artificially adds 0x7ffffff to each tweet ID that is read from the API. It
+ also subtracts 0x7fffffff from anything it sends back to the API. This allows you to test your application
+ code and make sure it works well with large unsigned longs. This is important because tweet IDs that are
+ treated as signed integers will become negative after 2^32 - 1 (0x7fffffff). This will happen sometime
+ around the end of May 2009.
+
+ A future release of MGTwitterEngine will use 64-bit integers for the tweet IDs. The current change is
+ meant as a stopgap measure that will affect existing applications as little as possible.
+ */
+
+ #define LARGE_ID_TEST 0
+#else
+ /*
+ This option is only available when you are using the YAJL parser. Do not change the following definition.
+ */
+ #define LARGE_ID_TEST 0
+#endif
+
+#ifndef __MGTWITTERENGINEID__
+#define __MGTWITTERENGINEID__
+typedef unsigned long long MGTwitterEngineID;
+#endif
View
4 MGTwitterHTTPURLConnection.h
@@ -10,7 +10,9 @@
#import "MGTwitterRequestTypes.h"
-@interface MGTwitterHTTPURLConnection : NSURLConnection {
+
+@interface MGTwitterHTTPURLConnection : NSURLConnection
+{
NSMutableData *_data; // accumulated data received on this connection
MGTwitterRequestType _requestType; // general type of this request, mostly for error handling
MGTwitterResponseType _responseType; // type of response data expected (if successful)
View
1  MGTwitterHTTPURLConnection.m
@@ -95,5 +95,4 @@ - (NSString *)description
return [description stringByAppendingFormat:@" (requestType = %d, identifier = %@)", _requestType, _identifier];
}
-
@end
View
5 MGTwitterMiscYAJLParser.m
@@ -41,7 +41,10 @@ - (void)endDictionary
[self _parsedObject:_results];
- [parsedObjects addObject:_results];
+ if(_results){
+ [parsedObjects addObject:_results];
+ }
+
[_results release];
_results = nil;
View
33 MGTwitterStatusesYAJLParser.m
@@ -51,23 +51,24 @@ - (void)startDictionaryWithKey:(NSString *)key
- (void)endDictionary
{
- if (_user)
- {
- [_status setObject:_user forKey:@"user"];
- [_user release];
- _user = nil;
- }
- else
- {
- [_status setObject:[NSNumber numberWithInt:requestType] forKey:TWITTER_SOURCE_REQUEST_TYPE];
-
- [self _parsedObject:_status];
-
- [parsedObjects addObject:_status];
- [_status release];
- _status = nil;
+ if (_status){
+ if (_user)
+ {
+ [_status setObject:_user forKey:@"user"];
+ [_user release];
+ _user = nil;
+ }
+ else
+ {
+ [_status setObject:[NSNumber numberWithInt:requestType] forKey:TWITTER_SOURCE_REQUEST_TYPE];
+
+ [self _parsedObject:_status];
+
+ [parsedObjects addObject:_status];
+ [_status release];
+ _status = nil;
+ }
}
-
#if DEBUG_PARSING
NSLog(@"status: dictionary end");
#endif
View
3  MGTwitterYAJLParser.h
@@ -8,7 +8,8 @@
#import "MGTwitterEngineGlobalHeader.h"
-#include <yajl/yajl_parse.h>
+//#include <yajl/yajl_parse.h>
+#import "yajl_parse.h"
#import "MGTwitterParserDelegate.h"
#import "MGTwitterEngineDelegate.h"
View
14 MGTwitterYAJLParser.m
@@ -44,20 +44,20 @@ int process_yajl_boolean(void * ctx, int boolVal)
int process_yajl_number(void *ctx, const char *numberVal, unsigned int numberLen)
{
id self = ctx;
-
+
if (currentKey)
{
NSString *stringValue = [[NSString alloc] initWithBytesNoCopy:(void *)numberVal length:numberLen encoding:NSUTF8StringEncoding freeWhenDone:NO];
-
+
NSNumber *longLongValue = [NSNumber numberWithLongLong:[stringValue longLongValue]];
[self addValue:longLongValue forKey:currentKey];
-
+
[stringValue release];
-
+
[currentKey release];
currentKey = nil;
}
-
+
return 1;
}
@@ -246,7 +246,7 @@ - (id)initWithJSON:(NSData *)theJSON delegate:(NSObject *)theDelegate
0, // allowComments: if nonzero, javascript style comments will be allowed in the input (both /* */ and //)
0 // checkUTF8: if nonzero, invalid UTF8 strings will cause a parse error
};
- _handle = yajl_alloc(&callbacks, &cfg, self);
+ _handle = yajl_alloc(&callbacks, &cfg, NULL, self);
if (! _handle)
{
return nil;
@@ -258,7 +258,7 @@ - (id)initWithJSON:(NSData *)theJSON delegate:(NSObject *)theDelegate
unsigned char *errorMessage = yajl_get_error(_handle, 0, [json bytes], [json length]);
NSLog(@"MGTwitterYAJLParser: error = %s", errorMessage);
[self _parsingErrorOccurred:[NSError errorWithDomain:@"YAJL" code:status userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithUTF8String:(char *)errorMessage] forKey:@"errorMessage"]]];
- yajl_free_error(errorMessage);
+ yajl_free_error(_handle, errorMessage);
}
// free the yajl parser
Please sign in to comment.
Something went wrong with that request. Please try again.