Permalink
Browse files

fix POSTing with data

  • Loading branch information...
1 parent c849201 commit bd7dc325de734ff32ad233a6b0294b77352a1022 @zagraves zagraves committed Oct 9, 2009
Showing with 27 additions and 15 deletions.
  1. +21 −12 Source/YOSSocial/YOSRequestClient.m
  2. +6 −3 Source/YOSSocial/YOSUserRequest.m
@@ -15,7 +15,7 @@
#define OAUTH_PARAMS_IN_AUTH_HEADER @"OAUTH_PARAMS_IN_AUTH_HEADER"
#define OAUTH_PARAMS_IN_QUERY_STRING @"OAUTH_PARAMS_IN_QUERY_STRING"
-static NSString *const kYOSUserAgentPrefix = @"YosCocoaSdk/0.4";
+static NSString *const kYOSUserAgentPrefix = @"YosCocoaSdk/0.5";
@implementation YOSRequestClient
@@ -66,7 +66,6 @@ - (YOSResponseData *)sendSynchronousRequest
YOSResponseData *serviceResponseData = [YOSResponseData responseWithData:connectionResponseData
andURLResponse:urlResponse];
-
return serviceResponseData;
}
@@ -76,7 +75,7 @@ - (BOOL)sendAsyncRequestWithDelegate:(id)delegate
[self setRequestDelegate:delegate];
NSMutableURLRequest *urlRequest = [self buildUrlRequest];
- // self.URLConnection = [[NSURLConnection connectionWithRequest:urlRequest delegate:self] retain];
+ // self.URLConnection = [[NSURLConnection connectionWithRequest:urlRequest delegate:self] retain];
[self setURLConnection:[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self startImmediately:YES]];
@@ -99,16 +98,26 @@ - (NSMutableURLRequest *)buildUrlRequest
if([self.HTTPMethod isEqualToString:@"POST"])
{
- NSString *requestAbsoluteURLString = [self.requestUrl absoluteString];
- NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@", requestAbsoluteURLString]];
- [urlRequest setURL:url];
+ // NSString *requestAbsoluteURLString = [self.requestUrl absoluteString];
+ // NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@", requestAbsoluteURLString]];
+ // [urlRequest setURL:url];
+ //
+ // NSString *postDataQueryString = (oauthRequest)
+ // ? [[oauthRequest allRequestParametersAsDictionary] QueryString]
+ // : [requestParameters QueryString];
+ //
+ // NSData *postData = [postDataQueryString dataUsingEncoding: NSASCIIStringEncoding];
+ // [urlRequest setHTTPBody:postData];
- NSString *postDataQueryString = (oauthRequest)
- ? [[oauthRequest allRequestParametersAsDictionary] QueryString]
- : [requestParameters QueryString];
+ NSDictionary *queryParameters = (oauthRequest && [oauthParamsLocation isEqualToString:OAUTH_PARAMS_IN_QUERY_STRING])
+ ? [oauthRequest allRequestParametersAsDictionary]
+ : requestParameters;
- NSData *postData = [postDataQueryString dataUsingEncoding: NSASCIIStringEncoding];
- [urlRequest setHTTPBody:postData];
+ NSString *requestAbsoluteURLString = [NSString stringWithFormat:@"%@?%@", [self.requestUrl absoluteString], [queryParameters QueryString]];
+ NSURL *url = [NSURL URLWithString:requestAbsoluteURLString];
+
+ [urlRequest setURL:url];
+ [urlRequest setHTTPBody:self.HTTPBody];
}
else {
NSDictionary *queryParameters = (oauthRequest && [oauthParamsLocation isEqualToString:OAUTH_PARAMS_IN_QUERY_STRING])
@@ -256,4 +265,4 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)aConnection
}
}
-@end
+@end
@@ -62,13 +62,14 @@ - (BOOL)fetchContactsWithStart:(NSInteger)start andCount:(NSInteger)count withDe
[client setRequestUrl:url];
[client setHTTPMethod:@"GET"];
[client setRequestParameters:requestParameters];
+
return [client sendAsyncRequestWithDelegate:delegate];
}
- (BOOL)fetchContactWithID:(NSInteger)contactId withDelegate:(id)delegate
{
NSString *method = [NSString stringWithFormat:@"contact"];
- NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@/%@", self.baseUrl, self.apiVersion, @"user", self.user.guid, method, contactId];
+ NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@/%@", self.baseUrl, self.apiVersion, @"user", self.user.guid, method, [NSString stringWithFormat:@"%d", contactId]];
NSURL *url = [NSURL URLWithString:requestUrl];
NSMutableDictionary *requestParameters = [NSMutableDictionary dictionary];
@@ -84,7 +85,7 @@ - (BOOL)fetchContactWithID:(NSInteger)contactId withDelegate:(id)delegate
return [client sendAsyncRequestWithDelegate:delegate];
}
-- (BOOL)addContact:(NSDictionary *)contact withDelegate:(id)delegate
+- (BOOL)addContact:(NSDictionary *)contact
{
NSString *method = [NSString stringWithFormat:@"contacts"];
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@", self.baseUrl, self.apiVersion, @"user", self.user.guid, method];
@@ -114,6 +115,8 @@ - (BOOL)addContact:(NSDictionary *)contact withDelegate:(id)delegate
YOSResponseData *response = [client sendSynchronousRequest];
NSInteger httpStatusCode = [response.HTTPURLResponse statusCode];
+ NSLog(@"%@", [response responseText]);
+
if(!response.data) {
return FALSE;
}
@@ -142,7 +145,7 @@ - (BOOL)fetchContactSyncRevision:(NSInteger)revision withDelegate:(id)delegate
return [client sendAsyncRequestWithDelegate:delegate];
}
-- (BOOL)syncContactsRevision:(NSDictionary *)contactsync withDelegate:(id)delegate
+- (BOOL)syncContactsRevision:(NSDictionary *)contactsync
{
NSString *method = [NSString stringWithFormat:@"contacts"];
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@", self.baseUrl, self.apiVersion, @"user", self.user.guid, method];

0 comments on commit bd7dc32

Please sign in to comment.