Skip to content
Browse files

adding contacts write/sync. addContact, getContactSync, syncContacts,…

… getContact
  • Loading branch information...
1 parent 8c07367 commit c8492018be813f6cc80e3d58ccbf5684b2a913cd @zagraves zagraves committed Oct 8, 2009
Showing with 146 additions and 4 deletions.
  1. +30 −2 Source/YOSSocial/YOSUserRequest.h
  2. +116 −2 Source/YOSSocial/YOSUserRequest.m
View
32 Source/YOSSocial/YOSUserRequest.h
@@ -38,6 +38,34 @@
- (BOOL)fetchContactsWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate;
/**
+ * Fetches a single contact given a contact ID number.
+ * @param contactId An integer specifying a contact ID.
+ * @param delegate An object containing the methods to handle the request's response.
+ */
+- (BOOL)fetchContactWithID:(NSInteger)contactId withDelegate:(id)delegate;
+
+/**
+ * Adds a contact to the users address book given a dictionary of contact fields.
+ * @param contact A dictionary containing a list of contact fields such as name, email and nickname
+ * @param delegate An object containing the methods to handle the request's response.
+ */
+- (BOOL)addContact:(NSDictionary *)contact withDelegate:(id)delegate;
+
+/**
+ * Fetches the users contact list given a local revision ID.
+ * @param revision An integer specifying the local revision.
+ * @param delegate An object containing the methods to handle the request's response.
+ */
+- (BOOL)fetchContactSyncRevision:(NSInteger)revision withDelegate:(id)delegate;
+
+/**
+ * Fetches the users contact list given a local revision ID.
+ * @param contactsync A dictionary of a users local contact list with a local revision ID.
+ * @param delegate An object containing the methods to handle the request's response.
+ */
+- (BOOL)syncContactsRevision:(NSDictionary *)contactsync withDelegate:(id)delegate;
+
+/**
* Fetches the profile of the user using an asynchronous request.
* @param delegate An object containing the methods to handle the request's response.
*/
@@ -55,14 +83,14 @@
* @param documentType A document type such as 'text/plain'
* @param delegate An object containing the methods to handle the request's response.
*/
-- (BOOL)fetchDataFromContent:(NSString *)documentContent andDocumentType:(NSString *)documentType withDelegate:(id)delegate;
+- (BOOL)fetchPlacesFromContent:(NSString *)documentContent andDocumentType:(NSString *)documentType withDelegate:(id)delegate;
/**
* Fetches the structured location data for a given place name.
* @param location A place name or location string.
* @param delegate An object containing the methods to handle the request's response.
*/
-- (BOOL)fetchDataForGeoLocation:(NSString *)location withDelegate:(id)delegate;
+- (BOOL)fetchPlaceForLocation:(NSString *)location withDelegate:(id)delegate;
/**
* Fetches the profiles of the user's connections using an asynchronous request.
View
118 Source/YOSSocial/YOSUserRequest.m
@@ -65,6 +65,120 @@ - (BOOL)fetchContactsWithStart:(NSInteger)start andCount:(NSInteger)count withDe
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];
+ NSURL *url = [NSURL URLWithString:requestUrl];
+
+ 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 = [self requestClient];
+ [client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
+ [client setRequestUrl:url];
+ [client setHTTPMethod:@"GET"];
+ [client setRequestParameters:requestParameters];
+ return [client sendAsyncRequestWithDelegate:delegate];
+}
+
+- (BOOL)addContact:(NSDictionary *)contact withDelegate:(id)delegate
+{
+ NSString *method = [NSString stringWithFormat:@"contacts"];
+ NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@", self.baseUrl, self.apiVersion, @"user", self.user.guid, method];
+ NSURL *url = [NSURL URLWithString:requestUrl];
+
+ NSMutableDictionary *requestParameters = [NSMutableDictionary dictionary];
+ [requestParameters setObject:self.format forKey:@"format"];
+ [requestParameters setObject:self.user.region forKey:@"region"];
+ [requestParameters setObject:self.user.language forKey:@"lang"];
+
+ NSMutableDictionary *contactData = [NSMutableDictionary dictionary];
+ [contactData setObject:contact forKey:@"contact"];
+
+ NSString *jsonContact = [self serializeDictionary:contactData];
+ NSData *contactHTTPBody = [jsonContact dataUsingEncoding:NSUTF8StringEncoding];
+
+ NSMutableDictionary *requestHeaders = [NSMutableDictionary dictionary];
+ [requestHeaders setObject:@"application/json" forKey:@"Content-Type"];
+
+ YOSRequestClient *client = [self requestClient];
+ [client setRequestUrl:url];
+ [client setHTTPMethod:@"POST"];
+ [client setHTTPBody:contactHTTPBody];
+ [client setRequestHeaders:requestHeaders];
+ [client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
+
+ YOSResponseData *response = [client sendSynchronousRequest];
+ NSInteger httpStatusCode = [response.HTTPURLResponse statusCode];
+
+ if(!response.data) {
+ return FALSE;
+ }
+
+ return (httpStatusCode == 200);
+}
+
+- (BOOL)fetchContactSyncRevision:(NSInteger)revision withDelegate:(id)delegate
+{
+ NSString *method = [NSString stringWithFormat:@"contacts"];
+ NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@", self.baseUrl, self.apiVersion, @"user", self.user.guid, method];
+ NSURL *url = [NSURL URLWithString:requestUrl];
+
+ NSMutableDictionary *requestParameters = [NSMutableDictionary dictionary];
+ [requestParameters setObject:@"sync" forKey:@"view"];
+ [requestParameters setObject:[NSString stringWithFormat:@"%d", revision] forKey:@"rev"];
+ [requestParameters setObject:self.format forKey:@"format"];
+ [requestParameters setObject:self.user.region forKey:@"region"];
+ [requestParameters setObject:self.user.language forKey:@"lang"];
+
+ YOSRequestClient *client = [self requestClient];
+ [client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
+ [client setRequestUrl:url];
+ [client setHTTPMethod:@"GET"];
+ [client setRequestParameters:requestParameters];
+ return [client sendAsyncRequestWithDelegate:delegate];
+}
+
+- (BOOL)syncContactsRevision:(NSDictionary *)contactsync withDelegate:(id)delegate
+{
+ NSString *method = [NSString stringWithFormat:@"contacts"];
+ NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@", self.baseUrl, self.apiVersion, @"user", self.user.guid, method];
+ NSURL *url = [NSURL URLWithString:requestUrl];
+
+ NSMutableDictionary *requestParameters = [NSMutableDictionary dictionary];
+ [requestParameters setObject:self.format forKey:@"format"];
+ [requestParameters setObject:self.user.region forKey:@"region"];
+ [requestParameters setObject:self.user.language forKey:@"lang"];
+
+ NSMutableDictionary *contactSyncData = [NSMutableDictionary dictionary];
+ [contactSyncData setObject:contactsync forKey:@"contactsync"];
+
+ NSString *jsonContactsync = [self serializeDictionary:contactSyncData];
+ NSData *contactsyncHTTPBody = [jsonContactsync dataUsingEncoding:NSUTF8StringEncoding];
+
+ NSMutableDictionary *requestHeaders = [NSMutableDictionary dictionary];
+ [requestHeaders setObject:@"application/json" forKey:@"Content-Type"];
+
+ YOSRequestClient *client = [self requestClient];
+ [client setRequestUrl:url];
+ [client setHTTPMethod:@"PUT"];
+ [client setHTTPBody:contactsyncHTTPBody];
+ [client setRequestHeaders:requestHeaders];
+ [client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
+
+ YOSResponseData *response = [client sendSynchronousRequest];
+ NSInteger httpStatusCode = [response.HTTPURLResponse statusCode];
+
+ if(!response.data) {
+ return FALSE;
+ }
+
+ return (httpStatusCode == 200);
+}
+
- (BOOL)fetchProfileWithDelegate:(id)delegate
{
NSString *method = [NSString stringWithFormat:@"profile"];
@@ -96,14 +210,14 @@ - (BOOL)fetchConnectionProfilesWithStart:(NSInteger)start andCount:(NSInteger)co
return [self query:[NSString stringWithFormat:@"select * from social.profile where guid in (%@)", queryJoin] withDelegate:delegate];
}
-- (BOOL)fetchDataFromContent:(NSString *)documentContent andDocumentType:(NSString *)documentType withDelegate:(id)delegate
+- (BOOL)fetchPlacesFromContent:(NSString *)documentContent andDocumentType:(NSString *)documentType withDelegate:(id)delegate
{
documentContent = (documentContent) ? documentContent : @"text/plain";
return [self query:[NSString stringWithFormat:@"select * from geo.placemaker where documentContent=\"%@\" and documentType=\"%@\"", documentContent, documentType]
withDelegate:delegate];
}
-- (BOOL)fetchDataForGeoLocation:(NSString *)location withDelegate:(id)delegate
+- (BOOL)fetchPlaceForLocation:(NSString *)location withDelegate:(id)delegate
{
return [self query:[NSString stringWithFormat:@"select * from geo.places where text=\"%@\"", location] withDelegate:delegate];
}

0 comments on commit c849201

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