├── twitter_load.png ├── TwitterCommonLibrary_Prefix.pch ├── NSString+UUID.h ├── MGTwitterStatusesParser.h ├── MGTwitterUsersParser.h ├── MGTwitterMessagesParser.h ├── MGTwitterMiscLibXMLParser.h ├── MGTwitterUsersLibXMLParser.h ├── MGTwitterMiscParser.h ├── MGTwitterMessagesLibXMLParser.h ├── MGTwitterStatusesLibXMLParser.h ├── MGTwitterUserListsParser.h ├── MGTwitterSocialGraphParser.h ├── TouchJSON └── Source │ ├── JSON │ ├── JSONRepresentation.h │ ├── CJSONSerializer.h │ ├── CJSONDeserializer.h │ ├── CJSONScanner.h │ └── CJSONDeserializer.m │ ├── Experimental │ ├── CJSONSerializedData.h │ ├── CJSONDeserializer_BlocksExtensions.h │ ├── CFilteringJSONSerializer.h │ ├── CJSONSerializedData.m │ ├── CFilteringJSONSerializer.m │ └── CJSONDeserializer_BlocksExtensions.m │ ├── Extensions │ ├── NSCharacterSet_Extensions.h │ ├── NSDictionary_JSONExtensions.h │ ├── CDataScanner_Extensions.h │ ├── NSDictionary_JSONExtensions.m │ ├── NSScanner_Extensions.h │ ├── NSCharacterSet_Extensions.m │ ├── NSScanner_Extensions.m │ └── CDataScanner_Extensions.m │ └── CDataScanner.h ├── main.m ├── oauthconsumer ├── Crypto │ ├── sha1.h │ ├── hmac.h │ ├── Base64Transcoder.h │ ├── hmac.c │ └── sha1.c ├── README ├── Categories │ ├── NSURL+Base.h │ ├── NSString+URLEncoding.h │ ├── NSURL+Base.m │ ├── NSMutableURLRequest+Parameters.h │ ├── NSString+URLEncoding.m │ └── NSMutableURLRequest+Parameters.m ├── OAProblem.h ├── OAPlaintextSignatureProvider.h ├── OASignatureProviding.h ├── OAHMAC_SHA1SignatureProvider.h ├── OAPlaintextSignatureProvider.m ├── OAConsumer.h ├── OAuthConsumer.h ├── OACall.h ├── OADataFetcher.h ├── OAServiceTicket.h ├── OARequestParameter.h ├── OAConsumer.m ├── OAServiceTicket.m ├── OATokenManager.h ├── OAMutableURLRequest.h ├── OARequestParameter.m ├── OAHMAC_SHA1SignatureProvider.m ├── OAToken.h ├── OADataFetcher.m ├── OAProblem.m └── OACall.m ├── MGTwitterSocialGraphLibXMLParser.h ├── NSString+UUID.m ├── StreamingTableViewController.h ├── LogicTests-Info.plist ├── README ├── Classes ├── TwitterCommonLibraryAppDelegate.h ├── StreamingDelegate.h ├── StreamingConsumer.h ├── StreamingDelegate.m ├── StreamingConsumer.m ├── TwitterEngine.h └── TwitterCommonLibraryAppDelegate.m ├── MGTwitterParserDelegate.h ├── TwitterCommonLibrary-Info.plist ├── MGTwitterUsersLibXMLParser.m ├── MGTwitterStatusesLibXMLParser.m ├── OAuthSignInViewController.h ├── MGTwitterXMLParser.h ├── MGTwitterHTTPURLConnection.h ├── MGTwitterTouchJSONParser.h ├── MGTwitterMiscLibXMLParser.m ├── MGTwitterMiscParser.m ├── NSData+Base64.h ├── MGTwitterLibXMLParser.h ├── MGTwitterUsersParser.m ├── MGTwitterUserListsParser.m ├── MGTwitterMessagesParser.m ├── MGTwitterSocialGraphParser.m ├── MGTwitterEngineGlobalHeader.h ├── MGTwitterHTTPURLConnection.m ├── MGTwitterEngineDelegate.h ├── MGTwitterStatusesParser.m ├── MGTwitterSocialGraphLibXMLParser.m ├── MGTwitterMessagesLibXMLParser.m ├── NSData+Base64.m ├── MGTwitterTouchJSONParser.m ├── MGTwitterRequestTypes.h ├── MGTwitterXMLParser.m └── StreamingTableViewController.m /twitter_load.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TimShi/TSTwitterEngine/HEAD/twitter_load.png -------------------------------------------------------------------------------- /TwitterCommonLibrary_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'TwitterCommonLibrary' target in the 'TwitterCommonLibrary' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | -------------------------------------------------------------------------------- /NSString+UUID.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+UUID.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 16/09/2007. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | @interface NSString (UUID) 12 | 13 | + (NSString*)stringWithNewUUID; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /MGTwitterStatusesParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterStatusesParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterXMLParser.h" 12 | 13 | @interface MGTwitterStatusesParser : MGTwitterXMLParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /MGTwitterUsersParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterUsersParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 19/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterStatusesParser.h" 12 | 13 | @interface MGTwitterUsersParser : MGTwitterStatusesParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /MGTwitterMessagesParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMessagesParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 19/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterStatusesParser.h" 12 | 13 | @interface MGTwitterMessagesParser : MGTwitterStatusesParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /MGTwitterMiscLibXMLParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMiscLibXMLParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterLibXMLParser.h" 12 | 13 | @interface MGTwitterMiscLibXMLParser : MGTwitterLibXMLParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /MGTwitterUsersLibXMLParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterUsersLibXMLParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterLibXMLParser.h" 12 | 13 | @interface MGTwitterUsersLibXMLParser : MGTwitterLibXMLParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /MGTwitterMiscParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMiscParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 06/06/2008. 6 | // Copyright 2008 Instinctive Code. All rights reserved. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterStatusesParser.h" 12 | 13 | @interface MGTwitterMiscParser : MGTwitterStatusesParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /MGTwitterMessagesLibXMLParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMessagesLibXMLParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterLibXMLParser.h" 12 | 13 | @interface MGTwitterMessagesLibXMLParser : MGTwitterLibXMLParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /MGTwitterStatusesLibXMLParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterStatusesLibXMLParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterLibXMLParser.h" 12 | 13 | @interface MGTwitterStatusesLibXMLParser : MGTwitterLibXMLParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /MGTwitterUserListsParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterUserListsParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Clinton Shryock on 6/10/10. 6 | // Copyright 2010 scary-robot. All rights reserved. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterStatusesParser.h" 12 | 13 | @interface MGTwitterUserListsParser : MGTwitterStatusesParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /MGTwitterSocialGraphParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterSocialGraphParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Robert McGovern on 2010/03/19. 6 | // Copyright 2010 Tarasis. All rights reserved. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterStatusesParser.h" 12 | 13 | @interface MGTwitterSocialGraphParser : MGTwitterStatusesParser { 14 | NSMutableArray * twitterIDs; 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /TouchJSON/Source/JSON/JSONRepresentation.h: -------------------------------------------------------------------------------- 1 | // 2 | // JSONRepresentation.h 3 | // TouchJSON 4 | // 5 | // Created by Jonathan Wight on 10/15/10. 6 | // Copyright 2010 toxicsoftware.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol JSONRepresentation 12 | 13 | @optional 14 | - (id)initWithJSONDataRepresentation:(NSData *)inJSONData; 15 | 16 | - (NSData *)JSONDataRepresentation; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // TwitterCommonLibrary 4 | // 5 | // Created by Tim Shi on 11-01-07. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /oauthconsumer/Crypto/sha1.h: -------------------------------------------------------------------------------- 1 | 2 | // From http://www.mirrors.wiretapped.net/security/cryptography/hashes/sha1/sha1.c 3 | 4 | typedef struct { 5 | unsigned long state[5]; 6 | unsigned long count[2]; 7 | unsigned char buffer[64]; 8 | } SHA1_CTX; 9 | 10 | extern void SHA1Init(SHA1_CTX* context); 11 | extern void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len); 12 | extern void SHA1Final(unsigned char digest[20], SHA1_CTX* context); 13 | -------------------------------------------------------------------------------- /TouchJSON/Source/Experimental/CJSONSerializedData.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJSONSerializedData.h 3 | // TouchMetricsTest 4 | // 5 | // Created by Jonathan Wight on 10/31/10. 6 | // Copyright 2010 toxicsoftware.com. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface CJSONSerializedData : NSObject { 13 | NSData *data; 14 | } 15 | 16 | @property (readonly, nonatomic, retain) NSData *data; 17 | 18 | - (id)initWithData:(NSData *)inData; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /MGTwitterSocialGraphLibXMLParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterSocialGraphLibXMLParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Robert McGovern on 2010/03/20. 6 | // Copyright 2010 Tarasis. All rights reserved. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterLibXMLParser.h" 12 | 13 | @interface MGTwitterSocialGraphLibXMLParser : MGTwitterLibXMLParser { 14 | NSMutableArray * twitterIDs; 15 | } 16 | 17 | - (NSDictionary *)_socialGraphDictionaryForNodeWithName:(const xmlChar *)parentNodeName; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /TouchJSON/Source/Experimental/CJSONDeserializer_BlocksExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJSONDeserializer_BlocksExtensions.h 3 | // TouchJSON 4 | // 5 | // Created by Jonathan Wight on 10/15/10. 6 | // Copyright 2010 toxicsoftware.com. All rights reserved. 7 | // 8 | 9 | #import "CJSONDeserializer.h" 10 | 11 | @interface CJSONDeserializer (CJSONDeserializer_BlocksExtensions) 12 | 13 | - (void)deserializeAsDictionary:(NSData *)inData completionBlock:(void (^)(id result, NSError *error))block; 14 | - (void)deserializeAsArray:(NSData *)inData completionBlock:(void (^)(id result, NSError *error))block; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /NSString+UUID.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+UUID.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 16/09/2007. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "NSString+UUID.h" 10 | 11 | 12 | @implementation NSString (UUID) 13 | 14 | 15 | + (NSString*)stringWithNewUUID 16 | { 17 | // Create a new UUID 18 | CFUUIDRef uuidObj = CFUUIDCreate(nil); 19 | 20 | // Get the string representation of the UUID 21 | NSString *newUUID = (NSString*)CFUUIDCreateString(nil, uuidObj); 22 | CFRelease(uuidObj); 23 | return [newUUID autorelease]; 24 | } 25 | 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /oauthconsumer/README: -------------------------------------------------------------------------------- 1 | This is an iPhone ready version of: 2 | http://oauth.googlecode.com/svn/code/obj-c/OAuthConsumer/ 3 | 4 | "iPhone ready" simply means you just need to add the files to Xcode, and import "OAuthConsumer.h". 5 | 6 | If you're rolling with the iPhone: 7 | 8 | 1) Be sure to add Security.framework. 9 | 2) Include libxml2.dylib in your frameworks. You also need to add a 10 | build property to the project -- "header search paths" needs to 11 | include "$SDKROOT/usr/include/libxml2" with "Recursive" checked. 12 | 13 | 3) Optionally removed the OATestServer.rb file (seems like this is to create a test server in ruby) -------------------------------------------------------------------------------- /TouchJSON/Source/Experimental/CFilteringJSONSerializer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CFilteringJSONSerializer.h 3 | // CouchNotes 4 | // 5 | // Created by Jonathan Wight on 06/20/10. 6 | // Copyright 2010 toxicsoftware.com. All rights reserved. 7 | // 8 | 9 | #import "CJSONSerializer.h" 10 | 11 | typedef NSString *(^JSONConversionTest)(id inObject); 12 | typedef id (^JSONConversionConverter)(id inObject); 13 | 14 | @interface CFilteringJSONSerializer : CJSONSerializer { 15 | NSSet *tests; 16 | NSDictionary *convertersByName; 17 | } 18 | 19 | @property (readwrite, nonatomic, retain) NSSet *tests; 20 | @property (readwrite, nonatomic, retain) NSDictionary *convertersByName; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /StreamingTableViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // StreamingTableViewController.h 3 | // TwitterCommonLibrary 4 | // 5 | // Created by Tim Shi on 11-01-10. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "StreamingConsumer.h" 11 | 12 | @interface StreamingTableViewController : UITableViewController { 13 | 14 | //This array stores the streaming tweets, once it hits certain limit we'll start to delete from the bottom of the list 15 | //(first in first out kind of circular que) 16 | NSMutableArray* streamingTweets; 17 | } 18 | 19 | - (void) consumerDidProcessStatus:(NSString*) statusString; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /TouchJSON/Source/Experimental/CJSONSerializedData.m: -------------------------------------------------------------------------------- 1 | // 2 | // CJSONSerializedData.m 3 | // TouchMetricsTest 4 | // 5 | // Created by Jonathan Wight on 10/31/10. 6 | // Copyright 2010 toxicsoftware.com. All rights reserved. 7 | // 8 | 9 | #import "CJSONSerializedData.h" 10 | 11 | 12 | @implementation CJSONSerializedData 13 | 14 | @synthesize data; 15 | 16 | - (id)initWithData:(NSData *)inData 17 | { 18 | if ((self = [super init]) != NULL) 19 | { 20 | data = [inData retain]; 21 | } 22 | return(self); 23 | } 24 | 25 | - (void)dealloc 26 | { 27 | [data release]; 28 | data = NULL; 29 | // 30 | [super dealloc]; 31 | } 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /LogicTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleSignature 16 | ???? 17 | CFBundleVersion 18 | 1.0 19 | 20 | 21 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | The TSTwitterEngine uses a few other open source projects: MGTwitter Engine, Touch JSON and OAuthConsumer. The goal is to provide an easy to set up library for building Twitter integration into iPhone app. The library provides out of box support for oAuth authentication, twitter's rest api and streaming api. 2 | 3 | The project include an demo application for the library. When running, the demo project presents a modal view to ask the user to log into their twitter account, and starts streaming any tweets with the keyword "github" via a table view. 4 | 5 | To run the demo project, add your consumer key and consumer secret in the TWitterEngine.h file. 6 | 7 | If you want to change the keyword, replace it in the TwitterCommonLibraryAppDelegate.m 8 | 9 | Tim -------------------------------------------------------------------------------- /Classes/TwitterCommonLibraryAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // TwitterCommonLibraryAppDelegate.h 3 | // TwitterCommonLibrary 4 | // 5 | // Created by Tim Shi on 11-01-07. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "StreamingDelegate.h" 11 | #import "StreamingConsumer.h" 12 | #import "StreamingTableViewController.h" 13 | #import "OAuthSignInViewController.h" 14 | 15 | @interface TwitterCommonLibraryAppDelegate : NSObject { 16 | UIWindow *window; 17 | 18 | StreamingDelegate* streamingDelegate; 19 | 20 | StreamingTableViewController* streamingTableController; 21 | 22 | OAuthSignInViewController* signInController; 23 | } 24 | 25 | @property (nonatomic, retain) IBOutlet UIWindow *window; 26 | 27 | -(void) startStreaming; 28 | 29 | @end 30 | 31 | -------------------------------------------------------------------------------- /MGTwitterParserDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterParserDelegate.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 18/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterRequestTypes.h" 12 | 13 | @protocol MGTwitterParserDelegate 14 | 15 | - (void)parsingSucceededForRequest:(NSString *)identifier 16 | ofResponseType:(MGTwitterResponseType)responseType 17 | withParsedObjects:(NSArray *)parsedObjects; 18 | 19 | - (void)parsingFailedForRequest:(NSString *)requestIdentifier 20 | ofResponseType:(MGTwitterResponseType)responseType 21 | withError:(NSError *)error; 22 | 23 | #if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE 24 | - (void)parsedObject:(NSDictionary *)parsedObject forRequest:(NSString *)identifier 25 | ofResponseType:(MGTwitterResponseType)responseType; 26 | #endif 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /TwitterCommonLibrary-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | MainWindow 29 | 30 | 31 | -------------------------------------------------------------------------------- /MGTwitterUsersLibXMLParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterUsersLibXMLParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterUsersLibXMLParser.h" 10 | 11 | 12 | @implementation MGTwitterUsersLibXMLParser 13 | 14 | - (void)parse 15 | { 16 | int readerResult = xmlTextReaderRead(_reader); 17 | if (readerResult != 1) 18 | return; 19 | int nodeType = xmlTextReaderNodeType(_reader); 20 | const xmlChar *name = xmlTextReaderConstName(_reader); 21 | while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(BAD_CAST "users", name))) 22 | { 23 | if (nodeType == XML_READER_TYPE_ELEMENT) 24 | { 25 | if (xmlStrEqual(name, BAD_CAST "user")) 26 | { 27 | [parsedObjects addObject:[self _userDictionaryForNodeWithName:name]]; 28 | } 29 | } 30 | 31 | // advance reader 32 | readerResult = xmlTextReaderRead(_reader); 33 | if (readerResult != 1) 34 | { 35 | break; 36 | } 37 | nodeType = xmlTextReaderNodeType(_reader); 38 | name = xmlTextReaderConstName(_reader); 39 | } 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /MGTwitterStatusesLibXMLParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterStatusesLibXMLParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterStatusesLibXMLParser.h" 10 | 11 | 12 | @implementation MGTwitterStatusesLibXMLParser 13 | 14 | 15 | - (void)parse 16 | { 17 | int readerResult = xmlTextReaderRead(_reader); 18 | if (readerResult != 1) 19 | return; 20 | int nodeType = xmlTextReaderNodeType(_reader); 21 | const xmlChar *name = xmlTextReaderConstName(_reader); 22 | while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(BAD_CAST "statuses", name))) 23 | { 24 | if (nodeType == XML_READER_TYPE_ELEMENT) 25 | { 26 | if (xmlStrEqual(name, BAD_CAST "status")) 27 | { 28 | [parsedObjects addObject:[self _statusDictionaryForNodeWithName:name]]; 29 | } 30 | } 31 | 32 | // advance reader 33 | readerResult = xmlTextReaderRead(_reader); 34 | if (readerResult != 1) 35 | { 36 | break; 37 | } 38 | nodeType = xmlTextReaderNodeType(_reader); 39 | name = xmlTextReaderConstName(_reader); 40 | } 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /OAuthSignInViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAuthSignInViewController.h 3 | // TwitterCommonLibrary 4 | // 5 | // Created by Tim Shi on 11-01-11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define kGGTwitterLoadingBackgroundImage @"twitter_load.png" 12 | 13 | @protocol OAuthSignInViewControllerDelegate 14 | @optional 15 | - (void) authenticatedWithPin:(NSString *) pin; 16 | - (void) authenticationFailed; 17 | - (void) authenticationCanceled; 18 | @end 19 | 20 | 21 | @interface OAuthSignInViewController:UIViewController { 22 | 23 | UIWebView *_webView; 24 | UINavigationBar *_navBar; 25 | UIImageView *_backgroundView; 26 | 27 | id _delegate; 28 | UIView *_blockerView; 29 | 30 | BOOL _loading, _firstLoad; 31 | } 32 | 33 | - (id)initWithDelegate:(id) aDelegate; 34 | - (NSString *) locateAuthPinInWebView: (UIWebView *) webView; 35 | - (void) loadRequest:(NSURLRequest*) request; 36 | 37 | //This is a weak reference since we don't retain the delegate. 38 | @property (nonatomic, assign) id delegate; 39 | @end 40 | -------------------------------------------------------------------------------- /Classes/StreamingDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // StreamingDelegate.h 3 | // TwitterCommonLibrary 4 | // 5 | // Created by Tim Shi on 11-01-07. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "StreamingDelegate.h" 11 | #import "StreamingConsumer.h" 12 | 13 | /* 14 | Twitter Engine's streaming connection keeps reference to this delegate object. 15 | 16 | This object has a reference to the consumer so that it can create task for the consumer and add it to the operation queue. 17 | */ 18 | 19 | @interface StreamingDelegate : NSObject{ 20 | 21 | //This is a strong reference because the consumer belongs to the delegate. 22 | StreamingConsumer* streamingConsumer; 23 | } 24 | 25 | //Designated initializer, retain reference to the consumer. 26 | - (id)initWithConsumer:(StreamingConsumer*)consumer; 27 | 28 | //delegate method to url connection. When data is received we simply create a task with the recieved data and throw it to a queue for processing by the consumer. 29 | - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data; 30 | 31 | //sends back the user credential 32 | - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Classes/StreamingConsumer.h: -------------------------------------------------------------------------------- 1 | // 2 | // StreamingConsumer.h 3 | // TwitterCommonLibrary 4 | // 5 | // Created by Tim Shi on 11-01-07. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol TwitterStreamingDelegate 12 | @required 13 | - (void) consumerDidProcessStatus:(NSString*) statusString; 14 | @end 15 | 16 | /* 17 | Responsible for parsing the status and doing something with it. 18 | */ 19 | @interface StreamingConsumer : NSObject { 20 | //Holds the data that comes in until it represents a complete status. 21 | NSMutableString* holderString; 22 | 23 | //Streaming data comes in and gets put on this queue. 24 | NSOperationQueue* operationQue; 25 | 26 | //a weak reference because the delegate doesn't belong to the consumer. 27 | id delegate; 28 | } 29 | 30 | @property(nonatomic, retain) NSOperationQueue* operationQue; 31 | 32 | //Takes the data and processes it. 33 | -(void) process:(NSString*)data; 34 | 35 | //Other method can create a task with the data and throw it on the operation queue for processing later. 36 | - (NSOperation*)taskWithData:(NSString*)data; 37 | 38 | //Parses string with certain delimiter. 39 | - (NSRange) parseStringWithDelimiter:(NSString*) delimiter forString:(NSString*) toBeParsed; 40 | 41 | #pragma delegate 42 | - (id)delegate; 43 | - (void)setDelegate:(id)newDelegate; 44 | 45 | @end -------------------------------------------------------------------------------- /MGTwitterXMLParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterXMLParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 18/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | #import "MGTwitterParserDelegate.h" 11 | 12 | @interface MGTwitterXMLParser : NSObject { 13 | __weak NSObject *delegate; // weak ref 14 | NSString *identifier; 15 | MGTwitterRequestType requestType; 16 | MGTwitterResponseType responseType; 17 | NSData *xml; 18 | NSMutableArray *parsedObjects; 19 | NSXMLParser *parser; 20 | __weak NSMutableDictionary *currentNode; 21 | NSString *lastOpenedElement; 22 | } 23 | 24 | + (id)parserWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate 25 | connectionIdentifier:(NSString *)identifier requestType:(MGTwitterRequestType)reqType 26 | responseType:(MGTwitterResponseType)respType; 27 | - (id)initWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate 28 | connectionIdentifier:(NSString *)identifier requestType:(MGTwitterRequestType)reqType 29 | responseType:(MGTwitterResponseType)respType; 30 | 31 | - (NSString *)lastOpenedElement; 32 | - (void)setLastOpenedElement:(NSString *)value; 33 | 34 | - (void)addSource; 35 | 36 | - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName 37 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName; 38 | 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /MGTwitterHTTPURLConnection.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterHTTPURLConnection.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 16/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterRequestTypes.h" 12 | 13 | 14 | @interface MGTwitterHTTPURLConnection : NSURLConnection 15 | { 16 | NSMutableData *_data; // accumulated data received on this connection 17 | MGTwitterRequestType _requestType; // general type of this request, mostly for error handling 18 | MGTwitterResponseType _responseType; // type of response data expected (if successful) 19 | NSString *_identifier; 20 | NSURL *_URL; // the URL used for the connection (needed as a base URL when parsing with libxml) 21 | NSHTTPURLResponse * _response; // the response. 22 | } 23 | 24 | // Initializer 25 | - (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate 26 | requestType:(MGTwitterRequestType)requestType responseType:(MGTwitterResponseType)responseType; 27 | 28 | // Data helper methods 29 | - (void)resetDataLength; 30 | - (void)appendData:(NSData *)data; 31 | 32 | // Accessors 33 | - (NSString *)identifier; 34 | - (NSData *)data; 35 | - (NSURL *)URL; 36 | - (MGTwitterRequestType)requestType; 37 | - (MGTwitterResponseType)responseType; 38 | - (NSString *)description; 39 | 40 | @property (nonatomic, retain) NSHTTPURLResponse *response; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /oauthconsumer/Categories/NSURL+Base.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSURL+Base.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | 27 | #import 28 | 29 | 30 | @interface NSURL (OABaseAdditions) 31 | 32 | - (NSString *)URLStringWithoutQuery; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /oauthconsumer/OAProblem.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAProblem.h 3 | // OAuthConsumer 4 | // 5 | // Created by Alberto García Hierro on 03/09/08. 6 | // Copyright 2008 Alberto García Hierro. All rights reserved. 7 | // bynotes.com 8 | 9 | #import 10 | 11 | enum { 12 | kOAProblemSignatureMethodRejected = 0, 13 | kOAProblemParameterAbsent, 14 | kOAProblemVersionRejected, 15 | kOAProblemConsumerKeyUnknown, 16 | kOAProblemTokenRejected, 17 | kOAProblemSignatureInvalid, 18 | kOAProblemNonceUsed, 19 | kOAProblemTimestampRefused, 20 | kOAProblemTokenExpired, 21 | kOAProblemTokenNotRenewable 22 | }; 23 | 24 | @interface OAProblem : NSObject { 25 | const NSString *problem; 26 | } 27 | 28 | @property (readonly) const NSString *problem; 29 | 30 | - (id)initWithProblem:(const NSString *)aProblem; 31 | - (id)initWithResponseBody:(const NSString *)response; 32 | 33 | - (BOOL)isEqualToProblem:(OAProblem *)aProblem; 34 | - (BOOL)isEqualToString:(const NSString *)aProblem; 35 | - (BOOL)isEqualTo:(id)aProblem; 36 | - (int)code; 37 | 38 | + (OAProblem *)problemWithResponseBody:(const NSString *)response; 39 | 40 | + (const NSArray *)validProblems; 41 | 42 | + (OAProblem *)SignatureMethodRejected; 43 | + (OAProblem *)ParameterAbsent; 44 | + (OAProblem *)VersionRejected; 45 | + (OAProblem *)ConsumerKeyUnknown; 46 | + (OAProblem *)TokenRejected; 47 | + (OAProblem *)SignatureInvalid; 48 | + (OAProblem *)NonceUsed; 49 | + (OAProblem *)TimestampRefused; 50 | + (OAProblem *)TokenExpired; 51 | + (OAProblem *)TokenNotRenewable; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /oauthconsumer/OAPlaintextSignatureProvider.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAPlaintextSignatureProvider.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | 27 | #import 28 | #import "OASignatureProviding.h" 29 | 30 | @interface OAPlaintextSignatureProvider : NSObject 31 | @end 32 | -------------------------------------------------------------------------------- /oauthconsumer/OASignatureProviding.h: -------------------------------------------------------------------------------- 1 | // 2 | // OASignatureProviding.h 3 | // 4 | // Created by Jon Crosby on 10/19/07. 5 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | 26 | #import 27 | 28 | 29 | @protocol OASignatureProviding 30 | 31 | - (NSString *)name; 32 | - (NSString *)signClearText:(NSString *)text withSecret:(NSString *)secret; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /MGTwitterTouchJSONParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterTouchJSONParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Steve Streza on 3/24/10. 6 | // Copyright 2010 MGTwitterEngine. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "MGTwitterParserDelegate.h" 12 | #import "MGTwitterEngineDelegate.h" 13 | 14 | @interface MGTwitterTouchJSONParser : NSObject { 15 | __weak NSObject *delegate; // weak ref 16 | NSString *identifier; 17 | MGTwitterRequestType requestType; 18 | MGTwitterResponseType responseType; 19 | NSURL *URL; 20 | NSData *json; 21 | NSMutableArray *parsedObjects; 22 | MGTwitterEngineDeliveryOptions deliveryOptions; 23 | } 24 | 25 | + (id)parserWithJSON:(NSData *)theJSON 26 | delegate:(NSObject *)theDelegate 27 | connectionIdentifier:(NSString *)identifier 28 | requestType:(MGTwitterRequestType)reqType 29 | responseType:(MGTwitterResponseType)respType 30 | URL:(NSURL *)URL 31 | deliveryOptions:(MGTwitterEngineDeliveryOptions)deliveryOptions; 32 | - (id)initWithJSON:(NSData *)theJSON 33 | delegate:(NSObject *)theDelegate 34 | connectionIdentifier:(NSString *)identifier 35 | requestType:(MGTwitterRequestType)reqType 36 | responseType:(MGTwitterResponseType)respType 37 | URL:(NSURL *)URL 38 | deliveryOptions:(MGTwitterEngineDeliveryOptions)deliveryOptions; 39 | 40 | // delegate callbacks 41 | - (void)_parsingDidEnd; 42 | - (void)_parsingErrorOccurred:(NSError *)parseError; 43 | - (void)_parsedObject:(NSDictionary *)dictionary; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /oauthconsumer/OAHMAC_SHA1SignatureProvider.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAHMAC_SHA1SignatureProvider.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | 27 | #import 28 | #import "OASignatureProviding.h" 29 | 30 | 31 | @interface OAHMAC_SHA1SignatureProvider : NSObject 32 | @end 33 | -------------------------------------------------------------------------------- /MGTwitterMiscLibXMLParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMiscLibXMLParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterMiscLibXMLParser.h" 10 | 11 | 12 | @implementation MGTwitterMiscLibXMLParser 13 | 14 | - (void)parse 15 | { 16 | int readerResult = xmlTextReaderRead(_reader); 17 | if (readerResult != 1) 18 | return; 19 | 20 | int nodeType = xmlTextReaderNodeType(_reader); 21 | const xmlChar *name = xmlTextReaderConstName(_reader); 22 | while (! (nodeType == XML_READER_TYPE_END_ELEMENT)) 23 | { 24 | if (nodeType == XML_READER_TYPE_ELEMENT) 25 | { 26 | if (xmlStrEqual(name, BAD_CAST "hash")) 27 | { 28 | [parsedObjects addObject:[self _hashDictionaryForNodeWithName:name]]; 29 | } 30 | else 31 | { 32 | // process element as a string -- API calls like friendships/exists.xml just return false or true 33 | NSString *string = [self _nodeValueAsString]; 34 | if (string) 35 | { 36 | NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; 37 | [dictionary setObject:string forKey:[NSString stringWithUTF8String:(const char *)name]]; 38 | [parsedObjects addObject:dictionary]; 39 | } 40 | } 41 | } 42 | 43 | // advance reader 44 | readerResult = xmlTextReaderRead(_reader); 45 | if (readerResult != 1) 46 | { 47 | break; 48 | } 49 | nodeType = xmlTextReaderNodeType(_reader); 50 | name = xmlTextReaderConstName(_reader); 51 | } 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /oauthconsumer/Crypto/hmac.h: -------------------------------------------------------------------------------- 1 | // 2 | // hmac.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jonathan Wight on 4/8/8. 6 | // Copyright 2008 Jonathan Wight. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | #ifndef HMAC_H 27 | #define HMAC_H 1 28 | 29 | extern void hmac_sha1(const unsigned char *inText, int inTextLength, unsigned char* inKey, const unsigned int inKeyLength, unsigned char *outDigest); 30 | 31 | #endif /* HMAC_H */ 32 | -------------------------------------------------------------------------------- /TouchJSON/Source/Extensions/NSCharacterSet_Extensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSCharacterSet_Extensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 12/08/2005. 6 | // Copyright 2005 toxicsoftware.com. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | @interface NSCharacterSet (NSCharacterSet_Extensions) 33 | 34 | + (NSCharacterSet *)linebreaksCharacterSet; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /MGTwitterMiscParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMiscParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 06/06/2008. 6 | // Copyright 2008 Instinctive Code. All rights reserved. 7 | // 8 | 9 | #import "MGTwitterMiscParser.h" 10 | 11 | 12 | @implementation MGTwitterMiscParser 13 | 14 | 15 | #pragma mark NSXMLParser delegate methods 16 | 17 | 18 | - (void)parser:(NSXMLParser *)theParser didStartElement:(NSString *)elementName 19 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 20 | attributes:(NSDictionary *)attributeDict 21 | { 22 | //NSLog(@"Started element: %@ (%@)", elementName, attributeDict); 23 | [self setLastOpenedElement:elementName]; 24 | 25 | if (!currentNode) { 26 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 27 | [parsedObjects addObject:newNode]; 28 | currentNode = newNode; 29 | } 30 | 31 | // Create relevant name-value pair. 32 | [currentNode setObject:[NSMutableString string] forKey:elementName]; 33 | } 34 | 35 | 36 | - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName 37 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 38 | { 39 | [super parser:theParser didEndElement:elementName namespaceURI:namespaceURI qualifiedName:qName]; 40 | 41 | if ([elementName isEqualToString:@"remaining_hits"]) { 42 | NSNumber *hits = [NSNumber numberWithInt:[[currentNode objectForKey:elementName] intValue]]; 43 | [currentNode setObject:hits forKey:elementName]; 44 | } 45 | } 46 | 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /oauthconsumer/Categories/NSString+URLEncoding.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+URLEncoding.h 3 | // 4 | // Created by Jon Crosby on 10/19/07. 5 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | 26 | #import 27 | 28 | 29 | @interface NSString (OAURLEncodingAdditions) 30 | 31 | - (NSString *)encodedURLString; 32 | - (NSString *)encodedURLParameterString; 33 | - (NSString *)decodedURLString; 34 | - (NSString *)removeQuotes; 35 | @end 36 | -------------------------------------------------------------------------------- /TouchJSON/Source/Extensions/NSDictionary_JSONExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary_JSONExtensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 04/17/08. 6 | // Copyright 2008 toxicsoftware.com. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | @interface NSDictionary (NSDictionary_JSONExtensions) 33 | 34 | + (id)dictionaryWithJSONData:(NSData *)inData error:(NSError **)outError; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /oauthconsumer/Categories/NSURL+Base.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSURL+Base.m 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | 27 | #import "NSURL+Base.h" 28 | 29 | 30 | @implementation NSURL (OABaseAdditions) 31 | 32 | - (NSString *)URLStringWithoutQuery { 33 | NSArray *parts = [[self absoluteString] componentsSeparatedByString:@"?"]; 34 | return [parts objectAtIndex:0]; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /Classes/StreamingDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // StreamingDelegate.m 3 | // TwitterCommonLibrary 4 | // 5 | // Created by Tim Shi on 11-01-07. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "StreamingDelegate.h" 10 | 11 | 12 | @implementation StreamingDelegate 13 | 14 | - (id)init 15 | { 16 | return [self initWithConsumer:NULL] ; 17 | } 18 | 19 | -(id)initWithConsumer:(StreamingConsumer*)consumer { 20 | if(self = [super init]) { 21 | if (consumer != nil){ 22 | streamingConsumer = consumer; 23 | [streamingConsumer retain]; 24 | }else{ 25 | //TODO: throw an error here 26 | return nil; 27 | } 28 | } 29 | return self; 30 | } 31 | 32 | //TODO: the implementation should take care of the credential using OAuth 33 | - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { 34 | #ifdef DEBUG 35 | NSLog(@"recieved authentication challenge"); 36 | #endif 37 | [[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge]; 38 | return; 39 | } 40 | 41 | - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 42 | NSString *dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 43 | 44 | #ifdef DEBGUG 45 | NSLog(@"recieved data %@", dataString); 46 | #endif 47 | 48 | NSOperation* operation = [streamingConsumer taskWithData:dataString]; 49 | 50 | [[streamingConsumer operationQue] addOperation:operation]; 51 | 52 | [dataString release]; 53 | } 54 | 55 | -(void) dealloc{ 56 | [streamingConsumer release]; 57 | [super dealloc]; 58 | } 59 | @end 60 | -------------------------------------------------------------------------------- /NSData+Base64.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+Base64.m 3 | // 4 | // Derived from http://colloquy.info/project/browser/trunk/NSDataAdditions.h?rev=1576 5 | // Created by khammond on Mon Oct 29 2001. 6 | // Formatted by Timothy Hatcher on Sun Jul 4 2004. 7 | // Copyright (c) 2001 Kyle Hammond. All rights reserved. 8 | // Original development by Dave Winer. 9 | // 10 | 11 | #import "MGTwitterEngineGlobalHeader.h" 12 | 13 | @interface NSData (Base64) 14 | 15 | /*! @function +dataWithBase64EncodedString: 16 | @discussion This method returns an autoreleased NSData object. The NSData object is initialized with the 17 | contents of the Base 64 encoded string. This is a convenience method. 18 | @param inBase64String An NSString object that contains only Base 64 encoded data. 19 | @result The NSData object. */ 20 | + (NSData *) dataWithBase64EncodedString:(NSString *) string; 21 | 22 | /*! @function -initWithBase64EncodedString: 23 | @discussion The NSData object is initialized with the contents of the Base 64 encoded string. 24 | This method returns self as a convenience. 25 | @param inBase64String An NSString object that contains only Base 64 encoded data. 26 | @result This method returns self. */ 27 | - (id) initWithBase64EncodedString:(NSString *) string; 28 | 29 | /*! @function -base64EncodingWithLineLength: 30 | @discussion This method returns a Base 64 encoded string representation of the data object. 31 | @param inLineLength A value of zero means no line breaks. This is crunched to a multiple of 4 (the next 32 | one greater than inLineLength). 33 | @result The base 64 encoded data. */ 34 | - (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /oauthconsumer/OAPlaintextSignatureProvider.m: -------------------------------------------------------------------------------- 1 | // 2 | // OAPlaintextSignatureProvider.m 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | 27 | #import "OAPlaintextSignatureProvider.h" 28 | 29 | 30 | @implementation OAPlaintextSignatureProvider 31 | 32 | - (NSString *)name { 33 | return @"PLAINTEXT"; 34 | } 35 | 36 | - (NSString *)signClearText:(NSString *)text withSecret:(NSString *)secret { 37 | return secret; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /TouchJSON/Source/Extensions/CDataScanner_Extensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CDataScanner_Extensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 12/08/2005. 6 | // Copyright 2005 toxicsoftware.com. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "CDataScanner.h" 31 | 32 | @interface CDataScanner (CDataScanner_Extensions) 33 | 34 | - (BOOL)scanCStyleComment:(NSString **)outComment; 35 | - (BOOL)scanCPlusPlusStyleComment:(NSString **)outComment; 36 | 37 | - (NSUInteger)lineOfScanLocation; 38 | - (NSDictionary *)userInfoForScanLocation; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /oauthconsumer/OAConsumer.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAConsumer.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | 27 | #import 28 | 29 | 30 | @interface OAConsumer : NSObject { 31 | @protected 32 | NSString *key; 33 | NSString *secret; 34 | } 35 | @property(copy, readwrite) NSString *key; 36 | @property(copy, readwrite) NSString *secret; 37 | 38 | - (id)initWithKey:(const NSString *)aKey secret:(const NSString *)aSecret; 39 | 40 | - (BOOL)isEqualToConsumer:(OAConsumer *)aConsumer; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /MGTwitterLibXMLParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterLibXMLParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 18/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | #include 11 | 12 | #import "MGTwitterParserDelegate.h" 13 | 14 | @interface MGTwitterLibXMLParser : NSObject { 15 | __weak NSObject *delegate; // weak ref 16 | NSString *identifier; 17 | MGTwitterRequestType requestType; 18 | MGTwitterResponseType responseType; 19 | NSURL *URL; 20 | NSData *xml; 21 | NSMutableArray *parsedObjects; 22 | 23 | xmlTextReaderPtr _reader; 24 | } 25 | 26 | + (id)parserWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate 27 | connectionIdentifier:(NSString *)identifier requestType:(MGTwitterRequestType)reqType 28 | responseType:(MGTwitterResponseType)respType URL:(NSURL *)URL; 29 | - (id)initWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate 30 | connectionIdentifier:(NSString *)identifier requestType:(MGTwitterRequestType)reqType 31 | responseType:(MGTwitterResponseType)respType URL:(NSURL *)URL; 32 | 33 | - (void)parse; 34 | 35 | // subclass utilities 36 | - (xmlChar *)_nodeValue; 37 | - (NSString *)_nodeValueAsString; 38 | - (NSDate *)_nodeValueAsDate; 39 | - (NSNumber *)_nodeValueAsInt; 40 | - (NSNumber *)_nodeValueAsBool; 41 | - (NSDictionary *)_statusDictionaryForNodeWithName:(const xmlChar *)parentNodeName; 42 | - (NSDictionary *)_userDictionaryForNodeWithName:(const xmlChar *)parentNodeName; 43 | - (NSDictionary *)_hashDictionaryForNodeWithName:(const xmlChar *)parentNodeName; 44 | 45 | // delegate callbacks 46 | - (void)_parsingDidEnd; 47 | - (void)_parsingErrorOccurred:(NSError *)parseError; 48 | 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /TouchJSON/Source/Extensions/NSDictionary_JSONExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary_JSONExtensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 04/17/08. 6 | // Copyright 2008 toxicsoftware.com. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "NSDictionary_JSONExtensions.h" 31 | 32 | #import "CJSONDeserializer.h" 33 | 34 | @implementation NSDictionary (NSDictionary_JSONExtensions) 35 | 36 | + (id)dictionaryWithJSONData:(NSData *)inData error:(NSError **)outError 37 | { 38 | return([[CJSONDeserializer deserializer] deserialize:inData error:outError]); 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /oauthconsumer/Categories/NSMutableURLRequest+Parameters.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSMutableURLRequest+Parameters.h 3 | // 4 | // Created by Jon Crosby on 10/19/07. 5 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | #import 26 | #import "OARequestParameter.h" 27 | #import "NSURL+Base.h" 28 | 29 | 30 | @interface NSMutableURLRequest (OAParameterAdditions) 31 | 32 | @property(nonatomic, retain) NSArray *parameters; 33 | 34 | - (void)setHTTPBodyWithString:(NSString *)body; 35 | - (void)attachFileWithName:(NSString *)name filename:(NSString*)filename contentType:(NSString *)contentType data:(NSData*)data; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /TouchJSON/Source/Experimental/CFilteringJSONSerializer.m: -------------------------------------------------------------------------------- 1 | // 2 | // CFilteringJSONSerializer.m 3 | // CouchNotes 4 | // 5 | // Created by Jonathan Wight on 06/20/10. 6 | // Copyright 2010 toxicsoftware.com. All rights reserved. 7 | // 8 | 9 | #import "CFilteringJSONSerializer.h" 10 | 11 | @implementation CFilteringJSONSerializer 12 | 13 | @synthesize tests; 14 | @synthesize convertersByName; 15 | 16 | - (void)dealloc 17 | { 18 | [tests release]; 19 | tests = NULL; 20 | // 21 | [convertersByName release]; 22 | convertersByName = NULL; 23 | // 24 | [super dealloc]; 25 | } 26 | 27 | - (NSData *)serializeObject:(id)inObject error:(NSError **)outError 28 | { 29 | NSData *theData = NULL; 30 | for (JSONConversionTest theTest in self.tests) 31 | { 32 | NSString *theName = theTest(inObject); 33 | if (theName != NULL) 34 | { 35 | id theObject = NULL; 36 | JSONConversionConverter theConverter = [self.convertersByName objectForKey:theName]; 37 | if (theConverter) 38 | { 39 | theObject = theConverter(inObject); 40 | } 41 | 42 | if (theObject) 43 | { 44 | if ([theObject isKindOfClass:[NSData class]]) 45 | { 46 | theData = theObject; 47 | break; 48 | } 49 | else 50 | { 51 | NSError *theError = NULL; 52 | theData = [super serializeObject:theObject error:&theError]; 53 | if (theData != NULL) 54 | { 55 | break; 56 | } 57 | } 58 | } 59 | } 60 | } 61 | 62 | if (theData == NULL) 63 | { 64 | theData = [super serializeObject:inObject error:outError]; 65 | } 66 | 67 | return(theData); 68 | } 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /TouchJSON/Source/Extensions/NSScanner_Extensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSScanner_Extensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 12/08/2005. 6 | // Copyright 2005 toxicsoftware.com. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | @interface NSScanner (NSScanner_Extensions) 33 | 34 | - (NSString *)remainingString; 35 | 36 | - (unichar)currentCharacter; 37 | - (unichar)scanCharacter; 38 | - (BOOL)scanCharacter:(unichar)inCharacter; 39 | - (void)backtrack:(unsigned)inCount; 40 | 41 | - (BOOL)scanCStyleComment:(NSString **)outComment; 42 | - (BOOL)scanCPlusPlusStyleComment:(NSString **)outComment; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /oauthconsumer/Crypto/Base64Transcoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Base64Transcoder.h 3 | * Base64Test 4 | * 5 | * Created by Jonathan Wight on Tue Mar 18 2003. 6 | * Copyright (c) 2003 Toxic Software. All rights reserved. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | * 26 | */ 27 | 28 | #include 29 | #include 30 | 31 | extern size_t EstimateBas64EncodedDataSize(size_t inDataSize); 32 | extern size_t EstimateBas64DecodedDataSize(size_t inDataSize); 33 | 34 | extern bool Base64EncodeData(const void *inInputData, size_t inInputDataSize, char *outOutputData, size_t *ioOutputDataSize); 35 | extern bool Base64DecodeData(const void *inInputData, size_t inInputDataSize, void *ioOutputData, size_t *ioOutputDataSize); 36 | 37 | -------------------------------------------------------------------------------- /oauthconsumer/OAuthConsumer.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAuthConsumer.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | #import 27 | #import "OAProblem.h" 28 | #import "OAToken.h" 29 | #import "OAConsumer.h" 30 | #import "OAMutableURLRequest.h" 31 | #import "NSString+URLEncoding.h" 32 | #import "NSMutableURLRequest+Parameters.h" 33 | #import "NSURL+Base.h" 34 | #import "OASignatureProviding.h" 35 | #import "OAHMAC_SHA1SignatureProvider.h" 36 | #import "OAPlaintextSignatureProvider.h" 37 | #import "OARequestParameter.h" 38 | #import "OAServiceTicket.h" 39 | #import "OADataFetcher.h" 40 | #import "OATokenManager.h" -------------------------------------------------------------------------------- /oauthconsumer/OACall.h: -------------------------------------------------------------------------------- 1 | // 2 | // OACall.h 3 | // OAuthConsumer 4 | // 5 | // Created by Alberto García Hierro on 04/09/08. 6 | // Copyright 2008 Alberto García Hierro. All rights reserved. 7 | // bynotes.com 8 | 9 | #import 10 | 11 | @class OAProblem; 12 | @class OACall; 13 | 14 | @protocol OACallDelegate 15 | 16 | - (void)call:(OACall *)call failedWithError:(NSError *)error; 17 | - (void)call:(OACall *)call failedWithProblem:(OAProblem *)problem; 18 | 19 | @end 20 | 21 | @class OAConsumer; 22 | @class OAToken; 23 | @class OADataFetcher; 24 | @class OAMutableURLRequest; 25 | @class OAServiceTicket; 26 | 27 | @interface OACall : NSObject { 28 | NSURL *url; 29 | NSString *method; 30 | NSArray *parameters; 31 | NSDictionary *files; 32 | NSObject *delegate; 33 | SEL finishedSelector; 34 | OADataFetcher *fetcher; 35 | OAMutableURLRequest *request; 36 | OAServiceTicket *ticket; 37 | } 38 | 39 | @property(readonly) NSURL *url; 40 | @property(readonly) NSString *method; 41 | @property(readonly) NSArray *parameters; 42 | @property(readonly) NSDictionary *files; 43 | @property(nonatomic, retain) OAServiceTicket *ticket; 44 | 45 | - (id)init; 46 | - (id)initWithURL:(NSURL *)aURL; 47 | - (id)initWithURL:(NSURL *)aURL method:(NSString *)aMethod; 48 | - (id)initWithURL:(NSURL *)aURL parameters:(NSArray *)theParameters; 49 | - (id)initWithURL:(NSURL *)aURL method:(NSString *)aMethod parameters:(NSArray *)theParameters; 50 | - (id)initWithURL:(NSURL *)aURL parameters:(NSArray *)theParameters files:(NSDictionary*)theFiles; 51 | 52 | - (id)initWithURL:(NSURL *)aURL 53 | method:(NSString *)aMethod 54 | parameters:(NSArray *)theParameters 55 | files:(NSDictionary*)theFiles; 56 | 57 | - (void)perform:(OAConsumer *)consumer 58 | token:(OAToken *)token 59 | realm:(NSString *)realm 60 | delegate:(NSObject *)aDelegate 61 | didFinish:(SEL)finished; 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /oauthconsumer/OADataFetcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // OADataFetcher.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 11/5/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | #import 27 | #import "OAMutableURLRequest.h" 28 | #import "OAServiceTicket.h" 29 | 30 | 31 | @interface OADataFetcher : NSObject { 32 | @private 33 | OAMutableURLRequest *request; 34 | NSURLResponse *response; 35 | NSURLConnection *connection; 36 | NSMutableData *responseData; 37 | id delegate; 38 | SEL didFinishSelector; 39 | SEL didFailSelector; 40 | } 41 | 42 | @property (nonatomic, assign) id delegate; 43 | 44 | - (void)fetchDataWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /oauthconsumer/OAServiceTicket.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAServiceTicket.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 11/5/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | 27 | #import 28 | #import "OAMutableURLRequest.h" 29 | 30 | 31 | @interface OAServiceTicket : NSObject { 32 | @private 33 | OAMutableURLRequest *request; 34 | NSURLResponse *response; 35 | NSData *data; 36 | BOOL didSucceed; 37 | } 38 | @property(readonly) OAMutableURLRequest *request; 39 | @property(readonly) NSURLResponse *response; 40 | @property(readonly) NSData *data; 41 | @property(readonly) BOOL didSucceed; 42 | @property(readonly) NSString *body; 43 | 44 | - (id)initWithRequest:(OAMutableURLRequest *)aRequest response:(NSURLResponse *)aResponse data:(NSData *)aData didSucceed:(BOOL)success; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /oauthconsumer/OARequestParameter.h: -------------------------------------------------------------------------------- 1 | // 2 | // OARequestParameter.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | 27 | #import 28 | #import "NSString+URLEncoding.h" 29 | 30 | 31 | @interface OARequestParameter : NSObject { 32 | @protected 33 | NSString *name; 34 | NSString *value; 35 | } 36 | @property(copy, readwrite) NSString *name; 37 | @property(copy, readwrite) NSString *value; 38 | 39 | - (id)initWithName:(NSString *)aName value:(NSString *)aValue; 40 | - (NSString *)URLEncodedName; 41 | - (NSString *)URLEncodedValue; 42 | - (NSString *)URLEncodedNameValuePair; 43 | 44 | - (BOOL)isEqualToRequestParameter:(OARequestParameter *)parameter; 45 | 46 | + (id)requestParameter:(NSString *)aName value:(NSString *)aValue; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /MGTwitterUsersParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterUsersParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 19/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterUsersParser.h" 10 | 11 | 12 | @implementation MGTwitterUsersParser 13 | 14 | 15 | #pragma mark NSXMLParser delegate methods 16 | 17 | 18 | - (void)parser:(NSXMLParser *)theParser didStartElement:(NSString *)elementName 19 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 20 | attributes:(NSDictionary *)attributeDict 21 | { 22 | //NSLog(@"Started element: %@ (%@)", elementName, attributeDict); 23 | [self setLastOpenedElement:elementName]; 24 | 25 | if ([elementName isEqualToString:@"user"]) { 26 | // Make new entry in parsedObjects. 27 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 28 | [parsedObjects addObject:newNode]; 29 | currentNode = newNode; 30 | } else if ([elementName isEqualToString:@"status"]) { 31 | // Add an appropriate dictionary to current node. 32 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 33 | [currentNode setObject:newNode forKey:elementName]; 34 | currentNode = newNode; 35 | } else if (currentNode) { 36 | // Create relevant name-value pair. 37 | [currentNode setObject:[NSMutableString string] forKey:elementName]; 38 | } 39 | } 40 | 41 | 42 | - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName 43 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 44 | { 45 | [super parser:theParser didEndElement:elementName namespaceURI:namespaceURI qualifiedName:qName]; 46 | 47 | if ([elementName isEqualToString:@"status"]) { 48 | currentNode = [parsedObjects lastObject]; 49 | } else if ([elementName isEqualToString:@"user"]) { 50 | [self addSource]; 51 | currentNode = nil; 52 | } 53 | } 54 | 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /MGTwitterUserListsParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterUserListsParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Clinton Shryock on 6/10/10. 6 | // Copyright 2010 scary-robot. All rights reserved. 7 | // 8 | 9 | #import "MGTwitterUserListsParser.h" 10 | 11 | 12 | @implementation MGTwitterUserListsParser 13 | 14 | #pragma mark NSXMLParser delegate methods 15 | 16 | 17 | - (void)parser:(NSXMLParser *)theParser didStartElement:(NSString *)elementName 18 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 19 | attributes:(NSDictionary *)attributeDict 20 | { 21 | //NSLog(@"Started element: %@ (%@)", elementName, attributeDict); 22 | [self setLastOpenedElement:elementName]; 23 | 24 | if ([elementName isEqualToString:@"list"]) { 25 | // Make new entry in parsedObjects. 26 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 27 | [parsedObjects addObject:newNode]; 28 | currentNode = newNode; 29 | } else if ([elementName isEqualToString:@"user"]) { 30 | // Add a 'user' dictionary to current node. 31 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 32 | [currentNode setObject:newNode forKey:elementName]; 33 | currentNode = newNode; 34 | } else if (currentNode) { 35 | // Create relevant name-value pair. 36 | [currentNode setObject:[NSMutableString string] forKey:elementName]; 37 | } 38 | } 39 | 40 | - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName 41 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 42 | { 43 | [super parser:theParser didEndElement:elementName namespaceURI:namespaceURI qualifiedName:qName]; 44 | 45 | if ([elementName isEqualToString:@"list"]) { 46 | currentNode = [parsedObjects lastObject]; 47 | } else if ([elementName isEqualToString:@"user"]) { 48 | [self addSource]; 49 | currentNode = nil; 50 | } 51 | } 52 | 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /oauthconsumer/OAConsumer.m: -------------------------------------------------------------------------------- 1 | // 2 | // OAConsumer.m 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | #import "OAConsumer.h" 27 | 28 | 29 | @implementation OAConsumer 30 | @synthesize key, secret; 31 | 32 | #pragma mark init 33 | 34 | - (id)initWithKey:(const NSString *)aKey secret:(const NSString *)aSecret { 35 | [super init]; 36 | self.key = [aKey retain]; 37 | self.secret = [aSecret retain]; 38 | return self; 39 | } 40 | 41 | - (BOOL)isEqual:(id)object { 42 | if ([object isKindOfClass:[self class]]) { 43 | return [self isEqualToConsumer:(OAConsumer*)object]; 44 | } 45 | return NO; 46 | } 47 | 48 | - (BOOL)isEqualToConsumer:(OAConsumer *)aConsumer { 49 | return ([self.key isEqualToString:aConsumer.key] && 50 | [self.secret isEqualToString:aConsumer.secret]); 51 | } 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /TouchJSON/Source/Experimental/CJSONDeserializer_BlocksExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CJSONDeserializer_BlocksExtensions.m 3 | // TouchJSON 4 | // 5 | // Created by Jonathan Wight on 10/15/10. 6 | // Copyright 2010 toxicsoftware.com. All rights reserved. 7 | // 8 | 9 | #import "CJSONDeserializer_BlocksExtensions.h" 10 | 11 | #import "CJSONScanner.h" 12 | 13 | @implementation CJSONDeserializer (CJSONDeserializer_BlocksExtensions) 14 | 15 | - (void)deserializeAsDictionary:(NSData *)inData completionBlock:(void (^)(id result, NSError *error))block { 16 | 17 | NSError *noDataError = nil; 18 | if (inData == NULL || [inData length] == 0) { 19 | noDataError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL]; 20 | block(nil, noDataError); 21 | } 22 | 23 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 24 | 25 | NSError *deserializationError = nil; 26 | self.scanner.data = inData; 27 | NSDictionary *theDictionary = NULL; 28 | BOOL successful = [self.scanner scanJSONDictionary:&theDictionary error:&deserializationError]; 29 | 30 | dispatch_async(dispatch_get_main_queue (), ^{ 31 | if (successful) 32 | block(theDictionary, nil); 33 | else 34 | block(nil, deserializationError); 35 | }); 36 | }]; 37 | } 38 | 39 | - (void)deserializeAsArray:(NSData *)inData completionBlock:(void (^)(id result, NSError *error))block { 40 | 41 | NSError *nullInDataError = nil; 42 | if (inData == NULL || [inData length] == 0) { 43 | nullInDataError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL]; 44 | block(nil, nullInDataError); 45 | } 46 | 47 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 48 | 49 | NSError *deserializationError = nil; 50 | self.scanner.data = inData; 51 | NSArray *theArray = NULL; 52 | BOOL successful = [self.scanner scanJSONArray:&theArray error:&deserializationError]; 53 | 54 | dispatch_async(dispatch_get_main_queue(), ^{ 55 | if (successful) 56 | block(theArray, nil); 57 | else 58 | block(nil, deserializationError); 59 | }); 60 | }]; 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /oauthconsumer/OAServiceTicket.m: -------------------------------------------------------------------------------- 1 | // 2 | // OAServiceTicket.m 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 11/5/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | 27 | #import "OAServiceTicket.h" 28 | 29 | 30 | @implementation OAServiceTicket 31 | @synthesize request, response, data, didSucceed; 32 | 33 | - (id)initWithRequest:(OAMutableURLRequest *)aRequest response:(NSURLResponse *)aResponse data:(NSData *)aData didSucceed:(BOOL)success { 34 | [super init]; 35 | request = aRequest; 36 | response = aResponse; 37 | data = aData; 38 | didSucceed = success; 39 | return self; 40 | } 41 | 42 | - (NSString *)body 43 | { 44 | if (!data) { 45 | return nil; 46 | } 47 | 48 | return [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; 49 | } 50 | 51 | - (NSString *)description { 52 | return [NSString stringWithFormat:@"", [self body]]; 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /MGTwitterMessagesParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMessagesParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 19/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterMessagesParser.h" 10 | 11 | 12 | @implementation MGTwitterMessagesParser 13 | 14 | 15 | #pragma mark NSXMLParser delegate methods 16 | 17 | 18 | - (void)parser:(NSXMLParser *)theParser didStartElement:(NSString *)elementName 19 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 20 | attributes:(NSDictionary *)attributeDict 21 | { 22 | //NSLog(@"Started element: %@ (%@)", elementName, attributeDict); 23 | [self setLastOpenedElement:elementName]; 24 | 25 | if ([elementName isEqualToString:@"direct_message"]) { 26 | // Make new entry in parsedObjects. 27 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 28 | [parsedObjects addObject:newNode]; 29 | currentNode = newNode; 30 | } else if ([elementName isEqualToString:@"sender"] || [elementName isEqualToString:@"recipient"]) { 31 | // Add an appropriate dictionary to current node. 32 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 33 | [currentNode setObject:newNode forKey:elementName]; 34 | currentNode = newNode; 35 | } else if (currentNode) { 36 | // Create relevant name-value pair. 37 | [currentNode setObject:[NSMutableString string] forKey:elementName]; 38 | } 39 | } 40 | 41 | 42 | - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName 43 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 44 | { 45 | [super parser:theParser didEndElement:elementName namespaceURI:namespaceURI qualifiedName:qName]; 46 | 47 | if ([elementName isEqualToString:@"sender"] || [elementName isEqualToString:@"recipient"]) { 48 | currentNode = [parsedObjects lastObject]; 49 | } else if ([elementName isEqualToString:@"direct_message"]) { 50 | [self addSource]; 51 | currentNode = nil; 52 | } 53 | } 54 | 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /TouchJSON/Source/JSON/CJSONSerializer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJSONSerializer.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 12/07/2005. 6 | // Copyright 2005 toxicsoftware.com. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | @interface CJSONSerializer : NSObject { 33 | } 34 | 35 | + (id)serializer; 36 | 37 | /// Take any JSON compatible object (generally NSNull, NSNumber, NSString, NSArray and NSDictionary) and produce an NSData containing the serialized JSON. 38 | - (NSData *)serializeObject:(id)inObject error:(NSError **)outError; 39 | 40 | - (NSData *)serializeNull:(NSNull *)inNull error:(NSError **)outError; 41 | - (NSData *)serializeNumber:(NSNumber *)inNumber error:(NSError **)outError; 42 | - (NSData *)serializeString:(NSString *)inString error:(NSError **)outError; 43 | - (NSData *)serializeArray:(NSArray *)inArray error:(NSError **)outError; 44 | - (NSData *)serializeDictionary:(NSDictionary *)inDictionary error:(NSError **)outError; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /oauthconsumer/OATokenManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // OATokenManager.h 3 | // OAuthConsumer 4 | // 5 | // Created by Alberto García Hierro on 01/09/08. 6 | // Copyright 2008 Alberto García Hierro. All rights reserved. 7 | // bynotes.com 8 | 9 | #import 10 | 11 | #import "OACall.h" 12 | 13 | @class OATokenManager; 14 | 15 | @protocol OATokenManagerDelegate 16 | 17 | - (BOOL)tokenManager:(OATokenManager *)manager failedCall:(OACall *)call withError:(NSError *)error; 18 | - (BOOL)tokenManager:(OATokenManager *)manager failedCall:(OACall *)call withProblem:(OAProblem *)problem; 19 | 20 | @optional 21 | 22 | - (BOOL)tokenManagerNeedsToken:(OATokenManager *)manager; 23 | 24 | @end 25 | 26 | @class OAConsumer; 27 | @class OAToken; 28 | 29 | @interface OATokenManager : NSObject { 30 | OAConsumer *consumer; 31 | OAToken *acToken; 32 | OAToken *reqToken; 33 | OAToken *initialToken; 34 | NSString *authorizedTokenKey; 35 | NSString *oauthBase; 36 | NSString *realm; 37 | NSString *callback; 38 | NSObject *delegate; 39 | NSMutableArray *calls; 40 | NSMutableArray *selectors; 41 | NSMutableDictionary *delegates; 42 | BOOL isDispatching; 43 | } 44 | 45 | 46 | - (id)init; 47 | 48 | - (id)initWithConsumer:(OAConsumer *)aConsumer token:(OAToken *)aToken oauthBase:(const NSString *)base 49 | realm:(const NSString *)aRealm callback:(const NSString *)aCallback 50 | delegate:(NSObject *)aDelegate; 51 | 52 | - (void)authorizedToken:(const NSString *)key; 53 | 54 | - (void)fetchData:(NSString *)aURL finished:(SEL)didFinish; 55 | 56 | - (void)fetchData:(NSString *)aURL method:(NSString *)aMethod parameters:(NSArray *)theParameters 57 | finished:(SEL)didFinish; 58 | 59 | - (void)fetchData:(NSString *)aURL method:(NSString *)aMethod parameters:(NSArray *)theParameters 60 | files:(NSDictionary *)theFiles finished:(SEL)didFinish; 61 | 62 | - (void)fetchData:(NSString *)aURL method:(NSString *)aMethod parameters:(NSArray *)theParameters 63 | files:(NSDictionary *)theFiles finished:(SEL)didFinish delegate:(NSObject*)aDelegate; 64 | 65 | - (void)call:(OACall *)call failedWithError:(NSError *)error; 66 | - (void)call:(OACall *)call failedWithProblem:(OAProblem *)problem; 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /TouchJSON/Source/Extensions/NSCharacterSet_Extensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSCharacterSet_Extensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 12/08/2005. 6 | // Copyright 2005 toxicsoftware.com. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "NSCharacterSet_Extensions.h" 31 | 32 | @implementation NSCharacterSet (NSCharacterSet_Extensions) 33 | 34 | #define LF 0x000a // Line Feed 35 | #define FF 0x000c // Form Feed 36 | #define CR 0x000d // Carriage Return 37 | #define NEL 0x0085 // Next Line 38 | #define LS 0x2028 // Line Separator 39 | #define PS 0x2029 // Paragraph Separator 40 | 41 | static NSCharacterSet *sLineBreaksCharacterSet = NULL; 42 | 43 | + (NSCharacterSet *)linebreaksCharacterSet 44 | { 45 | @synchronized(self) 46 | { 47 | if (sLineBreaksCharacterSet == NULL) 48 | { 49 | unichar theCharacters[] = { LF, FF, CR, NEL, LS, PS, }; 50 | 51 | sLineBreaksCharacterSet = [[NSCharacterSet characterSetWithCharactersInString:[NSString stringWithCharacters:theCharacters length:sizeof(theCharacters) / sizeof(*theCharacters)]] retain]; 52 | } 53 | return(sLineBreaksCharacterSet); 54 | } 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /TouchJSON/Source/JSON/CJSONDeserializer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJSONDeserializer.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 12/15/2005. 6 | // Copyright 2005 toxicsoftware.com. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | extern NSString *const kJSONDeserializerErrorDomain /* = @"CJSONDeserializerErrorDomain" */; 33 | 34 | @class CJSONScanner; 35 | 36 | @interface CJSONDeserializer : NSObject { 37 | CJSONScanner *scanner; 38 | } 39 | 40 | @property (readwrite, nonatomic, retain) CJSONScanner *scanner; 41 | /// Object to return instead when a null encountered in the JSON. Defaults to NSNull. Setting to null causes the scanner to skip null values. 42 | @property (readwrite, nonatomic, retain) id nullObject; 43 | /// JSON must be encoded in Unicode (UTF-8, UTF-16 or UTF-32). Use this if you expect to get the JSON in another encoding. 44 | @property (readwrite, nonatomic, assign) NSStringEncoding allowedEncoding; 45 | 46 | + (id)deserializer; 47 | 48 | - (id)deserialize:(NSData *)inData error:(NSError **)outError; 49 | 50 | - (id)deserializeAsDictionary:(NSData *)inData error:(NSError **)outError; 51 | - (id)deserializeAsArray:(NSData *)inData error:(NSError **)outError; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /MGTwitterSocialGraphParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterSocialGraphParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Robert McGovern on 2010/03/19. 6 | // Copyright 2010 Tarasis. All rights reserved. 7 | // 8 | 9 | #import "MGTwitterSocialGraphParser.h" 10 | #import "MGTwitterMiscParser.h" 11 | 12 | 13 | @implementation MGTwitterSocialGraphParser 14 | 15 | 16 | #pragma mark NSXMLParser delegate methods 17 | 18 | 19 | - (void)parser:(NSXMLParser *)theParser didStartElement:(NSString *)elementName 20 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 21 | attributes:(NSDictionary *)attributeDict 22 | { 23 | //NSLog(@"SG: Started element: %@ (%@)", elementName, attributeDict); 24 | [self setLastOpenedElement:elementName]; 25 | 26 | if ([elementName isEqualToString:@"ids"]) { 27 | twitterIDs = [NSMutableArray arrayWithCapacity:0]; 28 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 29 | [parsedObjects addObject:newNode]; 30 | currentNode = newNode; 31 | } else if (currentNode && ![elementName isEqualToString:@"id"]) { 32 | // Create relevant name-value pair. 33 | [currentNode setObject:[NSMutableString string] forKey:elementName]; 34 | } 35 | } 36 | 37 | - (void)parser:(NSXMLParser *)theParser foundCharacters:(NSString *)characters 38 | { 39 | //NSLog(@"SG: Found characters: %@", characters); 40 | // Add the Twitter ID to the array 41 | if ([lastOpenedElement isEqualToString:@"id"]) { 42 | [twitterIDs addObject:characters]; 43 | // Append found characters to value of lastOpenedElement in currentNode. 44 | } else if (lastOpenedElement && currentNode) { 45 | [[currentNode objectForKey:lastOpenedElement] appendString:characters]; 46 | } 47 | } 48 | 49 | - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName 50 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 51 | { 52 | //NSLog(@"SG: didEndElement: %@", elementName); 53 | 54 | [super parser:theParser didEndElement:elementName namespaceURI:namespaceURI qualifiedName:qName]; 55 | 56 | // At the end of parsing, add the source type 57 | if ([elementName isEqualToString:@"id_list"]) { 58 | [self addSource]; 59 | currentNode = nil; 60 | } else if ([elementName isEqualToString:@"ids"]) { 61 | [currentNode setObject:twitterIDs forKey:elementName]; 62 | currentNode = [parsedObjects lastObject]; 63 | } 64 | } 65 | 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /TouchJSON/Source/JSON/CJSONScanner.h: -------------------------------------------------------------------------------- 1 | // 2 | // CJSONScanner.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 12/07/2005. 6 | // Copyright 2005 toxicsoftware.com. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "CDataScanner.h" 31 | 32 | /// CDataScanner subclass that understands JSON syntax natively. You should generally use CJSONDeserializer instead of this class. (TODO - this could have been a category?) 33 | @interface CJSONScanner : CDataScanner { 34 | BOOL strictEscapeCodes; 35 | id nullObject; 36 | NSStringEncoding allowedEncoding; 37 | } 38 | 39 | @property (readwrite, nonatomic, assign) BOOL strictEscapeCodes; 40 | @property (readwrite, nonatomic, retain) id nullObject; 41 | @property (readwrite, nonatomic, assign) NSStringEncoding allowedEncoding; 42 | 43 | - (BOOL)setData:(NSData *)inData error:(NSError **)outError; 44 | 45 | - (BOOL)scanJSONObject:(id *)outObject error:(NSError **)outError; 46 | - (BOOL)scanJSONDictionary:(NSDictionary **)outDictionary error:(NSError **)outError; 47 | - (BOOL)scanJSONArray:(NSArray **)outArray error:(NSError **)outError; 48 | - (BOOL)scanJSONStringConstant:(NSString **)outStringConstant error:(NSError **)outError; 49 | - (BOOL)scanJSONNumberConstant:(NSNumber **)outNumberConstant error:(NSError **)outError; 50 | 51 | @end 52 | 53 | extern NSString *const kJSONScannerErrorDomain /* = @"CJSONScannerErrorDomain" */; 54 | -------------------------------------------------------------------------------- /oauthconsumer/OAMutableURLRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAMutableURLRequest.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | 27 | #import 28 | #import "OAConsumer.h" 29 | #import "OAToken.h" 30 | #import "OAHMAC_SHA1SignatureProvider.h" 31 | #import "OASignatureProviding.h" 32 | #import "NSMutableURLRequest+Parameters.h" 33 | #import "NSURL+Base.h" 34 | 35 | 36 | @interface OAMutableURLRequest : NSMutableURLRequest { 37 | @protected 38 | OAConsumer *consumer; 39 | OAToken *token; 40 | NSString *realm; 41 | NSString *signature; 42 | id signatureProvider; 43 | NSString *nonce; 44 | NSString *timestamp; 45 | } 46 | @property(readonly) NSString *signature; 47 | @property(readonly) NSString *nonce; 48 | 49 | - (id)initWithURL:(NSURL *)aUrl 50 | consumer:(OAConsumer *)aConsumer 51 | token:(OAToken *)aToken 52 | realm:(NSString *)aRealm 53 | signatureProvider:(id)aProvider; 54 | 55 | - (id)initWithURL:(NSURL *)aUrl 56 | consumer:(OAConsumer *)aConsumer 57 | token:(OAToken *)aToken 58 | realm:(NSString *)aRealm 59 | signatureProvider:(id)aProvider 60 | nonce:(NSString *)aNonce 61 | timestamp:(NSString *)aTimestamp; 62 | 63 | - (void)prepare; 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /oauthconsumer/OARequestParameter.m: -------------------------------------------------------------------------------- 1 | // 2 | // OARequestParameter.m 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | 27 | #import "OARequestParameter.h" 28 | 29 | 30 | @implementation OARequestParameter 31 | @synthesize name, value; 32 | 33 | - (id)initWithName:(NSString *)aName value:(NSString *)aValue { 34 | [super init]; 35 | self.name = aName; 36 | self.value = aValue; 37 | return self; 38 | } 39 | 40 | - (NSString *)URLEncodedName { 41 | return self.name; 42 | // return [self.name encodedURLParameterString]; 43 | } 44 | 45 | - (NSString *)URLEncodedValue { 46 | return [self.value encodedURLParameterString]; 47 | } 48 | 49 | - (NSString *)URLEncodedNameValuePair { 50 | return [NSString stringWithFormat:@"%@=%@", [self URLEncodedName], [self URLEncodedValue]]; 51 | } 52 | 53 | - (BOOL)isEqual:(id)object { 54 | if ([object isKindOfClass:[self class]]) { 55 | return [self isEqualToRequestParameter:(OARequestParameter *)object]; 56 | } 57 | 58 | return NO; 59 | } 60 | 61 | - (BOOL)isEqualToRequestParameter:(OARequestParameter *)parameter { 62 | return ([self.name isEqualToString:parameter.name] && 63 | [self.value isEqualToString:parameter.value]); 64 | } 65 | 66 | 67 | + (id)requestParameter:(NSString *)aName value:(NSString *)aValue 68 | { 69 | return [[[self alloc] initWithName:aName value:aValue] autorelease]; 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /MGTwitterEngineGlobalHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterEngineGlobalHeader.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 09/08/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | /* 10 | This file conditionally includes the correct headers for either Mac OS X or iPhone deployment. 11 | */ 12 | 13 | #if TARGET_OS_IPHONE 14 | #import 15 | #import 16 | #else 17 | #import 18 | #endif 19 | 20 | /* 21 | Set YAJL_AVAILABLE to 1 if the YAJL JSON parser is available and you'd like MGTwitterEngine to use it. 22 | 23 | More information about this parser here: 24 | 25 | http://lloydforge.org/projects/yajl/ 26 | 27 | There are some speed advantages to using JSON instead of XML. Also, the Twitter Search API 28 | uses JSON, so adding this library to your project makes additional methods available to your 29 | application. 30 | 31 | Be aware, however, that the data types in the dictionaries returned by JSON may be different 32 | than the ones returned by XML. There is more type information in a JSON stream, so you may find 33 | that you get an NSNumber value instead of an NSString value for some keys in the dictionary. 34 | Make sure to test the new result sets in your application after switching from XML to JSON. 35 | 36 | Likewise, some keys may differ between the XML and JSON parsers. An example is the hourly limit 37 | returned by the getRateLimitStatus: method. For JSON, the key is "hourly_limit", for XML it is 38 | "hourly-limit". 39 | 40 | The event driven nature of the YAJL parser also allows delivery options to be specified. By 41 | default, all results are returned as an array of dictionaries. In some environments, such as the 42 | iPhone, the memory overhead of putting all the data into the array can be avoided by choosing 43 | the individual results option. This allows your application to process and store results without 44 | instantatiating a large collection and then enumerating over the items. 45 | 46 | If you want to use YAJL, change the following definition and make sure that the 47 | MGTwitterEngine*YAJLParser.m files are added to the Compile Sources phase of the MGTwitterEngine 48 | target. 49 | */ 50 | 51 | #define YAJL_AVAILABLE 0 52 | #define TOUCHJSON_AVAILABLE 1 53 | 54 | #ifndef __MGTWITTERENGINEID__ 55 | #define __MGTWITTERENGINEID__ 56 | typedef unsigned long long MGTwitterEngineID; 57 | typedef long long MGTwitterEngineCursorID; 58 | #endif 59 | 60 | #ifndef __MGTWITTERENGINELOCATIONDEGREES__ 61 | #define __MGTWITTERENGINELOCATIONDEGREES__ 62 | typedef double MGTwitterEngineLocationDegrees; 63 | #endif 64 | -------------------------------------------------------------------------------- /MGTwitterHTTPURLConnection.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterHTTPURLConnection.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 16/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterHTTPURLConnection.h" 10 | #import "NSString+UUID.h" 11 | 12 | 13 | 14 | @interface NSURLRequest (OAuthExtensions) 15 | -(void)prepare; 16 | @end 17 | 18 | @implementation NSURLRequest (OAuthExtensions) 19 | 20 | -(void)prepare{ 21 | // do nothing 22 | } 23 | 24 | @end 25 | 26 | 27 | 28 | @implementation MGTwitterHTTPURLConnection 29 | 30 | 31 | @synthesize response = _response; 32 | 33 | #pragma mark Initializer 34 | 35 | 36 | - (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate 37 | requestType:(MGTwitterRequestType)requestType responseType:(MGTwitterResponseType)responseType 38 | { 39 | // OAuth requests need to have -prepare called on them first. handle that case before the NSURLConnection sends it 40 | [request prepare]; 41 | 42 | if ((self = [super initWithRequest:request delegate:delegate])) { 43 | _data = [[NSMutableData alloc] initWithCapacity:0]; 44 | _identifier = [[NSString stringWithNewUUID] retain]; 45 | _requestType = requestType; 46 | _responseType = responseType; 47 | _URL = [[request URL] retain]; 48 | } 49 | 50 | return self; 51 | } 52 | 53 | 54 | - (void)dealloc 55 | { 56 | [_response release]; 57 | [_data release]; 58 | [_identifier release]; 59 | [_URL release]; 60 | [super dealloc]; 61 | } 62 | 63 | 64 | #pragma mark Data helper methods 65 | 66 | 67 | - (void)resetDataLength 68 | { 69 | [_data setLength:0]; 70 | } 71 | 72 | 73 | - (void)appendData:(NSData *)data 74 | { 75 | [_data appendData:data]; 76 | } 77 | 78 | 79 | #pragma mark Accessors 80 | 81 | 82 | - (NSString *)identifier 83 | { 84 | return [[_identifier retain] autorelease]; 85 | } 86 | 87 | 88 | - (NSData *)data 89 | { 90 | return [[_data retain] autorelease]; 91 | } 92 | 93 | 94 | - (NSURL *)URL 95 | { 96 | return [[_URL retain] autorelease]; 97 | } 98 | 99 | 100 | - (MGTwitterRequestType)requestType 101 | { 102 | return _requestType; 103 | } 104 | 105 | 106 | - (MGTwitterResponseType)responseType 107 | { 108 | return _responseType; 109 | } 110 | 111 | 112 | - (NSString *)description 113 | { 114 | NSString *description = [super description]; 115 | 116 | return [description stringByAppendingFormat:@" (requestType = %d, identifier = %@)", _requestType, _identifier]; 117 | } 118 | 119 | @end 120 | -------------------------------------------------------------------------------- /oauthconsumer/OAHMAC_SHA1SignatureProvider.m: -------------------------------------------------------------------------------- 1 | // 2 | // OAHMAC_SHA1SignatureProvider.m 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | 27 | #import "OAHMAC_SHA1SignatureProvider.h" 28 | 29 | // #include "hmac.h" 30 | #include "Base64Transcoder.h" 31 | 32 | #import 33 | #import 34 | 35 | @implementation OAHMAC_SHA1SignatureProvider 36 | 37 | - (NSString *)name { 38 | return @"HMAC-SHA1"; 39 | } 40 | 41 | - (NSString *)signClearText:(NSString *)text withSecret:(NSString *)secret { 42 | NSData *secretData = [secret dataUsingEncoding:NSUTF8StringEncoding]; 43 | NSData *clearTextData = [text dataUsingEncoding:NSUTF8StringEncoding]; 44 | unsigned char result[CC_SHA1_DIGEST_LENGTH]; 45 | 46 | // hmac_sha1((unsigned char *)[clearTextData bytes], [clearTextData length], (unsigned char *)[secretData bytes], [secretData length], result); 47 | 48 | CCHmac(kCCHmacAlgSHA1, (const void *)[secretData bytes], [secretData length], (const void *)[clearTextData bytes], [clearTextData length], result); 49 | 50 | //Base64 Encoding 51 | 52 | char base64Result[32]; 53 | size_t theResultLength = 32; 54 | Base64EncodeData(result, 20, base64Result, &theResultLength); 55 | NSData *theData = [NSData dataWithBytes:base64Result length:theResultLength]; 56 | 57 | NSString *base64EncodedResult = [[[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding] autorelease]; 58 | 59 | return base64EncodedResult; 60 | } 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /TouchJSON/Source/CDataScanner.h: -------------------------------------------------------------------------------- 1 | // 2 | // CDataScanner.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 04/16/08. 6 | // Copyright 2008 toxicsoftware.com. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | // NSScanner 33 | 34 | @interface CDataScanner : NSObject { 35 | NSData *data; 36 | 37 | u_int8_t *start; 38 | u_int8_t *end; 39 | u_int8_t *current; 40 | NSUInteger length; 41 | } 42 | 43 | @property (readwrite, nonatomic, retain) NSData *data; 44 | @property (readwrite, nonatomic, assign) NSUInteger scanLocation; 45 | @property (readonly, nonatomic, assign) NSUInteger bytesRemaining; 46 | @property (readonly, nonatomic, assign) BOOL isAtEnd; 47 | 48 | - (id)initWithData:(NSData *)inData; 49 | 50 | - (unichar)currentCharacter; 51 | - (unichar)scanCharacter; 52 | - (BOOL)scanCharacter:(unichar)inCharacter; 53 | 54 | - (BOOL)scanUTF8String:(const char *)inString intoString:(NSString **)outValue; 55 | - (BOOL)scanString:(NSString *)inString intoString:(NSString **)outValue; 56 | - (BOOL)scanCharactersFromSet:(NSCharacterSet *)inSet intoString:(NSString **)outValue; // inSet must only contain 7-bit ASCII characters 57 | 58 | - (BOOL)scanUpToString:(NSString *)string intoString:(NSString **)outValue; 59 | - (BOOL)scanUpToCharactersFromSet:(NSCharacterSet *)set intoString:(NSString **)outValue; // inSet must only contain 7-bit ASCII characters 60 | 61 | - (BOOL)scanNumber:(NSNumber **)outValue; 62 | - (BOOL)scanDecimalNumber:(NSDecimalNumber **)outValue; 63 | 64 | - (BOOL)scanDataOfLength:(NSUInteger)inLength intoData:(NSData **)outData; 65 | 66 | - (void)skipWhitespace; 67 | 68 | - (NSString *)remainingString; 69 | - (NSData *)remainingData; 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /MGTwitterEngineDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterEngineDelegate.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 16/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | @class OAToken; 11 | 12 | typedef enum _MGTwitterEngineDeliveryOptions { 13 | // all results will be delivered as an array via statusesReceived: and similar delegate methods 14 | MGTwitterEngineDeliveryAllResultsOption = 1 << 0, 15 | 16 | // individual results will be delivered as a dictionary via the receivedObject: delegate method 17 | MGTwitterEngineDeliveryIndividualResultsOption = 1 << 1, 18 | 19 | // these options can be combined with the | operator 20 | } MGTwitterEngineDeliveryOptions; 21 | 22 | 23 | 24 | @protocol MGTwitterEngineDelegate 25 | 26 | // These delegate methods are called after a connection has been established 27 | - (void)requestSucceeded:(NSString *)connectionIdentifier; 28 | - (void)requestFailed:(NSString *)connectionIdentifier withError:(NSError *)error; 29 | 30 | @optional 31 | 32 | #if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE 33 | // This delegate method is called each time a new result is parsed from the connection and 34 | // the deliveryOption is configured for MGTwitterEngineDeliveryIndividualResults. 35 | - (void)receivedObject:(NSDictionary *)dictionary forRequest:(NSString *)connectionIdentifier; 36 | #endif 37 | 38 | // These delegate methods are called after all results are parsed from the connection. If 39 | // the deliveryOption is configured for MGTwitterEngineDeliveryAllResults (the default), a 40 | // collection of all results is also returned. 41 | - (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier; 42 | - (void)directMessagesReceived:(NSArray *)messages forRequest:(NSString *)connectionIdentifier; 43 | - (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier; 44 | - (void)userListsReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier; 45 | - (void)miscInfoReceived:(NSArray *)miscInfo forRequest:(NSString *)connectionIdentifier; 46 | #if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE 47 | - (void)searchResultsReceived:(NSArray *)searchResults forRequest:(NSString *)connectionIdentifier; 48 | #endif 49 | - (void)socialGraphInfoReceived:(NSArray *)socialGraphInfo forRequest:(NSString *)connectionIdentifier; 50 | - (void)accessTokenReceived:(OAToken *)token forRequest:(NSString *)connectionIdentifier; 51 | 52 | #if TARGET_OS_IPHONE 53 | - (void)imageReceived:(UIImage *)image forRequest:(NSString *)connectionIdentifier; 54 | #else 55 | - (void)imageReceived:(NSImage *)image forRequest:(NSString *)connectionIdentifier; 56 | #endif 57 | 58 | // This delegate method is called whenever a connection has finished. 59 | - (void)connectionStarted:(NSString *)connectionIdentifier; 60 | - (void)connectionFinished:(NSString *)connectionIdentifier; 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /Classes/StreamingConsumer.m: -------------------------------------------------------------------------------- 1 | // 2 | // StreamingConsumer.m 3 | // TwitterCommonLibrary 4 | // 5 | // Created by Tim Shi on 11-01-07. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "StreamingConsumer.h" 10 | 11 | 12 | @implementation StreamingConsumer 13 | 14 | @synthesize operationQue; 15 | 16 | -(id)init{ 17 | if (self = [super init]){ 18 | holderString = [[NSMutableString alloc] init]; 19 | operationQue = [[NSOperationQueue alloc] init]; 20 | //process the task in serial 21 | [operationQue setMaxConcurrentOperationCount:1]; 22 | } 23 | return self; 24 | } 25 | 26 | #pragma mark delegate 27 | - (id)delegate { 28 | return delegate; 29 | } 30 | 31 | - (void)setDelegate:(id)newDelegate { 32 | delegate = newDelegate; 33 | } 34 | #pragma end delegate 35 | 36 | -(void) process:(NSString*)data{ 37 | [holderString appendString:[data stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 38 | 39 | NSRange range; 40 | 41 | range.location = [self parseStringWithDelimiter:@"%0D%0A" forString:holderString].location; 42 | range.length = [self parseStringWithDelimiter:@"%0D%0A" forString:holderString].length; 43 | 44 | if (range.location != NSNotFound){ 45 | NSString* jsonString = [holderString substringWithRange:range]; 46 | 47 | if ( [delegate respondsToSelector:@selector(consumerDidProcessStatus:)] ) { 48 | [delegate consumerDidProcessStatus:[jsonString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 49 | } 50 | 51 | if (range.location == 0 && range.length == 0){ 52 | //this means there is a carriage return, but it's at the ver begining of the string (duplicate carriage return for example) 53 | //so we have to remove it right away. 54 | NSRange carriageReturnRange; 55 | carriageReturnRange.location = range.location; 56 | carriageReturnRange.length = 6; 57 | [holderString deleteCharactersInRange:carriageReturnRange]; 58 | }else{ 59 | //delete the status that was parsed plus the carriage return character 60 | range.length = range.length + 6; 61 | [holderString deleteCharactersInRange:range]; 62 | } 63 | } 64 | } 65 | 66 | - (NSRange) parseStringWithDelimiter:(NSString*) delimiter forString:(NSString*) toBeParsed{ 67 | if([toBeParsed rangeOfString:delimiter].location != NSNotFound) { 68 | NSRange end = [toBeParsed rangeOfString:delimiter]; 69 | 70 | NSRange range; 71 | range.location = 0; 72 | range.length = end.location-0; 73 | 74 | return range; 75 | } 76 | return NSMakeRange(NSNotFound, 0); 77 | } 78 | 79 | #pragma mark operation 80 | - (NSOperation*)taskWithData:(NSString*)data { 81 | NSInvocationOperation* theOp = [[[NSInvocationOperation alloc] initWithTarget:self 82 | selector:@selector(process:) object:data] autorelease]; 83 | 84 | return theOp; 85 | } 86 | 87 | -(void)dealloc{ 88 | [operationQue release]; 89 | [holderString release]; 90 | [super dealloc]; 91 | } 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /oauthconsumer/OAToken.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAToken.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | #import 27 | 28 | @interface OAToken : NSObject { 29 | @protected 30 | NSString *key; 31 | NSString *secret; 32 | NSString *verifier; 33 | NSString *session; 34 | NSNumber *duration; 35 | NSMutableDictionary *attributes; 36 | NSDate *created; 37 | BOOL renewable; 38 | BOOL forRenewal; 39 | } 40 | @property(retain, readwrite) NSString *key; 41 | @property(retain, readwrite) NSString *secret; 42 | @property(retain, readwrite) NSString *verifier; 43 | @property(retain, readwrite) NSString *session; 44 | @property(retain, readwrite) NSNumber *duration; 45 | @property(retain, readwrite) NSDictionary *attributes; 46 | @property(readwrite, getter=isForRenewal) BOOL forRenewal; 47 | 48 | - (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret; 49 | - (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret verifier:(NSString *)aVerifier session:(NSString *)aSession 50 | duration:(NSNumber *)aDuration attributes:(NSDictionary *)theAttributes created:(NSDate *)creation 51 | renewable:(BOOL)renew; 52 | - (id)initWithHTTPResponseBody:(NSString *)body; 53 | 54 | - (id)initWithUserDefaultsUsingServiceProviderName:(NSString *)provider prefix:(NSString *)prefix; 55 | - (int)storeInUserDefaultsWithServiceProviderName:(NSString *)provider prefix:(NSString *)prefix; 56 | 57 | - (BOOL)isValid; 58 | 59 | - (void)setAttribute:(NSString *)aKey value:(NSString *)aValue; 60 | - (NSString *)attribute:(NSString *)aKey; 61 | - (void)setAttributesWithString:(NSString *)aAttributes; 62 | - (NSString *)attributeString; 63 | 64 | - (BOOL)hasExpired; 65 | - (BOOL)isRenewable; 66 | - (void)setDurationWithString:(NSString *)aDuration; 67 | - (BOOL)hasAttributes; 68 | - (NSDictionary *)parameters; 69 | 70 | - (BOOL)isEqualToToken:(OAToken *)aToken; 71 | 72 | + (void)removeFromUserDefaultsWithServiceProviderName:(const NSString *)provider prefix:(const NSString *)prefix; 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /MGTwitterStatusesParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterStatusesParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterStatusesParser.h" 10 | 11 | 12 | @implementation MGTwitterStatusesParser 13 | 14 | 15 | #pragma mark NSXMLParser delegate methods 16 | 17 | 18 | - (void)parser:(NSXMLParser *)theParser didStartElement:(NSString *)elementName 19 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 20 | attributes:(NSDictionary *)attributeDict 21 | { 22 | //NSLog(@"Started element: %@ (%@)", elementName, attributeDict); 23 | [self setLastOpenedElement:elementName]; 24 | 25 | if ([elementName isEqualToString:@"status"]) { 26 | // Make new entry in parsedObjects. 27 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 28 | [parsedObjects addObject:newNode]; 29 | currentNode = newNode; 30 | } else if ([elementName isEqualToString:@"user"]) { 31 | // Add a 'user' dictionary to current node. 32 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 33 | [currentNode setObject:newNode forKey:elementName]; 34 | currentNode = newNode; 35 | } else if ([elementName isEqualToString:@"place"]) { 36 | // Add a 'place' dictionary to current node. 37 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 38 | [currentNode setObject:newNode forKey:elementName]; 39 | currentNode = newNode; 40 | } else if ([elementName isEqualToString:@"retweeted_status"]) { 41 | // Add a 'retweet_status' dictionary to current node. 42 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 43 | [currentNode setObject:newNode forKey:elementName]; 44 | currentNode = newNode; 45 | } else if (currentNode) { 46 | // Create relevant name-value pair. 47 | [currentNode setObject:[NSMutableString string] forKey:elementName]; 48 | } 49 | } 50 | 51 | 52 | - (void)parser:(NSXMLParser *)theParser foundCharacters:(NSString *)characters 53 | { 54 | //NSLog(@"Found characters: %@", characters); 55 | // Append found characters to value of lastOpenedElement in currentNode. 56 | if (lastOpenedElement && currentNode) { 57 | [[currentNode objectForKey:lastOpenedElement] appendString:characters]; 58 | } 59 | } 60 | 61 | 62 | - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName 63 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 64 | { 65 | [super parser:theParser didEndElement:elementName namespaceURI:namespaceURI qualifiedName:qName]; 66 | 67 | if ([elementName isEqualToString:@"user"]) { 68 | currentNode = [parsedObjects lastObject]; 69 | } else if ([elementName isEqualToString:@"place"]) { 70 | currentNode = [parsedObjects lastObject]; 71 | } else if ([elementName isEqualToString:@"retweeted_status"]) { 72 | currentNode = [parsedObjects lastObject]; 73 | } else if ([elementName isEqualToString:@"status"]) { 74 | [self addSource]; 75 | currentNode = nil; 76 | } 77 | } 78 | 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /oauthconsumer/Crypto/hmac.c: -------------------------------------------------------------------------------- 1 | // 2 | // hmac.c 3 | // OAuthConsumer 4 | // 5 | // Created by Jonathan Wight on 4/8/8. 6 | // Copyright 2008 Jonathan Wight. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | /* 27 | * Implementation of HMAC-SHA1. Adapted from example at http://tools.ietf.org/html/rfc2104 28 | 29 | */ 30 | 31 | #include "sha1.h" 32 | #include "hmac.h" 33 | 34 | #include 35 | #include 36 | 37 | void hmac_sha1(const unsigned char *inText, int inTextLength, unsigned char* inKey, const unsigned int inKeyLengthConst, unsigned char *outDigest) 38 | { 39 | const int B = 64; 40 | const size_t L = 20; 41 | 42 | SHA1_CTX theSHA1Context; 43 | unsigned char k_ipad[B + 1]; /* inner padding - key XORd with ipad */ 44 | unsigned char k_opad[B + 1]; /* outer padding - key XORd with opad */ 45 | 46 | /* if key is longer than 64 bytes reset it to key=SHA1 (key) */ 47 | unsigned int inKeyLength = inKeyLengthConst; 48 | if (inKeyLength > B) 49 | { 50 | SHA1Init(&theSHA1Context); 51 | SHA1Update(&theSHA1Context, inKey, inKeyLength); 52 | SHA1Final(inKey, &theSHA1Context); 53 | inKeyLength = L; 54 | } 55 | 56 | /* start out by storing key in pads */ 57 | memset(k_ipad, 0, sizeof k_ipad); 58 | memset(k_opad, 0, sizeof k_opad); 59 | memcpy(k_ipad, inKey, inKeyLength); 60 | memcpy(k_opad, inKey, inKeyLength); 61 | 62 | /* XOR key with ipad and opad values */ 63 | int i; 64 | for (i = 0; i < B; i++) 65 | { 66 | k_ipad[i] ^= 0x36; 67 | k_opad[i] ^= 0x5c; 68 | } 69 | 70 | /* 71 | * perform inner SHA1 72 | */ 73 | SHA1Init(&theSHA1Context); /* init context for 1st pass */ 74 | SHA1Update(&theSHA1Context, k_ipad, B); /* start with inner pad */ 75 | SHA1Update(&theSHA1Context, (unsigned char *)inText, inTextLength); /* then text of datagram */ 76 | SHA1Final((unsigned char *)outDigest, &theSHA1Context); /* finish up 1st pass */ 77 | 78 | /* 79 | * perform outer SHA1 80 | */ 81 | SHA1Init(&theSHA1Context); /* init context for 2nd 82 | * pass */ 83 | SHA1Update(&theSHA1Context, k_opad, B); /* start with outer pad */ 84 | SHA1Update(&theSHA1Context, outDigest, L); /* then results of 1st 85 | * hash */ 86 | SHA1Final(outDigest, &theSHA1Context); /* finish up 2nd pass */ 87 | 88 | } 89 | -------------------------------------------------------------------------------- /MGTwitterSocialGraphLibXMLParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterSocialGraphLibXMLParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Robert McGovern on 2010/03/20. 6 | // Copyright 2010 Tarasis. All rights reserved. 7 | // 8 | 9 | #import "MGTwitterSocialGraphLibXMLParser.h" 10 | 11 | 12 | @implementation MGTwitterSocialGraphLibXMLParser 13 | - (void)parse 14 | { 15 | int readerResult = xmlTextReaderRead(_reader); 16 | if (readerResult != 1) 17 | return; 18 | 19 | int nodeType = xmlTextReaderNodeType(_reader); 20 | const xmlChar *name = xmlTextReaderConstName(_reader); 21 | 22 | NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; 23 | 24 | while (! (nodeType == XML_READER_TYPE_END_ELEMENT)) 25 | { 26 | //NSLog(@"name is: %@", [NSString stringWithUTF8String:(const char *)name]); 27 | if (nodeType == XML_READER_TYPE_ELEMENT) 28 | { 29 | if (xmlStrEqual(name, BAD_CAST "ids")) 30 | { 31 | [dictionary addEntriesFromDictionary:[self _socialGraphDictionaryForNodeWithName:name]]; 32 | } 33 | else if (xmlStrEqual(BAD_CAST "previous_cursor", name) || xmlStrEqual(BAD_CAST "next_cursor", name)) 34 | { 35 | // process element as a string -- API calls like friendships/exists.xml just return false or true 36 | NSString *string = [self _nodeValueAsString]; 37 | if (string) 38 | { 39 | [dictionary setObject:string forKey:[NSString stringWithUTF8String:(const char *)name]]; 40 | } 41 | } 42 | 43 | } 44 | 45 | // advance reader 46 | readerResult = xmlTextReaderRead(_reader); 47 | if (readerResult != 1) 48 | { 49 | break; 50 | } 51 | nodeType = xmlTextReaderNodeType(_reader); 52 | name = xmlTextReaderConstName(_reader); 53 | } 54 | 55 | [dictionary setObject:[NSNumber numberWithInt:requestType] forKey:TWITTER_SOURCE_REQUEST_TYPE]; 56 | [parsedObjects addObject:dictionary]; 57 | } 58 | 59 | - (NSDictionary *)_socialGraphDictionaryForNodeWithName:(const xmlChar *)parentNodeName 60 | { 61 | if (xmlTextReaderIsEmptyElement(_reader)) 62 | return nil; 63 | NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; 64 | twitterIDs = [NSMutableArray arrayWithCapacity:0]; 65 | 66 | int readerResult = xmlTextReaderRead(_reader); 67 | if (readerResult != 1) 68 | return nil; 69 | int nodeType = xmlTextReaderNodeType(_reader); 70 | const xmlChar *name = xmlTextReaderConstName(_reader); 71 | while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(parentNodeName, name))) 72 | { 73 | if (nodeType == XML_READER_TYPE_ELEMENT) 74 | { 75 | //NSLog(@" name is: %@", [NSString stringWithUTF8String:(const char *)name]); 76 | // process element as an integer 77 | NSNumber *number = [self _nodeValueAsInt]; 78 | if (number) 79 | { 80 | //[dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]]; 81 | [twitterIDs addObject:number]; 82 | } 83 | } 84 | 85 | // advance reader 86 | readerResult = xmlTextReaderRead(_reader); 87 | if (readerResult != 1) 88 | break; 89 | nodeType = xmlTextReaderNodeType(_reader); 90 | name = xmlTextReaderConstName(_reader); 91 | } 92 | 93 | [dictionary setObject:twitterIDs forKey:[NSString stringWithUTF8String:(const char *)name]]; 94 | 95 | return dictionary; 96 | } 97 | 98 | 99 | @end 100 | -------------------------------------------------------------------------------- /oauthconsumer/Categories/NSString+URLEncoding.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+URLEncoding.m 3 | // 4 | // Created by Jon Crosby on 10/19/07. 5 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | 26 | #import "NSString+URLEncoding.h" 27 | 28 | 29 | @implementation NSString (OAURLEncodingAdditions) 30 | 31 | - (NSString *)encodedURLString { 32 | NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, 33 | (CFStringRef)self, 34 | NULL, // characters to leave unescaped (NULL = all escaped sequences are replaced) 35 | CFSTR("?=&+"), // legal URL characters to be escaped (NULL = all legal characters are replaced) 36 | kCFStringEncodingUTF8); // encoding 37 | return [result autorelease]; 38 | } 39 | 40 | - (NSString *)encodedURLParameterString { 41 | NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, 42 | (CFStringRef)self, 43 | NULL, 44 | CFSTR(":/=,!$&'()*+;[]@#?"), 45 | kCFStringEncodingUTF8); 46 | return [result autorelease]; 47 | } 48 | 49 | - (NSString *)decodedURLString { 50 | NSString *result = (NSString*)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, 51 | (CFStringRef)self, 52 | CFSTR(""), 53 | kCFStringEncodingUTF8); 54 | 55 | return [result autorelease]; 56 | 57 | } 58 | 59 | -(NSString *)removeQuotes 60 | { 61 | NSUInteger length = [self length]; 62 | NSString *ret = self; 63 | if ([self characterAtIndex:0] == '"') { 64 | ret = [ret substringFromIndex:1]; 65 | } 66 | if ([self characterAtIndex:length - 1] == '"') { 67 | ret = [ret substringToIndex:length - 2]; 68 | } 69 | 70 | return ret; 71 | } 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /oauthconsumer/OADataFetcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // OADataFetcher.m 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 11/5/07. 6 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | 26 | 27 | #import "OADataFetcher.h" 28 | 29 | 30 | @implementation OADataFetcher 31 | 32 | 33 | @synthesize delegate; 34 | 35 | - (id)init { 36 | [super init]; 37 | responseData = [[NSMutableData alloc] init]; 38 | return self; 39 | } 40 | 41 | - (void)dealloc { 42 | [connection release]; 43 | [response release]; 44 | [responseData release]; 45 | [request release]; 46 | [super dealloc]; 47 | } 48 | 49 | /* Protocol for async URL loading */ 50 | - (void)connection:(NSURLConnection *)aConnection didReceiveResponse:(NSURLResponse *)aResponse { 51 | [response release]; 52 | response = [aResponse retain]; 53 | [responseData setLength:0]; 54 | } 55 | 56 | - (void)connection:(NSURLConnection *)aConnection didFailWithError:(NSError *)error { 57 | OAServiceTicket *ticket = [[OAServiceTicket alloc] initWithRequest:request 58 | response:response 59 | data:responseData 60 | didSucceed:NO]; 61 | [ticket autorelease]; 62 | [delegate performSelector:didFailSelector withObject:ticket withObject:error]; 63 | //TODO: document this, obviously you don't autorelease and then release again! 64 | //[ticket release], ticket = nil; 65 | } 66 | 67 | - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 68 | [responseData appendData:data]; 69 | } 70 | 71 | - (void)connectionDidFinishLoading:(NSURLConnection *)connection { 72 | OAServiceTicket *ticket = [[OAServiceTicket alloc] initWithRequest:request 73 | response:response 74 | data:responseData 75 | didSucceed:[(NSHTTPURLResponse *)response statusCode] < 400]; 76 | [ticket autorelease]; 77 | [delegate performSelector:didFinishSelector withObject:ticket withObject:responseData]; 78 | 79 | //TODO: document this, obviously you don't autorelease and then release again! 80 | //[ticket release], ticket = nil; 81 | } 82 | 83 | - (void)fetchDataWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector { 84 | request = [aRequest retain]; 85 | delegate = aDelegate; 86 | didFinishSelector = finishSelector; 87 | didFailSelector = failSelector; 88 | 89 | [request prepare]; 90 | 91 | connection = [[NSURLConnection alloc] initWithRequest:aRequest delegate:self]; 92 | } 93 | 94 | @end 95 | -------------------------------------------------------------------------------- /MGTwitterMessagesLibXMLParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMessagesLibXMLParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterMessagesLibXMLParser.h" 10 | 11 | 12 | @implementation MGTwitterMessagesLibXMLParser 13 | 14 | - (NSDictionary *)_directMessageDictionaryForNodeWithName:(const xmlChar *)parentNodeName { 15 | if (xmlTextReaderIsEmptyElement(_reader)) 16 | return nil; 17 | NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; 18 | 19 | int readerResult = xmlTextReaderRead(_reader); 20 | if (readerResult != 1) 21 | return nil; 22 | int nodeType = xmlTextReaderNodeType(_reader); 23 | const xmlChar *name = xmlTextReaderConstName(_reader); 24 | while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(parentNodeName, name))) 25 | { 26 | if (nodeType == XML_READER_TYPE_ELEMENT) 27 | { 28 | if (xmlStrEqual(name, BAD_CAST "sender") || xmlStrEqual(name, BAD_CAST "recipient")) 29 | { 30 | // "user" is the name of a sub-dictionary in each item 31 | [dictionary setObject:[self _userDictionaryForNodeWithName:name] forKey:[NSString stringWithUTF8String:(const char *)name]]; 32 | } 33 | else if (xmlStrEqual(name, BAD_CAST "id") || xmlStrEqual(name, BAD_CAST "sender_id") || xmlStrEqual(name, BAD_CAST "recipient_id")) 34 | { 35 | // process element as an integer 36 | NSNumber *number = [self _nodeValueAsInt]; 37 | if (number) 38 | { 39 | [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]]; 40 | } 41 | } 42 | else if (xmlStrEqual(name, BAD_CAST "created_at")) 43 | { 44 | // process element as a date 45 | NSDate *date = [self _nodeValueAsDate]; 46 | if (date) 47 | { 48 | [dictionary setObject:date forKey:[NSString stringWithUTF8String:(const char *)name]]; 49 | } 50 | } 51 | else if (xmlStrEqual(name, BAD_CAST "protected")) 52 | { 53 | // process element as a boolean 54 | NSNumber *number = [self _nodeValueAsBool]; 55 | if (number) 56 | { 57 | [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]]; 58 | } 59 | } 60 | else 61 | { 62 | // process element as a string 63 | NSString *string = [self _nodeValueAsString]; 64 | if (string) 65 | { 66 | [dictionary setObject:string forKey:[NSString stringWithUTF8String:(const char *)name]]; 67 | } 68 | } 69 | } 70 | 71 | // advance reader 72 | readerResult = xmlTextReaderRead(_reader); 73 | if (readerResult != 1) 74 | break; 75 | nodeType = xmlTextReaderNodeType(_reader); 76 | name = xmlTextReaderConstName(_reader); 77 | } 78 | 79 | // save the request type in the tweet 80 | [dictionary setObject:[NSNumber numberWithInt:requestType] forKey:TWITTER_SOURCE_REQUEST_TYPE]; 81 | 82 | return dictionary; 83 | } 84 | 85 | 86 | - (void)parse 87 | { 88 | int readerResult = xmlTextReaderRead(_reader); 89 | if (readerResult != 1) 90 | return; 91 | int nodeType = xmlTextReaderNodeType(_reader); 92 | const xmlChar *name = xmlTextReaderConstName(_reader); 93 | while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(BAD_CAST "direct-messages", name))) 94 | { 95 | if (nodeType == XML_READER_TYPE_ELEMENT) 96 | { 97 | if (xmlStrEqual(name, BAD_CAST "direct_message")) 98 | { 99 | [parsedObjects addObject:[self _directMessageDictionaryForNodeWithName:BAD_CAST "direct_message"]]; 100 | } 101 | } 102 | 103 | // advance reader 104 | readerResult = xmlTextReaderRead(_reader); 105 | if (readerResult != 1) 106 | { 107 | break; 108 | } 109 | nodeType = xmlTextReaderNodeType(_reader); 110 | name = xmlTextReaderConstName(_reader); 111 | } 112 | } 113 | 114 | @end 115 | -------------------------------------------------------------------------------- /TouchJSON/Source/Extensions/NSScanner_Extensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSScanner_Extensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 12/08/2005. 6 | // Copyright 2005 toxicsoftware.com. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "NSScanner_Extensions.h" 31 | 32 | #import "NSCharacterSet_Extensions.h" 33 | 34 | @implementation NSScanner (NSScanner_Extensions) 35 | 36 | - (NSString *)remainingString 37 | { 38 | return([[self string] substringFromIndex:[self scanLocation]]); 39 | } 40 | 41 | - (unichar)currentCharacter 42 | { 43 | return([[self string] characterAtIndex:[self scanLocation]]); 44 | } 45 | 46 | - (unichar)scanCharacter 47 | { 48 | NSUInteger theScanLocation = [self scanLocation]; 49 | unichar theCharacter = [[self string] characterAtIndex:theScanLocation]; 50 | [self setScanLocation:theScanLocation + 1]; 51 | return(theCharacter); 52 | } 53 | 54 | - (BOOL)scanCharacter:(unichar)inCharacter 55 | { 56 | NSUInteger theScanLocation = [self scanLocation]; 57 | if ([[self string] characterAtIndex:theScanLocation] == inCharacter) 58 | { 59 | [self setScanLocation:theScanLocation + 1]; 60 | return(YES); 61 | } 62 | else 63 | return(NO); 64 | } 65 | 66 | - (void)backtrack:(unsigned)inCount 67 | { 68 | NSUInteger theScanLocation = [self scanLocation]; 69 | if (inCount > theScanLocation) 70 | [NSException raise:NSGenericException format:@"Backtracked too far."]; 71 | [self setScanLocation:theScanLocation - inCount]; 72 | } 73 | 74 | - (BOOL)scanCStyleComment:(NSString **)outComment 75 | { 76 | if ([self scanString:@"/*" intoString:NULL] == YES) 77 | { 78 | NSString *theComment = NULL; 79 | if ([self scanUpToString:@"*/" intoString:&theComment] == NO) 80 | [NSException raise:NSGenericException format:@"Started to scan a C style comment but it wasn't terminated."]; 81 | 82 | if ([theComment rangeOfString:@"/*"].location != NSNotFound) 83 | [NSException raise:NSGenericException format:@"C style comments should not be nested."]; 84 | 85 | if ([self scanString:@"*/" intoString:NULL] == NO) 86 | [NSException raise:NSGenericException format:@"C style comment did not end correctly."]; 87 | 88 | if (outComment != NULL) 89 | *outComment = theComment; 90 | 91 | return(YES); 92 | } 93 | else 94 | { 95 | return(NO); 96 | } 97 | } 98 | 99 | - (BOOL)scanCPlusPlusStyleComment:(NSString **)outComment 100 | { 101 | if ([self scanString:@"//" intoString:NULL] == YES) 102 | { 103 | NSString *theComment = NULL; 104 | [self scanUpToCharactersFromSet:[NSCharacterSet linebreaksCharacterSet] intoString:&theComment]; 105 | [self scanCharactersFromSet:[NSCharacterSet linebreaksCharacterSet] intoString:NULL]; 106 | 107 | if (outComment != NULL) 108 | *outComment = theComment; 109 | 110 | return(YES); 111 | } 112 | else 113 | { 114 | return(NO); 115 | } 116 | } 117 | 118 | @end 119 | -------------------------------------------------------------------------------- /TouchJSON/Source/JSON/CJSONDeserializer.m: -------------------------------------------------------------------------------- 1 | // 2 | // CJSONDeserializer.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 12/15/2005. 6 | // Copyright 2005 toxicsoftware.com. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "CJSONDeserializer.h" 31 | 32 | #import "CJSONScanner.h" 33 | #import "CDataScanner.h" 34 | 35 | NSString *const kJSONDeserializerErrorDomain = @"CJSONDeserializerErrorDomain"; 36 | 37 | @interface CJSONDeserializer () 38 | @end 39 | 40 | @implementation CJSONDeserializer 41 | 42 | @synthesize scanner; 43 | 44 | + (id)deserializer 45 | { 46 | return([[[self alloc] init] autorelease]); 47 | } 48 | 49 | - (id)init 50 | { 51 | if ((self = [super init]) != NULL) 52 | { 53 | } 54 | return(self); 55 | } 56 | 57 | - (void)dealloc 58 | { 59 | [scanner release]; 60 | scanner = NULL; 61 | // 62 | [super dealloc]; 63 | } 64 | 65 | #pragma mark - 66 | 67 | - (CJSONScanner *)scanner 68 | { 69 | if (scanner == NULL) 70 | { 71 | scanner = [[CJSONScanner alloc] init]; 72 | } 73 | return(scanner); 74 | } 75 | 76 | - (id)nullObject 77 | { 78 | return(self.scanner.nullObject); 79 | } 80 | 81 | - (void)setNullObject:(id)inNullObject 82 | { 83 | self.scanner.nullObject = inNullObject; 84 | } 85 | 86 | #pragma mark - 87 | 88 | - (NSStringEncoding)allowedEncoding 89 | { 90 | return(self.scanner.allowedEncoding); 91 | } 92 | 93 | - (void)setAllowedEncoding:(NSStringEncoding)inAllowedEncoding 94 | { 95 | self.scanner.allowedEncoding = inAllowedEncoding; 96 | } 97 | 98 | #pragma mark - 99 | 100 | - (id)deserialize:(NSData *)inData error:(NSError **)outError 101 | { 102 | if (inData == NULL || [inData length] == 0) 103 | { 104 | if (outError) 105 | *outError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL]; 106 | 107 | return(NULL); 108 | } 109 | if ([self.scanner setData:inData error:outError] == NO) 110 | { 111 | return(NULL); 112 | } 113 | id theObject = NULL; 114 | if ([self.scanner scanJSONObject:&theObject error:outError] == YES) 115 | return(theObject); 116 | else 117 | return(NULL); 118 | } 119 | 120 | - (id)deserializeAsDictionary:(NSData *)inData error:(NSError **)outError 121 | { 122 | if (inData == NULL || [inData length] == 0) 123 | { 124 | if (outError) 125 | *outError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL]; 126 | 127 | return(NULL); 128 | } 129 | if ([self.scanner setData:inData error:outError] == NO) 130 | { 131 | return(NULL); 132 | } 133 | NSDictionary *theDictionary = NULL; 134 | if ([self.scanner scanJSONDictionary:&theDictionary error:outError] == YES) 135 | return(theDictionary); 136 | else 137 | return(NULL); 138 | } 139 | 140 | - (id)deserializeAsArray:(NSData *)inData error:(NSError **)outError 141 | { 142 | if (inData == NULL || [inData length] == 0) 143 | { 144 | if (outError) 145 | *outError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL]; 146 | 147 | return(NULL); 148 | } 149 | if ([self.scanner setData:inData error:outError] == NO) 150 | { 151 | return(NULL); 152 | } 153 | NSArray *theArray = NULL; 154 | if ([self.scanner scanJSONArray:&theArray error:outError] == YES) 155 | return(theArray); 156 | else 157 | return(NULL); 158 | } 159 | 160 | @end 161 | -------------------------------------------------------------------------------- /Classes/TwitterEngine.h: -------------------------------------------------------------------------------- 1 | // 2 | // TwitterEngine.h 3 | // TwitterCommonLibrary 4 | // 5 | // Created by Tim Shi on 11-01-07. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MGTwitterEngine.h" 11 | #import "OAuthConsumer.h" 12 | 13 | #define kRequestURL @"http://twitter.com/oauth/request_token" 14 | #define kAccessURL @"http://twitter.com/oauth/access_token" 15 | #define kAuthorizeURL @"http://twitter.com/oauth/authorize" 16 | 17 | #define kOAuthConsumerKey @"" //TODO: Add your consumer key here 18 | #define kOAuthConsumerSecret @"" //TODO: add your consumer secret here. 19 | 20 | /* 21 | The TwitterEngine is a singleton class, it has the following use: 22 | 23 | 1. Handles OAuth Authentication (Signing in/out) 24 | 2. Sends request and recieve response from Twitter. This is done by leveraging MGTE (MGTwitterEngine) 25 | 3. Manages streaming connections from Twitter. Collect streaming data and send it to the processing queue asynchronously. 26 | Possibily there could be a few. We have direct reference to the streaming connection because we don't need to have multiple streaming connection that do the samething. 27 | (compare to the connections in 2). 28 | */ 29 | 30 | @interface TwitterEngine : MGTwitterEngine { 31 | //This connection is managed by the corresponding startStreamingWithDelegate method 32 | NSURLConnection* streamingConnection; 33 | 34 | //endpoints of oAuth. The consumerKey, consumerSecrete and accessToken is inherited from the MGTwitterEngine super class. 35 | NSURL* _requestTokenURL; 36 | NSURL* _accessTokenURL; 37 | NSURL* _authorizeURL; 38 | 39 | //request token because there's no request token in MGTE because they use xAuth 40 | OAToken* _requestToken; 41 | 42 | /* 43 | Refer to the out of band work flow in twitter oAuth. This is neccessary in browserless applications. The pin is the equivalent of an oAuth verifier. The pin is sent 44 | back with the the request token when the user authorizes the request. 45 | */ 46 | NSString *_pin; 47 | } 48 | 49 | + (TwitterEngine*)sharedEngine; 50 | 51 | + (TwitterEngine*)sharedEngineWithDelegate: (NSObject *) delegate; 52 | 53 | //starts the streaming connection to a certain request url, that tracks certain keywords. 54 | - (void) startStreamingWithDelegate:(NSObject*)delegate withURL:(NSURL*)url forTracking:(NSString*)keywords; 55 | 56 | 57 | #pragma mark oAuth 58 | /* 59 | The oAuth work flow is (this flow will be implemented by the login controller, we provide the method that 60 | power this flow): 61 | if user is authorized (isAuthorized) 62 | request the request token (requestRequestToken) 63 | 64 | on receiving the request token 65 | get the authorize url request address (need both the request token and authorization url. 66 | the request token is used to identify the application. (authorizeURLRequest) 67 | 68 | load the authorize url to the user (the controller do this through a webview) 69 | 70 | get the oAuth verification pin (the controller finds the pin in the web view and sets it in the engine). 71 | 72 | exchange the request token for access token (requestAccessToken) 73 | 74 | cache the info 75 | else 76 | get the access token from cahced info. 77 | */ 78 | 79 | 80 | //Checks for the existence of an access token, if access token exists, return true. 81 | - (BOOL) isAuthorized; 82 | 83 | //Generate the URL request using the request token, and the authorize url. A webview can load this 84 | //URL request and present it to the user for login. 85 | - (NSURLRequest *) authorizeURLRequest; 86 | 87 | - (void)requestRequestToken:(id)aDelegate onSuccess:(SEL)success onFail:(SEL)fail; 88 | 89 | - (void)requestAccessToken:(id)aDelegate onSuccess:(SEL)success onFail:(SEL)fail; 90 | 91 | //Clear the access token from the engine, this is equivalent to login out. 92 | - (void) clearAccessToken; 93 | 94 | //call back method on request token success 95 | - (void) setRequestToken: (OAServiceTicket *) ticket withData: (NSData *) data; 96 | - (void) setAccessTokenWith: (OAServiceTicket *) ticket withData: (NSData *) data; 97 | #pragma mark oAuth end 98 | 99 | //TODO: we may not need to have these properties, or just make them private. It's easier to manage the retain, release cycle this way. 100 | @property (retain, nonatomic) NSURLConnection* streamingConnection; 101 | @property (retain, nonatomic) NSURL* _requestTokenURL; 102 | @property (retain, nonatomic) NSURL* _accessTokenURL; 103 | @property (retain, nonatomic) NSURL* _authorizeTokenURL; 104 | @property (retain, nonatomic) NSString* _pin; 105 | @property (retain, nonatomic) OAToken* _requestToken; 106 | 107 | @end 108 | -------------------------------------------------------------------------------- /NSData+Base64.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+Base64.m 3 | // 4 | // Derived from http://colloquy.info/project/browser/trunk/NSDataAdditions.h?rev=1576 5 | // Created by khammond on Mon Oct 29 2001. 6 | // Formatted by Timothy Hatcher on Sun Jul 4 2004. 7 | // Copyright (c) 2001 Kyle Hammond. All rights reserved. 8 | // Original development by Dave Winer. 9 | // 10 | 11 | #import "NSData+Base64.h" 12 | 13 | #import 14 | 15 | static char encodingTable[64] = { 16 | 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', 17 | 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', 18 | 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', 19 | 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' }; 20 | 21 | @implementation NSData (Base64) 22 | 23 | + (NSData *) dataWithBase64EncodedString:(NSString *) string { 24 | NSData *result = [[NSData alloc] initWithBase64EncodedString:string]; 25 | return [result autorelease]; 26 | } 27 | 28 | - (id) initWithBase64EncodedString:(NSString *) string { 29 | NSMutableData *mutableData = nil; 30 | 31 | if( string ) { 32 | unsigned long ixtext = 0; 33 | unsigned long lentext = 0; 34 | unsigned char ch = 0; 35 | unsigned char inbuf[3], outbuf[4]; 36 | short i = 0, ixinbuf = 0; 37 | BOOL flignore = NO; 38 | BOOL flendtext = NO; 39 | NSData *base64Data = nil; 40 | const unsigned char *base64Bytes = nil; 41 | 42 | // Convert the string to ASCII data. 43 | base64Data = [string dataUsingEncoding:NSASCIIStringEncoding]; 44 | base64Bytes = [base64Data bytes]; 45 | mutableData = [NSMutableData dataWithCapacity:[base64Data length]]; 46 | lentext = [base64Data length]; 47 | 48 | while( YES ) { 49 | if( ixtext >= lentext ) break; 50 | ch = base64Bytes[ixtext++]; 51 | flignore = NO; 52 | 53 | if( ( ch >= 'A' ) && ( ch <= 'Z' ) ) ch = ch - 'A'; 54 | else if( ( ch >= 'a' ) && ( ch <= 'z' ) ) ch = ch - 'a' + 26; 55 | else if( ( ch >= '0' ) && ( ch <= '9' ) ) ch = ch - '0' + 52; 56 | else if( ch == '+' ) ch = 62; 57 | else if( ch == '=' ) flendtext = YES; 58 | else if( ch == '/' ) ch = 63; 59 | else flignore = YES; 60 | 61 | if( ! flignore ) { 62 | short ctcharsinbuf = 3; 63 | BOOL flbreak = NO; 64 | 65 | if( flendtext ) { 66 | if( ! ixinbuf ) break; 67 | if( ( ixinbuf == 1 ) || ( ixinbuf == 2 ) ) ctcharsinbuf = 1; 68 | else ctcharsinbuf = 2; 69 | ixinbuf = 3; 70 | flbreak = YES; 71 | } 72 | 73 | inbuf [ixinbuf++] = ch; 74 | 75 | if( ixinbuf == 4 ) { 76 | ixinbuf = 0; 77 | outbuf [0] = ( inbuf[0] << 2 ) | ( ( inbuf[1] & 0x30) >> 4 ); 78 | outbuf [1] = ( ( inbuf[1] & 0x0F ) << 4 ) | ( ( inbuf[2] & 0x3C ) >> 2 ); 79 | outbuf [2] = ( ( inbuf[2] & 0x03 ) << 6 ) | ( inbuf[3] & 0x3F ); 80 | 81 | for( i = 0; i < ctcharsinbuf; i++ ) 82 | [mutableData appendBytes:&outbuf[i] length:1]; 83 | } 84 | 85 | if( flbreak ) break; 86 | } 87 | } 88 | } 89 | 90 | self = [self initWithData:mutableData]; 91 | return self; 92 | } 93 | 94 | - (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength { 95 | const unsigned char *bytes = [self bytes]; 96 | NSMutableString *result = [NSMutableString stringWithCapacity:[self length]]; 97 | unsigned long ixtext = 0; 98 | unsigned long lentext = [self length]; 99 | long ctremaining = 0; 100 | unsigned char inbuf[3], outbuf[4]; 101 | short i = 0; 102 | unsigned int charsonline = 0; 103 | short ctcopy = 0; 104 | unsigned long ix = 0; 105 | 106 | while( YES ) { 107 | ctremaining = lentext - ixtext; 108 | if( ctremaining <= 0 ) break; 109 | 110 | for( i = 0; i < 3; i++ ) { 111 | ix = ixtext + i; 112 | if( ix < lentext ) inbuf[i] = bytes[ix]; 113 | else inbuf [i] = 0; 114 | } 115 | 116 | outbuf [0] = (inbuf [0] & 0xFC) >> 2; 117 | outbuf [1] = ((inbuf [0] & 0x03) << 4) | ((inbuf [1] & 0xF0) >> 4); 118 | outbuf [2] = ((inbuf [1] & 0x0F) << 2) | ((inbuf [2] & 0xC0) >> 6); 119 | outbuf [3] = inbuf [2] & 0x3F; 120 | ctcopy = 4; 121 | 122 | switch( ctremaining ) { 123 | case 1: 124 | ctcopy = 2; 125 | break; 126 | case 2: 127 | ctcopy = 3; 128 | break; 129 | } 130 | 131 | for( i = 0; i < ctcopy; i++ ) 132 | [result appendFormat:@"%c", encodingTable[outbuf[i]]]; 133 | 134 | for( i = ctcopy; i < 4; i++ ) 135 | [result appendFormat:@"%c",'=']; 136 | 137 | ixtext += 3; 138 | charsonline += 4; 139 | 140 | if( lineLength > 0 ) { 141 | if (charsonline >= lineLength) { 142 | charsonline = 0; 143 | [result appendString:@"\n"]; 144 | } 145 | } 146 | } 147 | 148 | return result; 149 | } 150 | 151 | @end 152 | -------------------------------------------------------------------------------- /oauthconsumer/OAProblem.m: -------------------------------------------------------------------------------- 1 | // 2 | // OAProblem.m 3 | // OAuthConsumer 4 | // 5 | // Created by Alberto García Hierro on 03/09/08. 6 | // Copyright 2008 Alberto García Hierro. All rights reserved. 7 | // bynotes.com 8 | 9 | #import "OAProblem.h" 10 | 11 | const NSString *signature_method_rejected = @"signature_method_rejected"; 12 | const NSString *parameter_absent = @"parameter_absent"; 13 | const NSString *version_rejected = @"version_rejected"; 14 | const NSString *consumer_key_unknown = @"consumer_key_unknown"; 15 | const NSString *token_rejected = @"token_rejected"; 16 | const NSString *signature_invalid = @"signature_invalid"; 17 | const NSString *nonce_used = @"nonce_used"; 18 | const NSString *timestamp_refused = @"timestamp_refused"; 19 | const NSString *token_expired = @"token_expired"; 20 | const NSString *token_not_renewable = @"token_not_renewable"; 21 | 22 | @implementation OAProblem 23 | 24 | @synthesize problem; 25 | 26 | - (id)initWithPointer:(const NSString *) aPointer 27 | { 28 | [super init]; 29 | problem = aPointer; 30 | return self; 31 | } 32 | 33 | - (id)initWithProblem:(const NSString *) aProblem 34 | { 35 | NSUInteger idx = [[OAProblem validProblems] indexOfObject:aProblem]; 36 | if (idx == NSNotFound) { 37 | return nil; 38 | } 39 | 40 | return [self initWithPointer: [[OAProblem validProblems] objectAtIndex:idx]]; 41 | } 42 | 43 | - (id)initWithResponseBody:(const NSString *) response 44 | { 45 | NSArray *fields = [response componentsSeparatedByString:@"&"]; 46 | for (NSString *field in fields) { 47 | if ([field hasPrefix:@"oauth_problem="]) { 48 | NSString *value = [[field componentsSeparatedByString:@"="] objectAtIndex:1]; 49 | return [self initWithProblem:value]; 50 | } 51 | } 52 | 53 | return nil; 54 | } 55 | 56 | + (OAProblem *)problemWithResponseBody:(const NSString *) response 57 | { 58 | return [[[OAProblem alloc] initWithResponseBody:response] autorelease]; 59 | } 60 | 61 | + (const NSArray *)validProblems 62 | { 63 | static NSArray *array; 64 | if (!array) { 65 | array = [[NSArray alloc] initWithObjects:signature_method_rejected, 66 | parameter_absent, 67 | version_rejected, 68 | consumer_key_unknown, 69 | token_rejected, 70 | signature_invalid, 71 | nonce_used, 72 | timestamp_refused, 73 | token_expired, 74 | token_not_renewable, 75 | nil]; 76 | } 77 | 78 | return array; 79 | } 80 | 81 | - (BOOL)isEqualToProblem:(OAProblem *) aProblem 82 | { 83 | return [problem isEqualToString:(NSString *)aProblem->problem]; 84 | } 85 | 86 | - (BOOL)isEqualToString:(const NSString *) aProblem 87 | { 88 | return [problem isEqualToString:(NSString *)aProblem]; 89 | } 90 | 91 | - (BOOL)isEqualTo:(id) aProblem 92 | { 93 | if ([aProblem isKindOfClass:[NSString class]]) { 94 | return [self isEqualToString:aProblem]; 95 | } 96 | 97 | if ([aProblem isKindOfClass:[OAProblem class]]) { 98 | return [self isEqualToProblem:aProblem]; 99 | } 100 | 101 | return NO; 102 | } 103 | 104 | - (int)code { 105 | return [[[self class] validProblems] indexOfObject:problem]; 106 | } 107 | 108 | - (NSString *)description 109 | { 110 | return [NSString stringWithFormat:@"OAuth Problem: %@", (NSString *)problem]; 111 | } 112 | 113 | #pragma mark class_methods 114 | 115 | + (OAProblem *)SignatureMethodRejected 116 | { 117 | return [[[OAProblem alloc] initWithPointer:signature_method_rejected] autorelease]; 118 | } 119 | 120 | + (OAProblem *)ParameterAbsent 121 | { 122 | return [[[OAProblem alloc] initWithPointer:parameter_absent] autorelease]; 123 | } 124 | 125 | + (OAProblem *)VersionRejected 126 | { 127 | return [[[OAProblem alloc] initWithPointer:version_rejected] autorelease]; 128 | } 129 | 130 | + (OAProblem *)ConsumerKeyUnknown 131 | { 132 | return [[[OAProblem alloc] initWithPointer:consumer_key_unknown] autorelease]; 133 | } 134 | 135 | + (OAProblem *)TokenRejected 136 | { 137 | return [[[OAProblem alloc] initWithPointer:token_rejected] autorelease]; 138 | } 139 | 140 | + (OAProblem *)SignatureInvalid 141 | { 142 | return [[[OAProblem alloc] initWithPointer:signature_invalid] autorelease]; 143 | } 144 | 145 | + (OAProblem *)NonceUsed 146 | { 147 | return [[[OAProblem alloc] initWithPointer:nonce_used] autorelease]; 148 | } 149 | 150 | + (OAProblem *)TimestampRefused 151 | { 152 | return [[[OAProblem alloc] initWithPointer:timestamp_refused] autorelease]; 153 | } 154 | 155 | + (OAProblem *)TokenExpired 156 | { 157 | return [[[OAProblem alloc] initWithPointer:token_expired] autorelease]; 158 | } 159 | 160 | + (OAProblem *)TokenNotRenewable 161 | { 162 | return [[[OAProblem alloc] initWithPointer:token_not_renewable] autorelease]; 163 | } 164 | 165 | @end 166 | -------------------------------------------------------------------------------- /TouchJSON/Source/Extensions/CDataScanner_Extensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CDataScanner_Extensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 12/08/2005. 6 | // Copyright 2005 toxicsoftware.com. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "CDataScanner_Extensions.h" 31 | 32 | #import "NSCharacterSet_Extensions.h" 33 | 34 | @implementation CDataScanner (CDataScanner_Extensions) 35 | 36 | - (BOOL)scanCStyleComment:(NSString **)outComment 37 | { 38 | if ([self scanString:@"/*" intoString:NULL] == YES) 39 | { 40 | NSString *theComment = NULL; 41 | if ([self scanUpToString:@"*/" intoString:&theComment] == NO) 42 | [NSException raise:NSGenericException format:@"Started to scan a C style comment but it wasn't terminated."]; 43 | 44 | if ([theComment rangeOfString:@"/*"].location != NSNotFound) 45 | [NSException raise:NSGenericException format:@"C style comments should not be nested."]; 46 | 47 | if ([self scanString:@"*/" intoString:NULL] == NO) 48 | [NSException raise:NSGenericException format:@"C style comment did not end correctly."]; 49 | 50 | if (outComment != NULL) 51 | *outComment = theComment; 52 | 53 | return(YES); 54 | } 55 | else 56 | { 57 | return(NO); 58 | } 59 | } 60 | 61 | - (BOOL)scanCPlusPlusStyleComment:(NSString **)outComment 62 | { 63 | if ([self scanString:@"//" intoString:NULL] == YES) 64 | { 65 | NSString *theComment = NULL; 66 | [self scanUpToCharactersFromSet:[NSCharacterSet linebreaksCharacterSet] intoString:&theComment]; 67 | [self scanCharactersFromSet:[NSCharacterSet linebreaksCharacterSet] intoString:NULL]; 68 | 69 | if (outComment != NULL) 70 | *outComment = theComment; 71 | 72 | return(YES); 73 | } 74 | else 75 | { 76 | return(NO); 77 | } 78 | } 79 | 80 | - (NSUInteger)lineOfScanLocation 81 | { 82 | NSUInteger theLine = 0; 83 | for (const u_int8_t *C = start; C < current; ++C) 84 | { 85 | // TODO: JIW What about MS-DOS line endings you bastard! (Also other unicode line endings) 86 | if (*C == '\n' || *C == '\r') 87 | { 88 | ++theLine; 89 | } 90 | } 91 | return(theLine); 92 | } 93 | 94 | - (NSDictionary *)userInfoForScanLocation 95 | { 96 | NSUInteger theLine = 0; 97 | const u_int8_t *theLineStart = start; 98 | for (const u_int8_t *C = start; C < current; ++C) 99 | { 100 | if (*C == '\n' || *C == '\r') 101 | { 102 | theLineStart = C - 1; 103 | ++theLine; 104 | } 105 | } 106 | 107 | NSUInteger theCharacter = current - theLineStart; 108 | 109 | NSRange theStartRange = NSIntersectionRange((NSRange){ .location = MAX((NSInteger)self.scanLocation - 20, 0), .length = 20 + (NSInteger)self.scanLocation - 20 }, (NSRange){ .location = 0, .length = self.data.length }); 110 | NSRange theEndRange = NSIntersectionRange((NSRange){ .location = self.scanLocation, .length = 20 }, (NSRange){ .location = 0, .length = self.data.length }); 111 | 112 | 113 | NSString *theSnippet = [NSString stringWithFormat:@"%@!HERE>!%@", 114 | [[[NSString alloc] initWithData:[self.data subdataWithRange:theStartRange] encoding:NSUTF8StringEncoding] autorelease], 115 | [[[NSString alloc] initWithData:[self.data subdataWithRange:theEndRange] encoding:NSUTF8StringEncoding] autorelease] 116 | ]; 117 | 118 | NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys: 119 | [NSNumber numberWithUnsignedInteger:theLine], @"line", 120 | [NSNumber numberWithUnsignedInteger:theCharacter], @"character", 121 | [NSNumber numberWithUnsignedInteger:self.scanLocation], @"location", 122 | theSnippet, @"snippet", 123 | NULL]; 124 | return(theUserInfo); 125 | } 126 | 127 | @end 128 | -------------------------------------------------------------------------------- /MGTwitterTouchJSONParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterTouchJSONParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Steve Streza on 3/24/10. 6 | // Copyright 2010 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "MGTwitterTouchJSONParser.h" 10 | #import "CJSONDeserializer.h" 11 | 12 | @implementation MGTwitterTouchJSONParser 13 | 14 | + (id)parserWithJSON:(NSData *)theJSON 15 | delegate:(NSObject *)theDelegate 16 | connectionIdentifier:(NSString *)identifier 17 | requestType:(MGTwitterRequestType)reqType 18 | responseType:(MGTwitterResponseType)respType 19 | URL:(NSURL *)URL 20 | deliveryOptions:(MGTwitterEngineDeliveryOptions)deliveryOptions 21 | { 22 | return [[[self alloc] initWithJSON:theJSON 23 | delegate:theDelegate 24 | connectionIdentifier:identifier 25 | requestType:reqType 26 | responseType:respType 27 | URL:URL 28 | deliveryOptions:deliveryOptions] autorelease]; 29 | } 30 | 31 | - (id) initWithJSON:(NSData *)theJSON 32 | delegate:(NSObject *)theDelegate 33 | connectionIdentifier:(NSString *)theIdentifier 34 | requestType:(MGTwitterRequestType)reqType 35 | responseType:(MGTwitterResponseType)respType 36 | URL:(NSURL *)theURL 37 | deliveryOptions:(MGTwitterEngineDeliveryOptions)theDeliveryOptions 38 | { 39 | if(self = [super init]){ 40 | json = [theJSON retain]; 41 | identifier = [theIdentifier retain]; 42 | requestType = reqType; 43 | responseType = respType; 44 | URL = [theURL retain]; 45 | deliveryOptions = theDeliveryOptions; 46 | delegate = theDelegate; 47 | 48 | if (deliveryOptions & MGTwitterEngineDeliveryAllResultsOption) 49 | { 50 | parsedObjects = [[NSMutableArray alloc] initWithCapacity:0]; 51 | } 52 | else 53 | { 54 | parsedObjects = nil; // rely on nil target to discard addObject 55 | } 56 | 57 | if ([json length] <= 5) 58 | { 59 | // NOTE: this is a hack for API methods that return short JSON responses that can't be parsed by YAJL. These include: 60 | // friendships/exists: returns "true" or "false" 61 | // help/test: returns "ok" 62 | // An empty response of "[]" is a special case. 63 | NSString *result = [[[NSString alloc] initWithBytes:[json bytes] length:[json length] encoding:NSUTF8StringEncoding] autorelease]; 64 | if (! [result isEqualToString:@"[]"]) 65 | { 66 | NSMutableDictionary *dictionary = [[[NSMutableDictionary alloc] initWithCapacity:1] autorelease]; 67 | 68 | if ([result isEqualToString:@"\"ok\""]) 69 | { 70 | [dictionary setObject:[NSNumber numberWithBool:YES] forKey:@"ok"]; 71 | } 72 | else 73 | { 74 | [dictionary setObject:[NSNumber numberWithBool:[result isEqualToString:@"true"]] forKey:@"friends"]; 75 | } 76 | [dictionary setObject:[NSNumber numberWithInt:requestType] forKey:TWITTER_SOURCE_REQUEST_TYPE]; 77 | 78 | [self _parsedObject:dictionary]; 79 | 80 | [parsedObjects addObject:dictionary]; 81 | } 82 | } 83 | else 84 | { 85 | id results = [[CJSONDeserializer deserializer] deserialize:json 86 | error:nil]; 87 | if([results isKindOfClass:[NSArray class]]){ 88 | for(NSDictionary *result in results){ 89 | [self _parsedObject:result]; 90 | } 91 | }else{ 92 | [self _parsedObject:results]; 93 | } 94 | 95 | } 96 | 97 | // notify the delegate that parsing completed 98 | [self _parsingDidEnd]; 99 | } 100 | return self; 101 | } 102 | 103 | - (void)dealloc 104 | { 105 | [parsedObjects release]; 106 | [json release]; 107 | [identifier release]; 108 | [URL release]; 109 | 110 | delegate = nil; 111 | [super dealloc]; 112 | } 113 | 114 | #pragma mark Delegate callbacks 115 | 116 | - (BOOL) _isValidDelegateForSelector:(SEL)selector 117 | { 118 | return ((delegate != nil) && [delegate respondsToSelector:selector]); 119 | } 120 | 121 | - (void)_parsingDidEnd 122 | { 123 | if ([self _isValidDelegateForSelector:@selector(parsingSucceededForRequest:ofResponseType:withParsedObjects:)]) 124 | [delegate parsingSucceededForRequest:identifier ofResponseType:responseType withParsedObjects:parsedObjects]; 125 | } 126 | 127 | - (void)_parsingErrorOccurred:(NSError *)parseError 128 | { 129 | if ([self _isValidDelegateForSelector:@selector(parsingFailedForRequest:ofResponseType:withError:)]) 130 | [delegate parsingFailedForRequest:identifier ofResponseType:responseType withError:parseError]; 131 | } 132 | 133 | - (void)_parsedObject:(NSDictionary *)dictionary 134 | { 135 | [parsedObjects addObject:dictionary]; 136 | if (deliveryOptions & MGTwitterEngineDeliveryIndividualResultsOption) 137 | if ([self _isValidDelegateForSelector:@selector(parsedObject:forRequest:ofResponseType:)]) 138 | [delegate parsedObject:(NSDictionary *)dictionary forRequest:identifier ofResponseType:responseType]; 139 | } 140 | 141 | @end 142 | -------------------------------------------------------------------------------- /MGTwitterRequestTypes.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterEngineDelegate.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 17/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | typedef enum _MGTwitterRequestType { 12 | MGTwitterPublicTimelineRequest = 0, // latest statuses from the public timeline 13 | MGTwitterHomeTimelineRequest, // latest statuses from the home timeline 14 | MGTwitterFollowedTimelineRequest, // latest statuses from the people that the current users follows 15 | MGTwitterUserTimelineRequest, // statuses archive for the current user 16 | MGTwitterUserTimelineForUserRequest, // statuses archive for the specified user 17 | MGTwitterUpdateGetRequest, // get a status update for the specified id 18 | MGTwitterUpdateSendRequest, // send a new update for the current user 19 | MGTwitterUpdateDeleteRequest, // delete an update for the current user using the specified id 20 | MGTwitterRepliesRequest, // latest reply status for the current user 21 | MGTwitterRetweetSendRequest, // send a new retweet for the current user 22 | MGTwitterFeaturedUsersRequest, // latest status from featured users 23 | MGTwitterFriendUpdatesRequest, // last status for the people that the current user follows 24 | MGTwitterFriendUpdatesForUserRequest, // last status for the people that the specified user follows 25 | MGTwitterFollowerUpdatesRequest, // last status for the people that follow the current user 26 | MGTwitterUserInformationRequest, // user information using the specified id or email 27 | MGTwitterBulkUserInformationRequest, // user information using the specified id or email 28 | MGTwitterDirectMessagesRequest, // latest direct messages to the current user 29 | MGTwitterDirectMessagesSentRequest, // latest direct messages from the current user 30 | MGTwitterDirectMessageSendRequest, // send a new direct message from the current user 31 | MGTwitterDirectMessageDeleteRequest, // delete a direct message to/from the current user 32 | MGTwitterUpdatesEnableRequest, // enable status updates for specified user (e.g. follow) 33 | MGTwitterUpdatesDisableRequest, // disable status updates for specified user (e.g. unfollow) 34 | MGTwitterUpdatesCheckRequest, // check if the specified user is following another user 35 | MGTwitterAccountRequest, // changing account information for the current user 36 | MGTwitterAccountLocationRequest, // change location in account information for the current user 37 | MGTwitterAccountDeliveryRequest, // change notification delivery in account information for the current user 38 | MGTwitterAccountStatusRequest, // get rate limiting status for the current user 39 | MGTwitterFavoritesRequest, // latest favorites for the current user 40 | MGTwitterFavoritesForUserRequest, // latest favorites for the specified user 41 | MGTwitterFavoritesEnableRequest, // create a favorite for the current user using the specified id 42 | MGTwitterFavoritesDisableRequest, // remove a favorite for the current user using the specified id 43 | MGTwitterNotificationsEnableRequest, // enable notifications for the specified user 44 | MGTwitterNotificationsDisableRequest, // disable notifications for the specified user 45 | MGTwitterBlockEnableRequest, // enable block for the specified user 46 | MGTwitterBlockDisableRequest, // disable block for the specified user 47 | MGTwitterImageRequest, // requesting an image 48 | MGTwitterFriendIDsRequest, // request the numeric IDs for every user the specified user is following 49 | MGTwitterFollowerIDsRequest, // request the numeric IDs of the followers of the specified user 50 | MGTwitterUserListsRequest, 51 | MGTwitterUserListCreate, 52 | #if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE 53 | MGTwitterSearchRequest, // performing a search 54 | MGTwitterSearchCurrentTrendsRequest, // getting the current trends 55 | #endif 56 | MGTwitterOAuthTokenRequest, 57 | } MGTwitterRequestType; 58 | 59 | typedef enum _MGTwitterResponseType { 60 | MGTwitterStatuses = 0, // one or more statuses 61 | MGTwitterStatus = 1, // exactly one status 62 | MGTwitterUsers = 2, // one or more user's information 63 | MGTwitterUser = 3, // info for exactly one user 64 | MGTwitterDirectMessages = 4, // one or more direct messages 65 | MGTwitterDirectMessage = 5, // exactly one direct message 66 | MGTwitterGeneric = 6, // a generic response not requiring parsing 67 | MGTwitterMiscellaneous = 8, // a miscellaneous response of key-value pairs 68 | MGTwitterImage = 7, // an image 69 | #if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE 70 | MGTwitterSearchResults = 9, // search results 71 | #endif 72 | MGTwitterSocialGraph = 10, 73 | MGTwitterOAuthToken = 11, 74 | MGTwitterUserLists = 12, 75 | } MGTwitterResponseType; 76 | 77 | // This key is added to each tweet or direct message returned, 78 | // with an NSNumber value containing an MGTwitterRequestType. 79 | // This is designed to help client applications aggregate updates. 80 | #define TWITTER_SOURCE_REQUEST_TYPE @"source_api_request_type" 81 | -------------------------------------------------------------------------------- /oauthconsumer/OACall.m: -------------------------------------------------------------------------------- 1 | // 2 | // OACall.m 3 | // OAuthConsumer 4 | // 5 | // Created by Alberto García Hierro on 04/09/08. 6 | // Copyright 2008 Alberto García Hierro. All rights reserved. 7 | // bynotes.com 8 | 9 | #import "OAConsumer.h" 10 | #import "OAToken.h" 11 | #import "OAProblem.h" 12 | #import "OADataFetcher.h" 13 | #import "OAServiceTicket.h" 14 | #import "OAMutableURLRequest.h" 15 | #import "OACall.h" 16 | 17 | #import "NSMutableURLRequest+Parameters.h" 18 | 19 | @interface OACall (Private) 20 | 21 | - (void)callFinished:(OAServiceTicket *)ticket withData:(NSData *)data; 22 | - (void)callFailed:(OAServiceTicket *)ticket withError:(NSError *)error; 23 | 24 | @end 25 | 26 | @implementation OACall 27 | 28 | @synthesize url, method, parameters, files, ticket; 29 | 30 | - (id)init { 31 | return [self initWithURL:nil 32 | method:nil 33 | parameters:nil 34 | files:nil]; 35 | } 36 | 37 | - (id)initWithURL:(NSURL *)aURL { 38 | return [self initWithURL:aURL 39 | method:nil 40 | parameters:nil 41 | files:nil]; 42 | } 43 | 44 | - (id)initWithURL:(NSURL *)aURL method:(NSString *)aMethod { 45 | return [self initWithURL:aURL 46 | method:aMethod 47 | parameters:nil 48 | files:nil]; 49 | } 50 | 51 | - (id)initWithURL:(NSURL *)aURL parameters:(NSArray *)theParameters { 52 | return [self initWithURL:aURL 53 | method:nil 54 | parameters:theParameters]; 55 | } 56 | 57 | - (id)initWithURL:(NSURL *)aURL method:(NSString *)aMethod parameters:(NSArray *)theParameters { 58 | return [self initWithURL:aURL 59 | method:aMethod 60 | parameters:theParameters 61 | files:nil]; 62 | } 63 | 64 | - (id)initWithURL:(NSURL *)aURL parameters:(NSArray *)theParameters files:(NSDictionary*)theFiles { 65 | return [self initWithURL:aURL 66 | method:@"POST" 67 | parameters:theParameters 68 | files:theFiles]; 69 | } 70 | 71 | - (id)initWithURL:(NSURL *)aURL 72 | method:(NSString *)aMethod 73 | parameters:(NSArray *)theParameters 74 | files:(NSDictionary*)theFiles { 75 | url = [aURL retain]; 76 | method = [aMethod retain]; 77 | parameters = [theParameters retain]; 78 | files = [theFiles retain]; 79 | fetcher = nil; 80 | request = nil; 81 | 82 | return self; 83 | } 84 | 85 | - (void)dealloc { 86 | [url release]; 87 | [method release]; 88 | [parameters release]; 89 | [files release]; 90 | [fetcher release]; 91 | [request release]; 92 | [ticket release]; 93 | [super dealloc]; 94 | } 95 | 96 | - (void)callFailed:(OAServiceTicket *)aTicket withError:(NSError *)error { 97 | NSLog(@"error body: %@", aTicket.body); 98 | self.ticket = aTicket; 99 | [aTicket release]; 100 | OAProblem *problem = [OAProblem problemWithResponseBody:ticket.body]; 101 | if (problem) { 102 | [delegate call:self failedWithProblem:problem]; 103 | } else { 104 | [delegate call:self failedWithError:error]; 105 | } 106 | } 107 | 108 | - (void)callFinished:(OAServiceTicket *)aTicket withData:(NSData *)data { 109 | self.ticket = aTicket; 110 | [aTicket release]; 111 | if (ticket.didSucceed) { 112 | // NSLog(@"Call body: %@", ticket.body); 113 | [delegate performSelector:finishedSelector withObject:self withObject:ticket.body]; 114 | } else { 115 | // NSLog(@"Failed call body: %@", ticket.body); 116 | [self callFailed:[ticket retain] withError:nil]; 117 | } 118 | } 119 | 120 | - (void)perform:(OAConsumer *)consumer 121 | token:(OAToken *)token 122 | realm:(NSString *)realm 123 | delegate:(NSObject *)aDelegate 124 | didFinish:(SEL)finished 125 | 126 | { 127 | delegate = aDelegate; 128 | finishedSelector = finished; 129 | 130 | request = [[OAMutableURLRequest alloc] initWithURL:url 131 | consumer:consumer 132 | token:token 133 | realm:realm 134 | signatureProvider:nil]; 135 | if(method) { 136 | [request setHTTPMethod:method]; 137 | } 138 | 139 | if (self.parameters) { 140 | [request setParameters:self.parameters]; 141 | } 142 | 143 | // if (self.files) { 144 | // for (NSString *key in self.files) { 145 | // [request attachFileWithName:@"file" filename:NSLocalizedString(@"Photo.jpg", @"") data:[self.files objectForKey:key]]; 146 | // } 147 | // } 148 | 149 | fetcher = [[OADataFetcher alloc] init]; 150 | [fetcher fetchDataWithRequest:request 151 | delegate:self 152 | didFinishSelector:@selector(callFinished:withData:) 153 | didFailSelector:@selector(callFailed:withError:)]; 154 | } 155 | 156 | /*- (BOOL)isEqual:(id)object { 157 | if ([object isKindOfClass:[self class]]) { 158 | return [self isEqualToCall:(OACall *)object]; 159 | } 160 | return NO; 161 | } 162 | 163 | - (BOOL)isEqualToCall:(OACall *)aCall { 164 | return (delegate == aCall->delegate 165 | && finishedSelector == aCall->finishedSelector 166 | && [url isEqualTo:aCall.url] 167 | && [method isEqualToString:aCall.method] 168 | && [parameters isEqualToArray:aCall.parameters] 169 | && [files isEqualToDictionary:aCall.files]); 170 | }*/ 171 | 172 | @end 173 | -------------------------------------------------------------------------------- /oauthconsumer/Categories/NSMutableURLRequest+Parameters.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSMutableURLRequest+Parameters.m 3 | // 4 | // Created by Jon Crosby on 10/19/07. 5 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | 26 | #import "NSMutableURLRequest+Parameters.h" 27 | 28 | static NSString *Boundary = @"-----------------------------------0xCoCoaouTHeBouNDaRy"; 29 | 30 | @implementation NSMutableURLRequest (OAParameterAdditions) 31 | 32 | - (BOOL)isMultipart { 33 | return [[self valueForHTTPHeaderField:@"Content-Type"] hasPrefix:@"multipart/form-data"]; 34 | } 35 | 36 | - (NSArray *)parameters { 37 | NSString *encodedParameters = nil; 38 | 39 | if (![self isMultipart]) { 40 | if ([[self HTTPMethod] isEqualToString:@"GET"] || [[self HTTPMethod] isEqualToString:@"DELETE"]) { 41 | encodedParameters = [[self URL] query]; 42 | } else { 43 | encodedParameters = [[[NSString alloc] initWithData:[self HTTPBody] encoding:NSASCIIStringEncoding] autorelease]; 44 | } 45 | } 46 | 47 | if (encodedParameters == nil || [encodedParameters isEqualToString:@""]) { 48 | return nil; 49 | } 50 | NSArray *encodedParameterPairs = [encodedParameters componentsSeparatedByString:@"&"]; 51 | NSMutableArray *requestParameters = [NSMutableArray arrayWithCapacity:[encodedParameterPairs count]]; 52 | 53 | for (NSString *encodedPair in encodedParameterPairs) { 54 | NSArray *encodedPairElements = [encodedPair componentsSeparatedByString:@"="]; 55 | OARequestParameter *parameter = [[OARequestParameter alloc] initWithName:[[encodedPairElements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] 56 | value:[[encodedPairElements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 57 | [requestParameters addObject:parameter]; 58 | [parameter release], parameter = nil; 59 | } 60 | 61 | return requestParameters; 62 | } 63 | 64 | - (void)setParameters:(NSArray *)parameters 65 | { 66 | NSMutableArray *pairs = [[[NSMutableArray alloc] initWithCapacity:[parameters count]] autorelease]; 67 | for (OARequestParameter *requestParameter in parameters) { 68 | [pairs addObject:[requestParameter URLEncodedNameValuePair]]; 69 | } 70 | 71 | NSString *encodedParameterPairs = [pairs componentsJoinedByString:@"&"]; 72 | 73 | if ([[self HTTPMethod] isEqualToString:@"GET"] || [[self HTTPMethod] isEqualToString:@"DELETE"]) { 74 | [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", [[self URL] URLStringWithoutQuery], encodedParameterPairs]]]; 75 | } else { 76 | // POST, PUT 77 | [self setHTTPBodyWithString:encodedParameterPairs]; 78 | [self setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 79 | } 80 | } 81 | 82 | - (void)setHTTPBodyWithString:(NSString *)body { 83 | NSData *bodyData = [body dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 84 | [self setValue:[NSString stringWithFormat:@"%d", [bodyData length]] forHTTPHeaderField:@"Content-Length"]; 85 | [self setHTTPBody:bodyData]; 86 | } 87 | 88 | - (void)attachFileWithName:(NSString *)name filename:(NSString*)filename contentType:(NSString *)contentType data:(NSData*)data { 89 | 90 | NSArray *parameters = [self parameters]; 91 | [self setValue:[@"multipart/form-data; boundary=" stringByAppendingString:Boundary] forHTTPHeaderField:@"Content-type"]; 92 | 93 | NSMutableData *bodyData = [NSMutableData new]; 94 | for (OARequestParameter *parameter in parameters) { 95 | NSString *param = [NSString stringWithFormat:@"--%@\r\nContent-Disposition: form-data; name=\"%@\"\r\n\r\n%@\r\n", 96 | Boundary, [parameter URLEncodedName], [parameter value]]; 97 | 98 | [bodyData appendData:[param dataUsingEncoding:NSUTF8StringEncoding]]; 99 | } 100 | 101 | NSString *filePrefix = [NSString stringWithFormat:@"--%@\r\nContent-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\nContent-Type: %@\r\n\r\n", 102 | Boundary, name, filename, contentType]; 103 | [bodyData appendData:[filePrefix dataUsingEncoding:NSUTF8StringEncoding]]; 104 | [bodyData appendData:data]; 105 | 106 | [bodyData appendData:[[[@"--" stringByAppendingString:Boundary] stringByAppendingString:@"--"] dataUsingEncoding:NSUTF8StringEncoding]]; 107 | [self setValue:[NSString stringWithFormat:@"%d", [bodyData length]] forHTTPHeaderField:@"Content-Length"]; 108 | [self setHTTPBody:bodyData]; 109 | [bodyData release]; 110 | } 111 | 112 | @end 113 | -------------------------------------------------------------------------------- /MGTwitterXMLParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterXMLParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 18/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterXMLParser.h" 10 | 11 | 12 | @implementation MGTwitterXMLParser 13 | 14 | 15 | #pragma mark Creation and Destruction 16 | 17 | 18 | + (id)parserWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate 19 | connectionIdentifier:(NSString *)identifier requestType:(MGTwitterRequestType)reqType 20 | responseType:(MGTwitterResponseType)respType 21 | { 22 | id parser = [[self alloc] initWithXML:theXML 23 | delegate:theDelegate 24 | connectionIdentifier:identifier 25 | requestType:reqType 26 | responseType:respType]; 27 | return [parser autorelease]; 28 | } 29 | 30 | 31 | - (id)initWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate 32 | connectionIdentifier:(NSString *)theIdentifier requestType:(MGTwitterRequestType)reqType 33 | responseType:(MGTwitterResponseType)respType 34 | { 35 | if ((self = [super init])) { 36 | xml = [theXML retain]; 37 | identifier = [theIdentifier retain]; 38 | requestType = reqType; 39 | responseType = respType; 40 | delegate = theDelegate; 41 | parsedObjects = [[NSMutableArray alloc] initWithCapacity:0]; 42 | 43 | // Set up the parser object. 44 | parser = [[NSXMLParser alloc] initWithData:xml]; 45 | [parser setDelegate:self]; 46 | [parser setShouldReportNamespacePrefixes:NO]; 47 | [parser setShouldProcessNamespaces:NO]; 48 | [parser setShouldResolveExternalEntities:NO]; 49 | 50 | // Begin parsing. 51 | [parser parse]; 52 | } 53 | 54 | return self; 55 | } 56 | 57 | 58 | - (void)dealloc 59 | { 60 | [parser release]; 61 | [parsedObjects release]; 62 | [xml release]; 63 | [identifier release]; 64 | delegate = nil; 65 | [super dealloc]; 66 | } 67 | 68 | 69 | #pragma mark NSXMLParser delegate methods 70 | 71 | 72 | - (void)parserDidStartDocument:(NSXMLParser *)theParser 73 | { 74 | //NSLog(@"Parsing begun"); 75 | } 76 | 77 | 78 | - (void)parserDidEndDocument:(NSXMLParser *)theParser 79 | { 80 | //NSLog(@"Parsing complete: %@", parsedObjects); 81 | [delegate parsingSucceededForRequest:identifier ofResponseType:responseType 82 | withParsedObjects:parsedObjects]; 83 | } 84 | 85 | 86 | - (void)parser:(NSXMLParser *)theParser didStartElement:(NSString *)elementName 87 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 88 | attributes:(NSDictionary *)attributeDict 89 | { 90 | //NSLog(@"Started element: %@ (%@)", elementName, attributeDict); 91 | } 92 | 93 | 94 | - (void)parser:(NSXMLParser *)theParser foundCharacters:(NSString *)characters 95 | { 96 | //NSLog(@"Found characters: %@", characters); 97 | } 98 | 99 | 100 | - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName 101 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 102 | { 103 | //NSLog(@"Ended element: %@", elementName); 104 | [self setLastOpenedElement:nil]; 105 | 106 | if ([elementName isEqualToString:@"protected"] 107 | || [elementName isEqualToString:@"truncated"] 108 | || [elementName isEqualToString:@"following"]) { 109 | // Change "true"/"false" into an NSNumber with a BOOL value. 110 | NSNumber *boolNumber = [NSNumber numberWithBool:[[currentNode objectForKey:elementName] isEqualToString:@"true"]]; 111 | [currentNode setObject:boolNumber forKey:elementName]; 112 | } else if ([elementName isEqualToString:@"created_at"]) { 113 | // Change date-string into an NSDate. 114 | // NSLog(@"%@", [currentNode objectForKey:elementName]); 115 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 116 | [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; 117 | dateFormatter.dateFormat = @"EEE MMM dd HH:mm:ss +0000 yyyy"; 118 | NSDate *creationDate = [dateFormatter dateFromString:[currentNode objectForKey:elementName]]; 119 | [dateFormatter release]; 120 | if (creationDate) { 121 | [currentNode setObject:creationDate forKey:elementName]; 122 | } 123 | } 124 | } 125 | 126 | 127 | - (void)parser:(NSXMLParser *)theParser foundAttributeDeclarationWithName:(NSString *)attributeName 128 | forElement:(NSString *)elementName type:(NSString *)type defaultValue:(NSString *)defaultValue 129 | { 130 | //NSLog(@"Found attribute: %@ (%@) [%@] {%@}", attributeName, elementName, type, defaultValue); 131 | } 132 | 133 | 134 | - (void)parser:(NSXMLParser *)theParser foundIgnorableWhitespace:(NSString *)whitespaceString 135 | { 136 | //NSLog(@"Found ignorable whitespace: %@", whitespaceString); 137 | } 138 | 139 | 140 | - (void)parser:(NSXMLParser *)theParser parseErrorOccurred:(NSError *)parseError 141 | { 142 | //NSLog(@"Parsing error occurred: %@", parseError); 143 | [delegate parsingFailedForRequest:identifier ofResponseType:responseType 144 | withError:parseError]; 145 | } 146 | 147 | 148 | #pragma mark Accessors 149 | 150 | 151 | - (NSString *)lastOpenedElement { 152 | return [[lastOpenedElement retain] autorelease]; 153 | } 154 | 155 | 156 | - (void)setLastOpenedElement:(NSString *)value { 157 | if (lastOpenedElement != value) { 158 | [lastOpenedElement release]; 159 | lastOpenedElement = [value copy]; 160 | } 161 | } 162 | 163 | 164 | #pragma mark Utility methods 165 | 166 | 167 | - (void)addSource 168 | { 169 | if (![currentNode objectForKey:TWITTER_SOURCE_REQUEST_TYPE]) { 170 | [currentNode setObject:[NSNumber numberWithInt:requestType] 171 | forKey:TWITTER_SOURCE_REQUEST_TYPE]; 172 | } 173 | } 174 | 175 | 176 | @end 177 | -------------------------------------------------------------------------------- /Classes/TwitterCommonLibraryAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // TwitterCommonLibraryAppDelegate.m 3 | // TwitterCommonLibrary 4 | // 5 | // Created by Tim Shi on 11-01-07. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "TwitterCommonLibraryAppDelegate.h" 10 | #import "TwitterEngine.h" 11 | #import "StreamingDelegate.h" 12 | #import "OAuthSignInViewController.h" 13 | 14 | #define trackingKeyWord @"track=github" //TODO: REPLACE ME 15 | 16 | @implementation TwitterCommonLibraryAppDelegate 17 | 18 | @synthesize window; 19 | 20 | 21 | #pragma mark - 22 | #pragma mark Application lifecycle 23 | 24 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 25 | NSLog(@"Application launched"); 26 | 27 | //Create the view controller 28 | streamingTableController = [[StreamingTableViewController alloc] initWithStyle:UITableViewStylePlain]; 29 | StreamingConsumer* consumer = [[StreamingConsumer alloc] init]; 30 | consumer.delegate = streamingTableController; 31 | streamingDelegate = [[StreamingDelegate alloc] initWithConsumer:consumer]; 32 | [consumer release]; 33 | 34 | [self.window addSubview:streamingTableController.view]; 35 | [self.window makeKeyAndVisible]; 36 | 37 | TwitterEngine* engine = [TwitterEngine sharedEngineWithDelegate:NULL]; 38 | [engine requestRequestToken:self onSuccess:@selector(onRequestTokenSuccess:withData:) onFail:@selector(onRequestTokenFailed:withData:)]; 39 | 40 | signInController = [[OAuthSignInViewController alloc] initWithDelegate:self]; 41 | return YES; 42 | } 43 | 44 | 45 | - (void)applicationWillResignActive:(UIApplication *)application { 46 | /* 47 | Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 48 | Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 49 | */ 50 | } 51 | 52 | 53 | - (void)applicationDidEnterBackground:(UIApplication *)application { 54 | /* 55 | Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 56 | If your application supports background execution, called instead of applicationWillTerminate: when the user quits. 57 | */ 58 | } 59 | 60 | 61 | - (void)applicationWillEnterForeground:(UIApplication *)application { 62 | /* 63 | Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background. 64 | */ 65 | } 66 | 67 | 68 | - (void)applicationDidBecomeActive:(UIApplication *)application { 69 | /* 70 | Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 71 | */ 72 | } 73 | 74 | 75 | - (void)applicationWillTerminate:(UIApplication *)application { 76 | /* 77 | Called when the application is about to terminate. 78 | See also applicationDidEnterBackground:. 79 | */ 80 | } 81 | 82 | #pragma mark - 83 | #pragma mark oAuth delegate 84 | - (void) onRequestTokenSuccess:(OAServiceTicket *)ticket withData:(NSData *)data { 85 | //Set the engine's request token with the data recieved. 86 | TwitterEngine* sharedEngine = [TwitterEngine sharedEngine]; 87 | [sharedEngine setRequestToken:ticket withData:data]; 88 | 89 | //now we can start the sign in process. 90 | [signInController loadRequest:[sharedEngine authorizeURLRequest]]; 91 | [streamingTableController presentModalViewController:signInController animated:YES]; 92 | } 93 | 94 | - (void) onRequestTokenFailed:(OAServiceTicket *)ticket withData:(NSData *)data { 95 | NSLog(@"request token failed"); 96 | 97 | //TODO: add your own error handling here. 98 | } 99 | 100 | - (void) onAccessTokenSuccess:(OAServiceTicket *)ticket withData:(NSData *)data { 101 | #ifdef DEBUG 102 | NSLog(@"got access token"); 103 | #endif 104 | //Set the engine's request token with the data recieved. 105 | TwitterEngine* sharedEngine = [TwitterEngine sharedEngine]; 106 | [sharedEngine setAccessTokenWith:ticket withData:data]; 107 | 108 | [self startStreaming]; 109 | } 110 | 111 | - (void) onAccessTokenFailed:(OAServiceTicket *)ticket withData:(NSData *)data { 112 | NSLog(@"Access token failed"); 113 | 114 | //TODO: add your own error handling here. 115 | } 116 | 117 | 118 | #pragma mark - 119 | #pragma mark OAuthSignInViewController delegate 120 | - (void) authenticatedWithPin:(NSString*) pin{ 121 | #ifdef DEBUG 122 | NSLog(@"authenticated with pin %@", pin); 123 | #endif 124 | TwitterEngine *engine = [TwitterEngine sharedEngine]; 125 | engine._pin = pin; 126 | 127 | //since we got the pin, we can ask for the access token now. 128 | [engine requestAccessToken:self onSuccess:@selector(onAccessTokenSuccess:withData:) onFail:@selector(onAccessTokenFailed:)]; 129 | 130 | [streamingTableController dismissModalViewControllerAnimated:YES]; 131 | } 132 | - (void) authenticationFailed{ 133 | #ifdef DEBUG 134 | NSLog(@"authentication failed"); 135 | #endif 136 | [streamingTableController dismissModalViewControllerAnimated:YES]; 137 | } 138 | - (void) authenticationCanceled{ 139 | #ifdef DEBUG 140 | NSLog(@"authentication canceled"); 141 | #endif 142 | [streamingTableController dismissModalViewControllerAnimated:YES]; 143 | } 144 | 145 | #pragma mark - 146 | #pragma mark streaming 147 | -(void) startStreaming{ 148 | NSURL* url = [[NSURL alloc] initWithString:@"http://stream.twitter.com/1/statuses/filter.json"]; 149 | 150 | TwitterEngine* engine = [TwitterEngine sharedEngine]; 151 | [engine startStreamingWithDelegate:streamingDelegate withURL:url forTracking:trackingKeyWord]; 152 | 153 | [url release]; 154 | } 155 | 156 | 157 | #pragma mark - 158 | #pragma mark Memory management 159 | 160 | - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { 161 | /* 162 | Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later. 163 | */ 164 | } 165 | 166 | 167 | - (void)dealloc { 168 | [signInController release]; 169 | [streamingTableController release]; 170 | [streamingDelegate release]; 171 | [window release]; 172 | [super dealloc]; 173 | } 174 | 175 | 176 | @end 177 | -------------------------------------------------------------------------------- /oauthconsumer/Crypto/sha1.c: -------------------------------------------------------------------------------- 1 | /* 2 | SHA-1 in C 3 | By Steve Reid 4 | 100% Public Domain 5 | 6 | Test Vectors (from FIPS PUB 180-1) 7 | "abc" 8 | A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D 9 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" 10 | 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 11 | A million repetitions of "a" 12 | 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F 13 | */ 14 | 15 | /* #define LITTLE_ENDIAN * This should be #define'd if true. */ 16 | #if __LITTLE_ENDIAN__ 17 | #define LITTLE_ENDIAN 18 | #endif 19 | /* #define SHA1HANDSOFF * Copies data before messing with it. */ 20 | 21 | #include 22 | #include 23 | 24 | #include "sha1.h" 25 | 26 | void SHA1Transform(unsigned long state[5], unsigned char buffer[64]); 27 | 28 | #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) 29 | 30 | /* blk0() and blk() perform the initial expand. */ 31 | /* I got the idea of expanding during the round function from SSLeay */ 32 | #ifdef LITTLE_ENDIAN 33 | #define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ 34 | |(rol(block->l[i],8)&0x00FF00FF)) 35 | #else 36 | #define blk0(i) block->l[i] 37 | #endif 38 | #define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ 39 | ^block->l[(i+2)&15]^block->l[i&15],1)) 40 | 41 | /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ 42 | #define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); 43 | #define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); 44 | #define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); 45 | #define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); 46 | #define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); 47 | 48 | 49 | /* Hash a single 512-bit block. This is the core of the algorithm. */ 50 | 51 | void SHA1Transform(unsigned long state[5], unsigned char buffer[64]) 52 | { 53 | unsigned long a, b, c, d, e; 54 | typedef union { 55 | unsigned char c[64]; 56 | unsigned long l[16]; 57 | } CHAR64LONG16; 58 | CHAR64LONG16* block; 59 | #ifdef SHA1HANDSOFF 60 | static unsigned char workspace[64]; 61 | block = (CHAR64LONG16*)workspace; 62 | memcpy(block, buffer, 64); 63 | #else 64 | block = (CHAR64LONG16*)buffer; 65 | #endif 66 | /* Copy context->state[] to working vars */ 67 | a = state[0]; 68 | b = state[1]; 69 | c = state[2]; 70 | d = state[3]; 71 | e = state[4]; 72 | /* 4 rounds of 20 operations each. Loop unrolled. */ 73 | R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); 74 | R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); 75 | R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); 76 | R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); 77 | R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); 78 | R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); 79 | R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); 80 | R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); 81 | R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); 82 | R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); 83 | R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); 84 | R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); 85 | R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); 86 | R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); 87 | R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); 88 | R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); 89 | R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); 90 | R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); 91 | R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); 92 | R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); 93 | /* Add the working vars back into context.state[] */ 94 | state[0] += a; 95 | state[1] += b; 96 | state[2] += c; 97 | state[3] += d; 98 | state[4] += e; 99 | /* Wipe variables */ 100 | a = b = c = d = e = 0; 101 | 102 | (void)a; (void)b; (void)c; (void)d; (void)e; 103 | } 104 | 105 | 106 | /* SHA1Init - Initialize new context */ 107 | 108 | void SHA1Init(SHA1_CTX* context) 109 | { 110 | /* SHA1 initialization constants */ 111 | context->state[0] = 0x67452301; 112 | context->state[1] = 0xEFCDAB89; 113 | context->state[2] = 0x98BADCFE; 114 | context->state[3] = 0x10325476; 115 | context->state[4] = 0xC3D2E1F0; 116 | context->count[0] = context->count[1] = 0; 117 | } 118 | 119 | 120 | /* Run your data through this. */ 121 | 122 | void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len) 123 | { 124 | unsigned int i, j; 125 | 126 | j = (context->count[0] >> 3) & 63; 127 | if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++; 128 | context->count[1] += (len >> 29); 129 | if ((j + len) > 63) { 130 | memcpy(&context->buffer[j], data, (i = 64-j)); 131 | SHA1Transform(context->state, context->buffer); 132 | for ( ; i + 63 < len; i += 64) { 133 | SHA1Transform(context->state, &data[i]); 134 | } 135 | j = 0; 136 | } 137 | else i = 0; 138 | memcpy(&context->buffer[j], &data[i], len - i); 139 | } 140 | 141 | 142 | /* Add padding and return the message digest. */ 143 | 144 | void SHA1Final(unsigned char digest[20], SHA1_CTX* context) 145 | { 146 | unsigned long i, j; 147 | unsigned char finalcount[8]; 148 | 149 | for (i = 0; i < 8; i++) { 150 | finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] 151 | >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ 152 | } 153 | SHA1Update(context, (unsigned char *)"\200", 1); 154 | while ((context->count[0] & 504) != 448) { 155 | SHA1Update(context, (unsigned char *)"\0", 1); 156 | } 157 | SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ 158 | for (i = 0; i < 20; i++) { 159 | digest[i] = (unsigned char) 160 | ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); 161 | } 162 | /* Wipe variables */ 163 | i = j = 0; 164 | 165 | (void)i; (void)j; 166 | 167 | memset(context->buffer, 0, 64); 168 | memset(context->state, 0, 20); 169 | memset(context->count, 0, 8); 170 | memset(&finalcount, 0, 8); 171 | #ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */ 172 | SHA1Transform(context->state, context->buffer); 173 | #endif 174 | } 175 | -------------------------------------------------------------------------------- /StreamingTableViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // StreamingTableViewController.m 3 | // TwitterCommonLibrary 4 | // 5 | // Created by Tim Shi on 11-01-10. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "StreamingTableViewController.h" 10 | #import "CJSONDeserializer.h" 11 | 12 | @implementation StreamingTableViewController 13 | 14 | 15 | #pragma mark - 16 | #pragma mark Initialization 17 | 18 | - (id)initWithStyle:(UITableViewStyle)style { 19 | // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. 20 | self = [super initWithStyle:style]; 21 | if (self) { 22 | streamingTweets = [[NSMutableArray alloc] initWithCapacity:25]; 23 | self.tableView.rowHeight = 60.0; 24 | } 25 | return self; 26 | } 27 | 28 | #pragma mark streamingDelegate 29 | - (void) consumerDidProcessStatus:(NSString*) statusString{ 30 | NSString *jsonString = statusString; 31 | NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; 32 | NSDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:nil]; 33 | 34 | if (dictionary!=nil) { 35 | #ifdef DEBUG 36 | NSLog(@"status is %@", [dictionary objectForKey:@"text"]); 37 | #endif 38 | [streamingTweets insertObject:[dictionary objectForKey:@"text"] atIndex:0]; 39 | 40 | //This method here is slow 41 | [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObjects: 42 | [NSIndexPath indexPathForRow:0 inSection:0], 43 | nil] 44 | withRowAnimation:UITableViewRowAnimationNone]; 45 | } 46 | } 47 | #pragma mark streamingDelegate end 48 | 49 | #pragma mark - 50 | #pragma mark View lifecycle 51 | 52 | /* 53 | - (void)viewDidLoad { 54 | [super viewDidLoad]; 55 | 56 | // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 57 | // self.navigationItem.rightBarButtonItem = self.editButtonItem; 58 | } 59 | */ 60 | 61 | /* 62 | - (void)viewWillAppear:(BOOL)animated { 63 | [super viewWillAppear:animated]; 64 | } 65 | */ 66 | /* 67 | - (void)viewDidAppear:(BOOL)animated { 68 | [super viewDidAppear:animated]; 69 | } 70 | */ 71 | /* 72 | - (void)viewWillDisappear:(BOOL)animated { 73 | [super viewWillDisappear:animated]; 74 | } 75 | */ 76 | /* 77 | - (void)viewDidDisappear:(BOOL)animated { 78 | [super viewDidDisappear:animated]; 79 | } 80 | */ 81 | /* 82 | // Override to allow orientations other than the default portrait orientation. 83 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 84 | // Return YES for supported orientations. 85 | return (interfaceOrientation == UIInterfaceOrientationPortrait); 86 | } 87 | */ 88 | 89 | 90 | #pragma mark - 91 | #pragma mark Table view data source 92 | 93 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 94 | // Return the number of sections. 95 | return 1; 96 | } 97 | 98 | 99 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 100 | // Return the number of rows in the section. 101 | return [streamingTweets count]; 102 | } 103 | 104 | 105 | // Customize the appearance of table view cells. 106 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 107 | 108 | static NSString *CellIdentifier = @"Cell"; 109 | 110 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 111 | if (cell == nil) { 112 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 113 | cell.backgroundColor = [UIColor clearColor]; 114 | cell.textLabel.numberOfLines = 3; 115 | cell.textLabel.textColor = [UIColor darkGrayColor]; 116 | cell.textLabel.backgroundColor = [UIColor clearColor]; 117 | } 118 | 119 | UIFont *font = [UIFont fontWithName:cell.textLabel.font.familyName size:12.0f]; 120 | CGSize maximumSize = CGSizeMake(300, 100); 121 | CGSize tweetStringSize = [[streamingTweets objectAtIndex:indexPath.row] 122 | sizeWithFont:font 123 | constrainedToSize:maximumSize 124 | lineBreakMode:cell.textLabel.lineBreakMode]; 125 | 126 | CGRect frame = CGRectMake(0, 0, 300, tweetStringSize.height); 127 | cell.textLabel.frame = frame; 128 | cell.textLabel.font = font; 129 | cell.textLabel.text = [streamingTweets objectAtIndex:indexPath.row]; 130 | 131 | return cell; 132 | } 133 | 134 | 135 | /* 136 | // Override to support conditional editing of the table view. 137 | - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 138 | // Return NO if you do not want the specified item to be editable. 139 | return YES; 140 | } 141 | */ 142 | 143 | 144 | /* 145 | // Override to support editing the table view. 146 | - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 147 | 148 | if (editingStyle == UITableViewCellEditingStyleDelete) { 149 | // Delete the row from the data source. 150 | [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 151 | } 152 | else if (editingStyle == UITableViewCellEditingStyleInsert) { 153 | // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 154 | } 155 | } 156 | */ 157 | 158 | 159 | /* 160 | // Override to support rearranging the table view. 161 | - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { 162 | } 163 | */ 164 | 165 | 166 | /* 167 | // Override to support conditional rearranging of the table view. 168 | - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { 169 | // Return NO if you do not want the item to be re-orderable. 170 | return YES; 171 | } 172 | */ 173 | 174 | 175 | #pragma mark - 176 | #pragma mark Table view delegate 177 | 178 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 179 | // Navigation logic may go here. Create and push another view controller. 180 | /* 181 | <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; 182 | // ... 183 | // Pass the selected object to the new view controller. 184 | [self.navigationController pushViewController:detailViewController animated:YES]; 185 | [detailViewController release]; 186 | */ 187 | } 188 | 189 | 190 | #pragma mark - 191 | #pragma mark Memory management 192 | 193 | - (void)didReceiveMemoryWarning { 194 | // Releases the view if it doesn't have a superview. 195 | [super didReceiveMemoryWarning]; 196 | 197 | // Relinquish ownership any cached data, images, etc. that aren't in use. 198 | } 199 | 200 | - (void)viewDidUnload { 201 | // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. 202 | // For example: self.myOutlet = nil; 203 | } 204 | 205 | 206 | - (void)dealloc { 207 | [streamingTweets release]; 208 | [super dealloc]; 209 | } 210 | 211 | 212 | @end 213 | 214 | --------------------------------------------------------------------------------