Browse files

better memory management with requestParam dictionaries, support new …

…requestClient method in YOSBaseRequest
  • Loading branch information...
1 parent 8bf8390 commit 4db5c7bd5870964a1db01c76a547ff415be9c99b @zagraves zagraves committed Sep 16, 2009
Showing with 19 additions and 97 deletions.
  1. +0 −6 Source/YOSSocial/YOSUserRequest.h
  2. +19 −91 Source/YOSSocial/YOSUserRequest.m
View
6 Source/YOSSocial/YOSUserRequest.h
@@ -44,12 +44,6 @@
- (void)fetchProfileWithDelegate:(id)delegate;
/**
- * Fetches the user's location data.
- * @param delegate
- */
-- (void)fetchProfileLocationWithDelegate:(id)delegate;
-
-/**
* Fetches the profiles of the user's connections using an asynchronous request.
* @param start An integer specifying the index of the first connection returned.
* @param count An integer specifying the number of connections returned.
View
110 Source/YOSSocial/YOSUserRequest.m
@@ -18,12 +18,8 @@ @implementation YOSUserRequest
+ (id)requestWithSession:(YOSSession *)session
{
- YOSUser *sessionedUser = [[YOSUser alloc] initWithSession:session];
- YOSUserRequest *request = [[YOSUserRequest alloc] initWithYOSUser:sessionedUser];
-
- [sessionedUser autorelease];
- [request autorelease];
-
+ YOSUser *sessionedUser = [[[YOSUser alloc] initWithSession:session] autorelease];
+ YOSUserRequest *request = [[[YOSUserRequest alloc] initWithYOSUser:sessionedUser] autorelease];
return request;
}
@@ -33,24 +29,19 @@ - (void)fetchConnectionsWithStart:(NSInteger)start andCount:(NSInteger)count wit
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@", self.baseUrl, self.apiVersion, @"user", self.user.guid, method];
NSURL *url = [NSURL URLWithString:requestUrl];
- NSMutableDictionary *requestParameters = [[NSMutableDictionary alloc] init];
+ NSMutableDictionary *requestParameters = [NSMutableDictionary dictionary];
[requestParameters setObject:self.format forKey:@"format"];
[requestParameters setObject:self.user.region forKey:@"region"];
[requestParameters setObject:self.user.language forKey:@"lang"];
[requestParameters setObject:[NSString stringWithFormat:@"%d", start] forKey:@"start"];
[requestParameters setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
- YOSRequestClient *client = [[YOSRequestClient alloc] initWithConsumer:[self consumerForRequest]
- andToken:[self tokenForRequest]];
-
+ YOSRequestClient *client = [self requestClient];
[client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
[client setRequestUrl:url];
[client setHTTPMethod:@"GET"];
[client setRequestParameters:requestParameters];
[client sendAsyncRequestWithDelegate:delegate];
-
- [client release];
- [requestParameters release];
}
- (void)fetchContactsWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
@@ -59,24 +50,19 @@ - (void)fetchContactsWithStart:(NSInteger)start andCount:(NSInteger)count withDe
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@", self.baseUrl, self.apiVersion, @"user", self.user.guid, method];
NSURL *url = [NSURL URLWithString:requestUrl];
- NSMutableDictionary *requestParameters = [[NSMutableDictionary alloc] init];
+ NSMutableDictionary *requestParameters = [NSMutableDictionary dictionary];
[requestParameters setObject:self.format forKey:@"format"];
[requestParameters setObject:self.user.region forKey:@"region"];
[requestParameters setObject:self.user.language forKey:@"lang"];
[requestParameters setObject:[NSString stringWithFormat:@"%d", start] forKey:@"start"];
[requestParameters setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
- YOSRequestClient *client = [[YOSRequestClient alloc] initWithConsumer:[self consumerForRequest]
- andToken:[self tokenForRequest]];
-
+ YOSRequestClient *client = [self requestClient];
[client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
[client setRequestUrl:url];
[client setHTTPMethod:@"GET"];
[client setRequestParameters:requestParameters];
[client sendAsyncRequestWithDelegate:delegate];
-
- [client release];
- [requestParameters release];
}
- (void)fetchProfileWithDelegate:(id)delegate
@@ -85,33 +71,17 @@ - (void)fetchProfileWithDelegate:(id)delegate
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@", self.baseUrl, self.apiVersion, @"user", self.user.guid, method];
NSURL *url = [NSURL URLWithString:requestUrl];
- NSMutableDictionary *requestParameters = [[NSMutableDictionary alloc] init];
+ NSMutableDictionary *requestParameters = [NSMutableDictionary dictionary];
[requestParameters setObject:self.format forKey:@"format"];
[requestParameters setObject:self.user.region forKey:@"region"];
[requestParameters setObject:self.user.language forKey:@"lang"];
- YOSRequestClient *client = [[YOSRequestClient alloc] initWithConsumer:[self consumerForRequest]
- andToken:[self tokenForRequest]];
-
+ YOSRequestClient *client = [self requestClient];
[client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
[client setRequestUrl:url];
[client setHTTPMethod:@"GET"];
[client setRequestParameters:requestParameters];
[client sendAsyncRequestWithDelegate:delegate];
-
- [client release];
- [requestParameters release];
-}
-
-- (void)fetchProfileLocationWithDelegate:(id)delegate
-{
- YQLQueryRequest *yqlRequest = [[YQLQueryRequest alloc] initWithYOSUser:[self user]];
-
- NSString *queryJoin = [NSString stringWithFormat:@"select location from social.profile where guid=\"%@\"", start, count, user.guid];
- NSString *yqlQuery = [NSString stringWithFormat:@"select * from geo.places where text in (%@)", queryJoin];
-
- [yqlRequest query:yqlQuery withDelegate:delegate];
- [yqlRequest release];
}
- (void)fetchConnectionProfilesWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
@@ -131,22 +101,17 @@ - (void)fetchStatusWithDelegate:(id)delegate
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@",self.baseUrl,self.apiVersion,@"user",self.user.guid,method];
NSURL *url = [NSURL URLWithString:requestUrl];
- NSMutableDictionary *requestParameters = [[NSMutableDictionary alloc] init];
+ NSMutableDictionary *requestParameters = [NSMutableDictionary dictionary];
[requestParameters setObject:self.format forKey:@"format"];
[requestParameters setObject:self.user.region forKey:@"region"];
[requestParameters setObject:self.user.language forKey:@"lang"];
- YOSRequestClient *client = [[YOSRequestClient alloc] initWithConsumer:[self consumerForRequest]
- andToken:[self tokenForRequest]];
-
+ YOSRequestClient *client = [self requestClient];
[client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
[client setRequestUrl:url];
[client setHTTPMethod:@"GET"];
[client setRequestParameters:requestParameters];
[client sendAsyncRequestWithDelegate:delegate];
-
- [client release];
- [requestParameters release];
}
- (void)fetchConnectionsStatusWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
@@ -169,25 +134,20 @@ - (void)fetchUpdatesWithStart:(NSInteger)start andCount:(NSInteger)count withDel
NSString *updatesDefaultSortingParam = [NSString stringWithFormat:@"pubDate"];
NSString *updatesTransform = [NSString stringWithFormat:@"(sort \"%@\" numeric descending (all))", updatesDefaultSortingParam];
- NSMutableDictionary *requestParameters = [[NSMutableDictionary alloc] init];
+ NSMutableDictionary *requestParameters = [NSMutableDictionary dictionary];
[requestParameters setObject:self.format forKey:@"format"];
[requestParameters setObject:self.user.region forKey:@"region"];
[requestParameters setObject:self.user.language forKey:@"lang"];
[requestParameters setObject:[NSString stringWithFormat:@"%d", start] forKey:@"start"];
[requestParameters setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
[requestParameters setObject:updatesTransform forKey:@"transform"];
- YOSRequestClient *client = [[YOSRequestClient alloc] initWithConsumer:[self consumerForRequest]
- andToken:[self tokenForRequest]];
-
+ YOSRequestClient *client = [self requestClient];
[client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
[client setRequestUrl:url];
[client setHTTPMethod:@"GET"];
[client setRequestParameters:requestParameters];
[client sendAsyncRequestWithDelegate:delegate];
-
- [client release];
- [requestParameters release];
}
- (void)fetchConnectionUpdatesWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
@@ -199,25 +159,20 @@ - (void)fetchConnectionUpdatesWithStart:(NSInteger)start andCount:(NSInteger)cou
NSString *updatesDefaultSortingParam = [NSString stringWithFormat:@"pubDate"];
NSString *updatesTransform = [NSString stringWithFormat:@"(sort \"%@\" numeric descending (all))", updatesDefaultSortingParam];
- NSMutableDictionary *requestParameters = [[NSMutableDictionary alloc] init];
+ NSMutableDictionary *requestParameters = [NSMutableDictionary dictionary];
[requestParameters setObject:self.format forKey:@"format"];
[requestParameters setObject:self.user.region forKey:@"region"];
[requestParameters setObject:self.user.language forKey:@"lang"];
[requestParameters setObject:[NSString stringWithFormat:@"%d", start] forKey:@"start"];
[requestParameters setObject:[NSString stringWithFormat:@"%d", count] forKey:@"count"];
[requestParameters setObject:updatesTransform forKey:@"transform"];
- YOSRequestClient *client = [[YOSRequestClient alloc] initWithConsumer:[self consumerForRequest]
- andToken:[self tokenForRequest]];
-
+ YOSRequestClient *client = [self requestClient];
[client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
[client setRequestUrl:url];
[client setHTTPMethod:@"GET"];
[client setRequestParameters:requestParameters];
[client sendAsyncRequestWithDelegate:delegate];
-
- [client release];
- [requestParameters release];
}
- (BOOL)insertUpdateWithTitle:(NSString *)aTitle
@@ -242,7 +197,7 @@ - (BOOL)insertUpdateWithTitle:(NSString *)aTitle
NSString *timestamp = [NSString stringWithFormat:@"%d", (long)[aDate timeIntervalSince1970]];
NSString *updateSource = [NSString stringWithFormat:@"APP.%@", theSession.applicationId];
- NSMutableDictionary *updateData = [[NSMutableDictionary alloc] initWithCapacity:10];
+ NSMutableDictionary *updateData = [NSMutableDictionary dictionary];
[updateData setObject:user.guid forKey:@"collectionID"];
[updateData setObject:updateSource forKey:@"source"];
[updateData setObject:aSuid forKey:@"suid"];
@@ -262,18 +217,14 @@ - (BOOL)insertUpdateWithTitle:(NSString *)aTitle
NSString *jsonUpdatesPayload = [self serializeDictionary:updatesDataPayload];
NSData *updatesHTTPBody = [jsonUpdatesPayload dataUsingEncoding:NSUTF8StringEncoding];
- [updateData release];
-
NSString *method = [NSString stringWithFormat:@"updates"];
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@/%@/%@", baseUrl, apiVersion, @"user", user.guid, method, updateSource, aSuid];
NSURL *url = [NSURL URLWithString:requestUrl];
NSMutableDictionary *requestHeaders = [NSMutableDictionary dictionary];
[requestHeaders setObject:@"application/json" forKey:@"Content-Type"];
- YOSRequestClient *client = [[YOSRequestClient alloc] initWithConsumer:[self consumerForRequest]
- andToken:[self tokenForRequest]];
-
+ YOSRequestClient *client = [self requestClient];
[client setRequestUrl:url];
[client setHTTPMethod:@"PUT"];
[client setHTTPBody:updatesHTTPBody];
@@ -283,10 +234,6 @@ - (BOOL)insertUpdateWithTitle:(NSString *)aTitle
YOSResponseData *response = [client sendSynchronousRequest];
NSInteger httpStatusCode = [response.HTTPURLResponse statusCode];
- // NSLog(@"%d", httpStatusCode);
-
- [client release];
-
if(!response.data) {
return FALSE;
}
@@ -313,20 +260,14 @@ - (BOOL)deleteUpdate:(NSString *)aSuid
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@/%@/%@", baseUrl, apiVersion, @"user", user.guid, method, updateSource, aSuid];
NSURL *url = [NSURL URLWithString:requestUrl];
- YOSRequestClient *client = [[YOSRequestClient alloc] initWithConsumer:[self consumerForRequest]
- andToken:[self tokenForRequest]];
-
+ YOSRequestClient *client = [self requestClient];
[client setRequestUrl:url];
[client setHTTPMethod:@"DELETE"];
[client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
YOSResponseData *response = [client sendSynchronousRequest];
NSInteger httpStatusCode = [response.HTTPURLResponse statusCode];
- // NSLog(@"%d", httpStatusCode);
-
- [client release];
-
if(!response.data) {
return FALSE;
}
@@ -355,9 +296,7 @@ - (BOOL)setStatus:(NSString *)theMessage
NSData *statusHTTPBody = [[self serializeDictionary:statusDictionary] dataUsingEncoding:NSUTF8StringEncoding];
- YOSRequestClient *client = [[YOSRequestClient alloc] initWithConsumer:[self consumerForRequest]
- andToken:[self tokenForRequest]];
-
+ YOSRequestClient *client = [self requestClient];
[client setRequestUrl:url];
[client setHTTPMethod:@"PUT"];
[client setHTTPBody:statusHTTPBody];
@@ -367,11 +306,6 @@ - (BOOL)setStatus:(NSString *)theMessage
YOSResponseData *response = [client sendSynchronousRequest];
NSInteger httpStatusCode = [response.HTTPURLResponse statusCode];
- NSLog(@"%@", response.responseText);
- // NSLog(@"%d", httpStatusCode);
-
- [client release];
-
if(!response.data) {
return FALSE;
}
@@ -389,9 +323,7 @@ - (BOOL)setSmallViewWithContents:(NSString *)content
NSData *smallViewContentHTTPBody = [content dataUsingEncoding:NSUTF8StringEncoding];
- YOSRequestClient *client = [[YOSRequestClient alloc] initWithConsumer:[self consumerForRequest]
- andToken:[self tokenForRequest]];
-
+ YOSRequestClient *client = [self requestClient];
[client setRequestUrl:url];
[client setHTTPMethod:@"PUT"];
[client setHTTPBody:smallViewContentHTTPBody];
@@ -401,10 +333,6 @@ - (BOOL)setSmallViewWithContents:(NSString *)content
YOSResponseData *response = [client sendSynchronousRequest];
NSInteger httpStatusCode = [response.HTTPURLResponse statusCode];
- [client release];
-
- // NSLog(@"%d", httpStatusCode);
-
if(!response.data) {
return FALSE;
}

0 comments on commit 4db5c7b

Please sign in to comment.