Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Architectural support for TouchJSON

  • Loading branch information...
commit 9463f27166340a955ce16ed58a0c9092d783d444 1 parent 4fcf85f
@stevestreza stevestreza authored committed
View
4 AppController.m
@@ -97,7 +97,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
//NSLog(@"getFriendIDsFor: connectionIdentifier = %@", [twitterEngine getFriendIDsFor:TESTING_SECONDARY_USER startingFromCursor:-1]);
//NSLog(@"getFollowerIDsFor: connectionIdentifier = %@", [twitterEngine getFollowerIDsFor:TESTING_SECONDARY_USER startingFromCursor:-1]);
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
// Search method
//NSLog(@"getSearchResultsForQuery: connectionIdentifier = %@", [twitterEngine getSearchResultsForQuery:TESTING_PRIMARY_USER sinceID:0 startingAtPage:1 count:20]);
@@ -186,7 +186,7 @@ - (void)connectionFinished:(NSString *)connectionIdentifier
}
}
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
- (void)receivedObject:(NSDictionary *)dictionary forRequest:(NSString *)connectionIdentifier
{
View
10 MGTwitterEngine.h
@@ -23,12 +23,12 @@
NSString *_clientURL;
NSString *_clientSourceToken;
NSString *_APIDomain;
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
NSString *_searchDomain;
#endif
BOOL _secureConnection;
BOOL _clearsCookies;
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
MGTwitterEngineDeliveryOptions _deliveryOptions;
#endif
}
@@ -51,7 +51,7 @@
- (void)setClientName:(NSString *)name version:(NSString *)version URL:(NSString *)url token:(NSString *)token;
- (NSString *)APIDomain;
- (void)setAPIDomain:(NSString *)domain;
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
- (NSString *)searchDomain;
- (void)setSearchDomain:(NSString *)domain;
#endif
@@ -59,7 +59,7 @@
- (void)setUsesSecureConnection:(BOOL)flag;
- (BOOL)clearsCookies; // YES = deletes twitter.com cookies when setting username/password, default is NO (see README.txt)
- (void)setClearsCookies:(BOOL)flag;
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
- (MGTwitterEngineDeliveryOptions)deliveryOptions;
- (void)setDeliveryOptions:(MGTwitterEngineDeliveryOptions)deliveryOptions;
#endif
@@ -205,7 +205,7 @@
// All methods below return a unique connection identifier.
// ======================================================================================================
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
// Search method
View
33 MGTwitterEngine.m
@@ -25,6 +25,10 @@
#import "MGTwitterUsersYAJLParser.h"
#import "MGTwitterMiscYAJLParser.h"
#import "MGTwitterSearchYAJLParser.h"
+#elif TOUCHJSON_AVAILABLE
+ #define API_FORMAT @"json"
+
+ #import "MGTwitterTouchJSONParser.h"
#else
#define API_FORMAT @"xml"
@@ -45,7 +49,7 @@
#define TWITTER_DOMAIN @"api.twitter.com/1"
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
#define TWITTER_SEARCH_DOMAIN @"search.twitter.com"
#endif
#define HTTP_POST_METHOD @"POST"
@@ -126,13 +130,13 @@ - (MGTwitterEngine *)initWithDelegate:(NSObject *)newDelegate
_clientURL = [DEFAULT_CLIENT_URL retain];
_clientSourceToken = [DEFAULT_CLIENT_TOKEN retain];
_APIDomain = [TWITTER_DOMAIN retain];
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
_searchDomain = [TWITTER_SEARCH_DOMAIN retain];
#endif
_secureConnection = YES;
_clearsCookies = NO;
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
_deliveryOptions = MGTwitterEngineDeliveryAllResultsOption;
#endif
}
@@ -155,7 +159,7 @@ - (void)dealloc
[_clientURL release];
[_clientSourceToken release];
[_APIDomain release];
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
[_searchDomain release];
#endif
@@ -272,7 +276,7 @@ - (void)setAPIDomain:(NSString *)domain
}
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
- (NSString *)searchDomain
{
@@ -316,7 +320,7 @@ - (void)setClearsCookies:(BOOL)flag
_clearsCookies = flag;
}
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
- (MGTwitterEngineDeliveryOptions)deliveryOptions
{
@@ -598,7 +602,7 @@ - (NSMutableURLRequest *)_baseRequestWithMethod:(NSString *)method
fullPath = [self _queryStringWithBase:fullPath parameters:params prefixed:YES];
}
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
NSString *domain = nil;
NSString *connectionType = nil;
if (requestType == MGTwitterSearchRequest || requestType == MGTwitterSearchCurrentTrendsRequest)
@@ -683,7 +687,7 @@ - (NSMutableURLRequest *)_baseRequestWithMethod:(NSString *)method
#pragma mark Parsing methods
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
- (void)_parseDataForConnection:(MGTwitterHTTPURLConnection *)connection
{
NSData *jsonData = [[[connection data] copy] autorelease];
@@ -699,6 +703,7 @@ - (void)_parseDataForConnection:(MGTwitterHTTPURLConnection *)connection
}
#endif
+#if YAJL_AVAILABLE
switch (responseType) {
case MGTwitterStatuses:
case MGTwitterStatus:
@@ -731,6 +736,12 @@ - (void)_parseDataForConnection:(MGTwitterHTTPURLConnection *)connection
default:
break;
}
+#elif TOUCHJSON_AVAILABLE
+ [MGTwitterTouchJSONParser parserWithJSON:jsonData delegate:self
+ connectionIdentifier:identifier requestType:requestType
+ responseType:responseType URL:URL deliveryOptions:_deliveryOptions];
+#endif
+
}
#else
- (void)_parseDataForConnection:(MGTwitterHTTPURLConnection *)connection
@@ -846,7 +857,7 @@ - (void)parsingSucceededForRequest:(NSString *)identifier
if ([self _isValidDelegateForSelector:@selector(miscInfoReceived:forRequest:)])
[_delegate miscInfoReceived:parsedObjects forRequest:identifier];
break;
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
case MGTwitterSearchResults:
if ([self _isValidDelegateForSelector:@selector(searchResultsReceived:forRequest:)])
[_delegate searchResultsReceived:parsedObjects forRequest:identifier];
@@ -869,7 +880,7 @@ - (void)parsingFailedForRequest:(NSString *)requestIdentifier
[_delegate requestFailed:requestIdentifier withError:error];
}
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
- (void)parsedObject:(NSDictionary *)dictionary forRequest:(NSString *)requestIdentifier
ofResponseType:(MGTwitterResponseType)responseType
@@ -1798,7 +1809,7 @@ - (NSString *)getFollowerIDsFor:(NSString *)username startingFromCursor:(MGTwitt
}
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
#pragma mark -
#pragma mark Search API methods
View
14 MGTwitterEngine.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 1E874648115AD8D80076FC51 /* MGTwitterTouchJSONParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E874647115AD8D80076FC51 /* MGTwitterTouchJSONParser.m */; };
44F7517C0E47DBD600858A1B /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 44F7517B0E47DBD600858A1B /* libxml2.dylib */; };
44F7518F0E47DDD500858A1B /* MGTwitterUsersLibXMLParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 44F751890E47DDD500858A1B /* MGTwitterUsersLibXMLParser.m */; };
44F751900E47DDD500858A1B /* MGTwitterMiscLibXMLParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 44F7518A0E47DDD500858A1B /* MGTwitterMiscLibXMLParser.m */; };
@@ -34,6 +35,8 @@
/* Begin PBXFileReference section */
089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
+ 1E874646115AD8D80076FC51 /* MGTwitterTouchJSONParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGTwitterTouchJSONParser.h; sourceTree = "<group>"; };
+ 1E874647115AD8D80076FC51 /* MGTwitterTouchJSONParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGTwitterTouchJSONParser.m; sourceTree = "<group>"; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = "<group>"; };
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
@@ -145,6 +148,15 @@
name = Products;
sourceTree = "<group>";
};
+ 1E874644115AD7BF0076FC51 /* Twitter TouchJSON Parsers */ = {
+ isa = PBXGroup;
+ children = (
+ 1E874646115AD8D80076FC51 /* MGTwitterTouchJSONParser.h */,
+ 1E874647115AD8D80076FC51 /* MGTwitterTouchJSONParser.m */,
+ );
+ name = "Twitter TouchJSON Parsers";
+ sourceTree = "<group>";
+ };
29B97314FDCFA39411CA2CEA /* MATwitterIntegration */ = {
isa = PBXGroup;
children = (
@@ -279,6 +291,7 @@
44F7517D0E47DBF600858A1B /* Twitter LibXML Parsers */,
C90F74CB0D6A3B5300F602A5 /* Twitter NSXML Parsers */,
44AEFFD00F213814004F5AE3 /* Twitter YAJL Parsers */,
+ 1E874644115AD7BF0076FC51 /* Twitter TouchJSON Parsers */,
C90F748C0D69FDE000F602A5 /* Categories */,
);
name = MATwitterEngine;
@@ -357,6 +370,7 @@
44F751A70E47DEC400858A1B /* NSData+Base64.m in Sources */,
D47CF9B511541D0A00E07931 /* MGTwitterSocialGraphParser.m in Sources */,
D47CFCA9115567ED00E07931 /* MGTwitterSocialGraphLibXMLParser.m in Sources */,
+ 1E874648115AD8D80076FC51 /* MGTwitterTouchJSONParser.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
4 MGTwitterEngineDelegate.h
@@ -29,7 +29,7 @@ typedef enum _MGTwitterEngineDeliveryOptions {
@optional
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
// This delegate method is called each time a new result is parsed from the connection and
// the deliveryOption is configured for MGTwitterEngineDeliveryIndividualResults.
- (void)receivedObject:(NSDictionary *)dictionary forRequest:(NSString *)connectionIdentifier;
@@ -42,7 +42,7 @@ typedef enum _MGTwitterEngineDeliveryOptions {
- (void)directMessagesReceived:(NSArray *)messages forRequest:(NSString *)connectionIdentifier;
- (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier;
- (void)miscInfoReceived:(NSArray *)miscInfo forRequest:(NSString *)connectionIdentifier;
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
- (void)searchResultsReceived:(NSArray *)searchResults forRequest:(NSString *)connectionIdentifier;
#endif
- (void)socialGraphInfoReceived:(NSArray *)socialGraphInfo forRequest:(NSString *)connectionIdentifier;
View
1  MGTwitterEngineGlobalHeader.h
@@ -49,6 +49,7 @@
*/
#define YAJL_AVAILABLE 0
+#define TOUCHJSON_AVAILABLE 1
#if YAJL_AVAILABLE
/*
View
4 MGTwitterParserDelegate.h
@@ -11,7 +11,7 @@
#import "MGTwitterRequestTypes.h"
@protocol MGTwitterParserDelegate
-
+
- (void)parsingSucceededForRequest:(NSString *)identifier
ofResponseType:(MGTwitterResponseType)responseType
withParsedObjects:(NSArray *)parsedObjects;
@@ -20,7 +20,7 @@
ofResponseType:(MGTwitterResponseType)responseType
withError:(NSError *)error;
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
- (void)parsedObject:(NSDictionary *)parsedObject forRequest:(NSString *)identifier
ofResponseType:(MGTwitterResponseType)responseType;
#endif
View
4 MGTwitterRequestTypes.h
@@ -46,7 +46,7 @@ typedef enum _MGTwitterRequestType {
MGTwitterImageRequest, // requesting an image
MGTwitterFriendIDsRequest, // request the numeric IDs for every user the specified user is following
MGTwitterFollowerIDsRequest, // request the numeric IDs of the followers of the specified user
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
MGTwitterSearchRequest, // performing a search
MGTwitterSearchCurrentTrendsRequest, // getting the current trends
#endif
@@ -62,7 +62,7 @@ typedef enum _MGTwitterResponseType {
MGTwitterGeneric = 6, // a generic response not requiring parsing
MGTwitterMiscellaneous = 8, // a miscellaneous response of key-value pairs
MGTwitterImage = 7, // an image
-#if YAJL_AVAILABLE
+#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
MGTwitterSearchResults = 9, // search results
#endif
MGTwitterSocialGraph = 10,
View
45 MGTwitterTouchJSONParser.h
@@ -0,0 +1,45 @@
+//
+// MGTwitterTouchJSONParser.h
+// MGTwitterEngine
+//
+// Created by Steve Streza on 3/24/10.
+// Copyright 2010 MGTwitterEngine. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+#import "MGTwitterParserDelegate.h"
+#import "MGTwitterEngineDelegate.h"
+
+@interface MGTwitterTouchJSONParser : NSObject {
+ __weak NSObject <MGTwitterParserDelegate> *delegate; // weak ref
+ NSString *identifier;
+ MGTwitterRequestType requestType;
+ MGTwitterResponseType responseType;
+ NSURL *URL;
+ NSData *json;
+ NSMutableArray *parsedObjects;
+ MGTwitterEngineDeliveryOptions deliveryOptions;
+}
+
++ (id)parserWithJSON:(NSData *)theJSON
+ delegate:(NSObject *)theDelegate
+connectionIdentifier:(NSString *)identifier
+ requestType:(MGTwitterRequestType)reqType
+ responseType:(MGTwitterResponseType)respType
+ URL:(NSURL *)URL
+ deliveryOptions:(MGTwitterEngineDeliveryOptions)deliveryOptions;
+- (id)initWithJSON:(NSData *)theJSON
+ delegate:(NSObject *)theDelegate
+connectionIdentifier:(NSString *)identifier
+ requestType:(MGTwitterRequestType)reqType
+ responseType:(MGTwitterResponseType)respType
+ URL:(NSURL *)URL
+ deliveryOptions:(MGTwitterEngineDeliveryOptions)deliveryOptions;
+
+// delegate callbacks
+- (void)_parsingDidEnd;
+- (void)_parsingErrorOccurred:(NSError *)parseError;
+- (void)_parsedObject:(NSDictionary *)dictionary;
+
+@end
View
88 MGTwitterTouchJSONParser.m
@@ -0,0 +1,88 @@
+//
+// MGTwitterTouchJSONParser.m
+// MGTwitterEngine
+//
+// Created by Steve Streza on 3/24/10.
+// Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import "MGTwitterTouchJSONParser.h"
+
+
+@implementation MGTwitterTouchJSONParser
+
++ (id)parserWithJSON:(NSData *)theJSON
+ delegate:(NSObject *)theDelegate
+connectionIdentifier:(NSString *)identifier
+ requestType:(MGTwitterRequestType)reqType
+ responseType:(MGTwitterResponseType)respType
+ URL:(NSURL *)URL
+ deliveryOptions:(MGTwitterEngineDeliveryOptions)deliveryOptions
+{
+ return [[[self alloc] initWithJSON:theJSON
+ delegate:theDelegate
+ connectionIdentifier:identifier
+ requestType:reqType
+ responseType:respType
+ URL:URL
+ deliveryOptions:deliveryOptions] autorelease];
+}
+
+- (id) initWithJSON:(NSData *)theJSON
+ delegate:(NSObject *)theDelegate
+connectionIdentifier:(NSString *)theIdentifier
+ requestType:(MGTwitterRequestType)reqType
+ responseType:(MGTwitterResponseType)respType
+ URL:(NSURL *)theURL
+ deliveryOptions:(MGTwitterEngineDeliveryOptions)theDeliveryOptions
+{
+ if(self = [super init]){
+ json = [theJSON retain];
+ identifier = [theIdentifier retain];
+ requestType = reqType;
+ responseType = respType;
+ URL = [theURL retain];
+ deliveryOptions = theDeliveryOptions;
+ delegate = theDelegate;
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+ [parsedObjects release];
+ [json release];
+ [identifier release];
+ [URL release];
+
+ delegate = nil;
+ [super dealloc];
+}
+
+#pragma mark Delegate callbacks
+
+- (BOOL) _isValidDelegateForSelector:(SEL)selector
+{
+ return ((delegate != nil) && [delegate respondsToSelector:selector]);
+}
+
+- (void)_parsingDidEnd
+{
+ if ([self _isValidDelegateForSelector:@selector(parsingSucceededForRequest:ofResponseType:withParsedObjects:)])
+ [delegate parsingSucceededForRequest:identifier ofResponseType:responseType withParsedObjects:parsedObjects];
+}
+
+- (void)_parsingErrorOccurred:(NSError *)parseError
+{
+ if ([self _isValidDelegateForSelector:@selector(parsingFailedForRequest:ofResponseType:withError:)])
+ [delegate parsingFailedForRequest:identifier ofResponseType:responseType withError:parseError];
+}
+
+- (void)_parsedObject:(NSDictionary *)dictionary
+{
+ if (deliveryOptions & MGTwitterEngineDeliveryIndividualResultsOption)
+ if ([self _isValidDelegateForSelector:@selector(parsedObject:forRequest:ofResponseType:)])
+ [delegate parsedObject:(NSDictionary *)dictionary forRequest:identifier ofResponseType:responseType];
+}
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.