Skip to content
Browse files

Added method to create lists for authenticated users.

`- (NSString *)createListsForUser:(NSString *)username withName:(NSString *)listName withOptions:(NSDictionary *)options;`
  • Loading branch information...
1 parent 60d02ad commit 0b58bc20601ed6892509f6752e6df955cefd1091 @catsby catsby committed with alexrepty Aug 10, 2010
Showing with 45 additions and 1 deletion.
  1. +8 −0 AppController.m
  2. +10 −0 MGTwitterEngine.h
  3. +26 −1 MGTwitterEngine.m
  4. +1 −0 MGTwitterRequestTypes.h
View
8 AppController.m
@@ -61,6 +61,14 @@ -(void)runTests{
NSLog(@"getRepliesStartingAtPage: connectionIdentifier = %@", [twitterEngine getRepliesStartingAtPage:0]);
//NSLog(@"deleteUpdate: connectionIdentifier = %@", [twitterEngine deleteUpdate:TESTING_ID]);
+ // Lists
+ //NSLog(@"get Lists for User:%@ connectionIdentifier = %@", TESTING_PRIMARY_USER, [twitterEngine getListsForUser:TESTING_PRIMARY_USER]);
+
+ // NSString *listName = @"test list 3";
+ // NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"private", @"mode", @"a description", @"description", nil];
+ //
+ // NSLog(@"creating list %@, connection identifier: %@", listName, [twitterEngine createListsForUser:TESTING_PRIMARY_USER withName:listName withOptions:dict]);
+
// User methods:
//NSLog(@"getRecentlyUpdatedFriendsFor: connectionIdentifier = %@", [twitterEngine getRecentlyUpdatedFriendsFor:nil startingAtPage:0]);
//NSLog(@"getFollowersIncludingCurrentStatus: connectionIdentifier = %@", [twitterEngine getFollowersIncludingCurrentStatus:YES]);
View
10 MGTwitterEngine.h
@@ -133,8 +133,18 @@
- (NSString *)getUserInformationForEmail:(NSString *)email; // users/show
// List Methods
+
+// List the lists of the specified user. Private lists will be included if the
+// authenticated users is the same as the user who's lists are being returned.
- (NSString *)getListsForUser:(NSString *)username;
+// Creates a new list for the authenticated user. Accounts are limited to 20 lists.
+// Options include:
+// mode - Whether your list is public or private. Values can be public or private.
+// If no mode is specified the list will be public.
+// description - The description to give the list.
+- (NSString *)createListsForUser:(NSString *)username withName:(NSString *)listName withOptions:(NSDictionary *)options;
+
// Direct Message methods
- (NSString *)getDirectMessagesSinceID:(MGTwitterEngineID)sinceID startingAtPage:(int)pageNum; // direct_messages
View
27 MGTwitterEngine.m
@@ -1549,7 +1549,7 @@ - (NSString *)deleteDirectMessage:(MGTwitterEngineID)updateID
}
#pragma mark Lists
-
+
- (NSString *)getListsForUser:(NSString *)username
{
NSString *path = [NSString stringWithFormat:@"%@/lists.%@", username, API_FORMAT];
@@ -1559,6 +1559,31 @@ - (NSString *)getListsForUser:(NSString *)username
responseType:MGTwitterUserLists];
}
+- (NSString *)createListsForUser:(NSString *)username withName:(NSString *)listName withOptions:(NSDictionary *)options;
+{
+ if (!username || !listName) {
+ NSLog(@"returning nil");
+ return nil;
+ }
+
+ NSString *path = [NSString stringWithFormat:@"%@/lists.%@", username, API_FORMAT];
+
+ NSMutableDictionary *queryParameters = [NSMutableDictionary dictionaryWithCapacity:0];
+ if ([options objectForKey:@"mode"]) {
+ [queryParameters setObject:[options objectForKey:@"mode"] forKey:@"mode"];
+ }
+ if ([options objectForKey:@"description"]) {
+ [queryParameters setObject:[options objectForKey:@"description"] forKey:@"description"];
+ }
+ [queryParameters setObject:listName forKey:@"name"];
+ NSString *body = [self _queryStringWithBase:nil parameters:queryParameters prefixed:NO];
+
+ return [self _sendRequestWithMethod:HTTP_POST_METHOD path:path
+ queryParameters:queryParameters body:body
+ requestType:MGTwitterUserListCreate
+ responseType:MGTwitterUserLists];
+}
+
#pragma mark Friendship methods
View
1 MGTwitterRequestTypes.h
@@ -48,6 +48,7 @@ typedef enum _MGTwitterRequestType {
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
MGTwitterUserListsRequest,
+ MGTwitterUserListCreate,
#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
MGTwitterSearchRequest, // performing a search
MGTwitterSearchCurrentTrendsRequest, // getting the current trends

0 comments on commit 0b58bc2

Please sign in to comment.
Something went wrong with that request. Please try again.