Permalink
Browse files

Added initial support for the Social Graph API requests.

At present, I am only handling NSXML parsing. LibXML is next and YAJL once I have it built and installed on my system.
  • Loading branch information...
1 parent f36e642 commit 8784e627603b5a4d13c6d6ed2106c7b1b489aef0 @tarasis tarasis committed Mar 20, 2010
View
16 AppController.m
@@ -52,7 +52,9 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
//NSLog(@"getRecentlyUpdatedFriendsFor: connectionIdentifier = %@", [twitterEngine getRecentlyUpdatedFriendsFor:nil startingAtPage:0]);
//NSLog(@"getFollowersIncludingCurrentStatus: connectionIdentifier = %@", [twitterEngine getFollowersIncludingCurrentStatus:YES]);
//NSLog(@"getUserInformationFor: connectionIdentifier = %@", [twitterEngine getUserInformationFor:TESTING_PRIMARY_USER]);
-
+ //NSLog(@"getFriendIDsFor: connectionIdentifier = %@", [twitterEngine getFriendIDsFor:@"duemoko" startingFromCursor:-1]);
+ //NSLog(@"getFollowerIDsFor: connectionIdentifier = %@", [twitterEngine getFollowerIDsFor:username startingFromCursor:-1]);
+
// Direct Message methods:
//NSLog(@"getDirectMessagesSinceID: connectionIdentifier = %@", [twitterEngine getDirectMessagesSinceID:0 startingAtPage:0]);
//NSLog(@"getSentDirectMessagesSinceID: connectionIdentifier = %@", [twitterEngine getSentDirectMessagesSinceID:0 startingAtPage:0]);
@@ -149,12 +151,24 @@ - (void)miscInfoReceived:(NSArray *)miscInfo forRequest:(NSString *)connectionId
NSLog(@"Got misc info for %@:\r%@", connectionIdentifier, miscInfo);
}
+
- (void)searchResultsReceived:(NSArray *)searchResults forRequest:(NSString *)connectionIdentifier
{
NSLog(@"Got search results for %@:\r%@", connectionIdentifier, searchResults);
}
+- (void)socialGraphInfoReceived:(NSArray *)socialGraphInfo forRequest:(NSString *)connectionIdentifier
+{
+ NSLog(@"Got social graph results for %@:\r%@", connectionIdentifier, socialGraphInfo);
+
+// NSLog(@"IDs: %@", [socialGraphInfo valueForKey:@"ids"]);
+// NSLog(@"previous_cursor: %@", [socialGraphInfo valueForKey:@"previous_cursor"]);
+// NSLog(@"next_cursor: %@", [socialGraphInfo valueForKey:@"next_cursor"]);
+// NSLog(@"source_api_request_type: %@", [socialGraphInfo valueForKey:@"source_api_request_type"]);
+}
+
+
- (void)imageReceived:(NSImage *)image forRequest:(NSString *)connectionIdentifier
{
NSLog(@"Got an image for %@: %@", connectionIdentifier, image);
View
5 MGTwitterEngine.h
@@ -181,6 +181,11 @@
- (NSString *)getDowntimeSchedule; // help/downtime_schedule (undocumented)
+// Social Graph methods
+- (NSString *)getFriendIDsFor:(NSString *)username startingFromCursor:(int)cursor; // friends/ids
+- (NSString *)getFollowerIDsFor:(NSString *)username startingFromCursor:(int)cursor; // followers/ids
+
+
#pragma mark Search API methods
// ======================================================================================================
View
43 MGTwitterEngine.m
@@ -34,6 +34,7 @@
#import "MGTwitterUsersParser.h"
#import "MGTwitterMessagesParser.h"
#import "MGTwitterMiscParser.h"
+ #import "MGTwitterSocialGraphParser.h"
#endif
#endif
@@ -700,6 +701,10 @@ - (void)_parseDataForConnection:(MGTwitterHTTPURLConnection *)connection
connectionIdentifier:identifier requestType:requestType
responseType:responseType];
break;
+ case MGTwitterSocialGraph:
+ [MGTwitterSocialGraphParser parserWithXML:xmlData delegate:self
+ connectionIdentifier:identifier requestType:requestType
+ responseType:responseType];
default:
break;
}
@@ -747,6 +752,10 @@ - (void)parsingSucceededForRequest:(NSString *)identifier
[_delegate searchResultsReceived:parsedObjects forRequest:identifier];
break;
#endif
+ case MGTwitterSocialGraph:
+ if ([self _isValidDelegateForSelector:@selector(socialGraphInfoReceived:forRequest:)])
+ [_delegate socialGraphInfoReceived: parsedObjects forRequest:identifier];
+ break;
default:
break;
}
@@ -1108,6 +1117,40 @@ - (NSString *)getFeaturedUsers
#pragma mark User methods
+- (NSString *)getFriendIDsFor:(NSString *)username startingFromCursor:(int)cursor
+{
+ NSLog(@"getFriendIDsFor:%@ atCursor:%d", username, cursor);
+ NSString *path = [NSString stringWithFormat:@"friends/ids.%@", API_FORMAT];
+
+ NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
+ if (username != nil) {
+ [params setObject:username forKey:@"screen_name"];
+ }
+ if (cursor >= -1) {
+ [params setObject:[NSString stringWithFormat:@"%ld", cursor] forKey:@"cursor"];
+ }
+
+ return [self _sendRequestWithMethod:nil path:path queryParameters:params body:nil
+ requestType:MGTwitterFriendIDsRequest
+ responseType:MGTwitterSocialGraph];
+}
+
+- (NSString *)getFollowerIDsFor:(NSString *)username startingFromCursor:(int)cursor
+{
+ NSString *path = [NSString stringWithFormat:@"followers/ids.%@", API_FORMAT];
+
+ NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
+ if (username != nil) {
+ [params setObject:username forKey:@"screen_name"];
+ }
+ if (cursor >= -1) {
+ [params setObject:[NSString stringWithFormat:@"%ld", cursor] forKey:@"cursor"];
+ }
+
+ return [self _sendRequestWithMethod:nil path:path queryParameters:params body:nil
+ requestType:MGTwitterFollowerIDsRequest
+ responseType:MGTwitterSocialGraph];
+}
- (NSString *)getRecentlyUpdatedFriendsFor:(NSString *)username startingAtPage:(int)page
{
View
17 MGTwitterEngine.xcodeproj/project.pbxproj
@@ -27,6 +27,7 @@
C9CB60EC0DF98ED300EE8FCF /* MGTwitterMiscParser.m in Sources */ = {isa = PBXBuildFile; fileRef = C9CB60EB0DF98ED300EE8FCF /* MGTwitterMiscParser.m */; };
C9EF98A10D68AB970041A17E /* NSString+UUID.m in Sources */ = {isa = PBXBuildFile; fileRef = C9EF98A00D68AB970041A17E /* NSString+UUID.m */; };
C9FEB12C0D6095AF009AA322 /* MGTwitterStatusesParser.m in Sources */ = {isa = PBXBuildFile; fileRef = C9FEB12B0D6095AF009AA322 /* MGTwitterStatusesParser.m */; };
+ D47CF9B511541D0A00E07931 /* MGTwitterSocialGraphParser.m in Sources */ = {isa = PBXBuildFile; fileRef = D47CF9B411541D0A00E07931 /* MGTwitterSocialGraphParser.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -89,6 +90,8 @@
C9F6B4910D6F18290066FC1E /* README.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.txt; sourceTree = "<group>"; };
C9FEB12A0D6095AF009AA322 /* MGTwitterStatusesParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGTwitterStatusesParser.h; sourceTree = "<group>"; };
C9FEB12B0D6095AF009AA322 /* MGTwitterStatusesParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGTwitterStatusesParser.m; sourceTree = "<group>"; };
+ D47CF9B311541D0A00E07931 /* MGTwitterSocialGraphParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGTwitterSocialGraphParser.h; sourceTree = "<group>"; };
+ D47CF9B411541D0A00E07931 /* MGTwitterSocialGraphParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGTwitterSocialGraphParser.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -242,6 +245,8 @@
C90031BF0D6B798800C38924 /* MGTwitterMessagesParser.m */,
C9CB60EA0DF98ED300EE8FCF /* MGTwitterMiscParser.h */,
C9CB60EB0DF98ED300EE8FCF /* MGTwitterMiscParser.m */,
+ D47CF9B311541D0A00E07931 /* MGTwitterSocialGraphParser.h */,
+ D47CF9B411541D0A00E07931 /* MGTwitterSocialGraphParser.m */,
);
name = "Twitter NSXML Parsers";
sourceTree = "<group>";
@@ -345,6 +350,7 @@
44F751920E47DDD500858A1B /* MGTwitterLibXMLParser.m in Sources */,
44F751930E47DDD500858A1B /* MGTwitterStatusesLibXMLParser.m in Sources */,
44F751A70E47DEC400858A1B /* NSData+Base64.m in Sources */,
+ D47CF9B511541D0A00E07931 /* MGTwitterSocialGraphParser.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -417,10 +423,7 @@
ARCHS_STANDARD_32_BIT_PRE_XCODE_3_1 = "ppc i386";
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- HEADER_SEARCH_PATHS = (
- /usr/include/libxml2,
- "\"$(SRCROOT)/yajl/build/yajl-0.4.0/include\"",
- );
+ HEADER_SEARCH_PATHS = /usr/include/libxml2;
OTHER_CFLAGS = "-DDEBUG";
PREBINDING = NO;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
@@ -434,11 +437,7 @@
ARCHS_STANDARD_32_BIT_PRE_XCODE_3_1 = "ppc i386";
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- HEADER_SEARCH_PATHS = (
- /usr/include/libxml2,
- "<Multiple",
- "values>",
- );
+ HEADER_SEARCH_PATHS = /usr/include/libxml2;
PREBINDING = NO;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
};
View
1 MGTwitterEngineDelegate.h
@@ -45,6 +45,7 @@ typedef enum _MGTwitterEngineDeliveryOptions {
#if YAJL_AVAILABLE
- (void)searchResultsReceived:(NSArray *)searchResults forRequest:(NSString *)connectionIdentifier;
#endif
+- (void)socialGraphInfoReceived:(NSArray *)socialGraphInfo forRequest:(NSString *)connectionIdentifier;
#if TARGET_OS_IPHONE
- (void)imageReceived:(UIImage *)image forRequest:(NSString *)connectionIdentifier;
View
3 MGTwitterRequestTypes.h
@@ -42,6 +42,8 @@ typedef enum _MGTwitterRequestType {
MGTwitterBlockEnableRequest, // enable block for the specified user
MGTwitterBlockDisableRequest, // disable block for the specified user
MGTwitterImageRequest, // requesting an image
+ MGTwitterFriendIDsRequest, // request the numeric IDs for every user the specified user is following
+ MGTwitterFollowerIDsRequest, // request the numeric IDs of the followers of the specified user
#if YAJL_AVAILABLE
MGTwitterSearchRequest, // performing a search
MGTwitterSearchCurrentTrendsRequest, // getting the current trends
@@ -61,6 +63,7 @@ typedef enum _MGTwitterResponseType {
#if YAJL_AVAILABLE
MGTwitterSearchResults = 9, // search results
#endif
+ MGTwitterSocialGraph = 10,
} MGTwitterResponseType;
// This key is added to each tweet or direct message returned,
View
17 MGTwitterSocialGraphParser.h
@@ -0,0 +1,17 @@
+//
+// MGTwitterSocialGraphParser.h
+// MGTwitterEngine
+//
+// Created by Robert McGovern on 2010/03/19.
+// Copyright 2010 Tarasis. All rights reserved.
+//
+
+#import "MGTwitterEngineGlobalHeader.h"
+
+#import "MGTwitterStatusesParser.h"
+
+@interface MGTwitterSocialGraphParser : MGTwitterStatusesParser {
+ NSMutableArray * twitterIDs;
+}
+
+@end
View
67 MGTwitterSocialGraphParser.m
@@ -0,0 +1,67 @@
+//
+// MGTwitterSocialGraphParser.m
+// MGTwitterEngine
+//
+// Created by Robert McGovern on 2010/03/19.
+// Copyright 2010 Tarasis. All rights reserved.
+//
+
+#import "MGTwitterSocialGraphParser.h"
+#import "MGTwitterMiscParser.h"
+
+
+@implementation MGTwitterSocialGraphParser
+
+
+#pragma mark NSXMLParser delegate methods
+
+
+- (void)parser:(NSXMLParser *)theParser didStartElement:(NSString *)elementName
+ namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
+ attributes:(NSDictionary *)attributeDict
+{
+ //NSLog(@"SG: Started element: %@ (%@)", elementName, attributeDict);
+ [self setLastOpenedElement:elementName];
+
+ if ([elementName isEqualToString:@"ids"]) {
+ twitterIDs = [NSMutableArray arrayWithCapacity:0];
+ NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0];
+ [parsedObjects addObject:newNode];
+ currentNode = newNode;
+ } else if (currentNode && ![elementName isEqualToString:@"id"]) {
+ // Create relevant name-value pair.
+ [currentNode setObject:[NSMutableString string] forKey:elementName];
+ }
+}
+
+- (void)parser:(NSXMLParser *)theParser foundCharacters:(NSString *)characters
+{
+ //NSLog(@"SG: Found characters: %@", characters);
+ // Add the Twitter ID to the array
+ if ([lastOpenedElement isEqualToString:@"id"]) {
+ [twitterIDs addObject:characters];
+ // Append found characters to value of lastOpenedElement in currentNode.
+ } else if (lastOpenedElement && currentNode) {
+ [[currentNode objectForKey:lastOpenedElement] appendString:characters];
+ }
+}
+
+- (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName
+ namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
+{
+ //NSLog(@"SG: didEndElement: %@", elementName);
+
+ [super parser:theParser didEndElement:elementName namespaceURI:namespaceURI qualifiedName:qName];
+
+ // At the end of parsing, add the source type
+ if ([elementName isEqualToString:@"id_list"]) {
+ [self addSource];
+ currentNode = nil;
+ } else if ([elementName isEqualToString:@"ids"]) {
+ [currentNode setObject:twitterIDs forKey:elementName];
+ currentNode = [parsedObjects lastObject];
+ }
+}
+
+
+@end

0 comments on commit 8784e62

Please sign in to comment.