Permalink
Browse files

added geo methods

  • Loading branch information...
1 parent 5ac4a02 commit 81c8c369f0aad8eccd6d04d7ed884a62bcfb772b @zagraves zagraves committed Sep 24, 2009
Showing with 84 additions and 39 deletions.
  1. +34 −8 Source/YOSSocial/YOSUserRequest.h
  2. +50 −31 Source/YOSSocial/YOSUserRequest.m
@@ -27,60 +27,81 @@
* @param count An integer specifying the number of connections returned.
* @param delegate An object containing the methods to handle the request's response.
*/
-- (void)fetchConnectionsWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate;
+- (BOOL)fetchConnectionsWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate;
/**
* Fetches the user's contacts using an asynchronous request.
* @param start An integer specifying the index of the first contact returned.
* @param count An integer specifying the number of contacts returned.
* @param delegate An object containing the methods to handle the request's response.
*/
-- (void)fetchContactsWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate;
+- (BOOL)fetchContactsWithStart:(NSInteger)start andCount:(NSInteger)count 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.
*/
-- (void)fetchProfileWithDelegate:(id)delegate;
+- (BOOL)fetchProfileWithDelegate:(id)delegate;
+
+/**
+ * Fetches the location of the user from their profile using an asynchronous request.
+ * @param delegate An object containing the methods to handle the request's response.
+ */
+- (BOOL)fetchProfileLocationWithDelegate:(id)delegate;
+
+/**
+ * Fetches probable locations from the content of a document.
+ * @param documentContent A string of text.
+ * @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;
+
+/**
+ * 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;
/**
* 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.
* @param delegate An object containing the methods to handle the request's response.
*/
-- (void)fetchConnectionProfilesWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate;
+- (BOOL)fetchConnectionProfilesWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate;
/**
* Fetches the current status messages 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.
* @param delegate An object containing the methods to handle the request's response.
*/
-- (void)fetchConnectionsStatusWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate;
+- (BOOL)fetchConnectionsStatusWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate;
/**
* Fetches the updates for the user using an asynchronous request.
* @param start An integer specifying the index of the first update returned.
* @param count An integer specifying the number of updates returned.
* @param delegate An object containing the methods to handle the request's response.
*/
-- (void)fetchUpdatesWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate;
+- (BOOL)fetchUpdatesWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate;
/**
* Fetches the updates for the user's connections using an asynchronous request.
* @param start An integer specifying the index of the first update returned.
* @param count An integer specifying the number of updates returned.
* @param delegate An object containing the methods to handle the request's response.
*/
-- (void)fetchConnectionUpdatesWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate;
+- (BOOL)fetchConnectionUpdatesWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate;
/**
* Fetches the current status message for the user using an asynchronous request.
* @return YOSResponseData An object containing the response data and any errors encountered.
* @param delegate An object containing the methods to handle the request's response.
*/
-- (void)fetchStatusWithDelegate:(id)delegate;
+- (BOOL)fetchStatusWithDelegate:(id)delegate;
/**
* Sets the user's status message using a synchronous request.
@@ -119,6 +140,11 @@
- (BOOL)setSmallViewWithContents:(NSString *)content;
/**
+ * Foo
+ */
+- (BOOL)query:(NSString *)aQuery withDelegate:(id)delegate;
+
+/**
* Creates a unique string (SUID) usable for inserting an update.
* @return A string containing a unique ID.
*/
@@ -23,7 +23,7 @@ + (id)requestWithSession:(YOSSession *)session
return request;
}
-- (void)fetchConnectionsWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
+- (BOOL)fetchConnectionsWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
{
NSString *method = [NSString stringWithFormat:@"connections"];
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@", self.baseUrl, self.apiVersion, @"user", self.user.guid, method];
@@ -41,10 +41,10 @@ - (void)fetchConnectionsWithStart:(NSInteger)start andCount:(NSInteger)count wit
[client setRequestUrl:url];
[client setHTTPMethod:@"GET"];
[client setRequestParameters:requestParameters];
- [client sendAsyncRequestWithDelegate:delegate];
+ return [client sendAsyncRequestWithDelegate:delegate];
}
-- (void)fetchContactsWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
+- (BOOL)fetchContactsWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
{
NSString *method = [NSString stringWithFormat:@"contacts"];
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@", self.baseUrl, self.apiVersion, @"user", self.user.guid, method];
@@ -62,10 +62,10 @@ - (void)fetchContactsWithStart:(NSInteger)start andCount:(NSInteger)count withDe
[client setRequestUrl:url];
[client setHTTPMethod:@"GET"];
[client setRequestParameters:requestParameters];
- [client sendAsyncRequestWithDelegate:delegate];
+ return [client sendAsyncRequestWithDelegate:delegate];
}
-- (void)fetchProfileWithDelegate:(id)delegate
+- (BOOL)fetchProfileWithDelegate:(id)delegate
{
NSString *method = [NSString stringWithFormat:@"profile"];
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@", self.baseUrl, self.apiVersion, @"user", self.user.guid, method];
@@ -81,21 +81,41 @@ - (void)fetchProfileWithDelegate:(id)delegate
[client setRequestUrl:url];
[client setHTTPMethod:@"GET"];
[client setRequestParameters:requestParameters];
- [client sendAsyncRequestWithDelegate:delegate];
+ return [client sendAsyncRequestWithDelegate:delegate];
}
-- (void)fetchConnectionProfilesWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
-{
- YQLQueryRequest *yqlRequest = [[YQLQueryRequest alloc] initWithYOSUser:[self user]];
-
+- (BOOL)fetchProfileLocationWithDelegate:(id)delegate
+{
+ NSString *queryJoin = [NSString stringWithFormat:@"select location from social.profile where guid=\"%@\"", user.guid];
+ return [self query:[NSString stringWithFormat:@"select * from geo.places where text in (%@)", queryJoin] withDelegate:delegate];
+}
+
+- (BOOL)fetchConnectionProfilesWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
+{
NSString *queryJoin = [NSString stringWithFormat:@"select guid from social.connections(%d,%d) where owner_guid=\"%@\"", start, count, user.guid];
- NSString *yqlQuery = [NSString stringWithFormat:@"select * from social.profile where guid in (%@)", queryJoin];
-
- [yqlRequest query:yqlQuery withDelegate:delegate];
- [yqlRequest release];
+ 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
+{
+ 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
+{
+ return [self query:[NSString stringWithFormat:@"select * from geo.places where text=\"%@\"", location] withDelegate:delegate];
+}
+
+- (BOOL)fetchConnectionsStatusWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
+{
+ NSString *yqlJoin = [NSString stringWithFormat:@"select guid from social.connections(%d,%d) where owner_guid=\"%@\"", start, count, user.guid];
+ return [self query:[NSString stringWithFormat:@"select guid,status from social.profile where guid in (%@) | sort(field=\"status.lastStatusModified\") | reverse()", yqlJoin]
+ withDelegate:delegate];
}
-- (void)fetchStatusWithDelegate:(id)delegate
+- (BOOL)fetchStatusWithDelegate:(id)delegate
{
NSString *method = [NSString stringWithFormat:@"profile/status"];
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@",self.baseUrl,self.apiVersion,@"user",self.user.guid,method];
@@ -111,21 +131,10 @@ - (void)fetchStatusWithDelegate:(id)delegate
[client setRequestUrl:url];
[client setHTTPMethod:@"GET"];
[client setRequestParameters:requestParameters];
- [client sendAsyncRequestWithDelegate:delegate];
+ return [client sendAsyncRequestWithDelegate:delegate];
}
-- (void)fetchConnectionsStatusWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
-{
- YQLQueryRequest *yqlRequest = [[YQLQueryRequest alloc] initWithYOSUser:[self user]];
-
- NSString *yqlJoin = [NSString stringWithFormat:@"select guid from social.connections(%d,%d) where owner_guid=\"%@\"", start, count, user.guid];
- NSString *yqlQuery = [NSString stringWithFormat:@"select guid,status from social.profile where guid in (%@) | sort(field=\"status.lastStatusModified\") | reverse()", yqlJoin];
-
- [yqlRequest query:yqlQuery withDelegate:delegate];
- [yqlRequest release];
-}
-
-- (void)fetchUpdatesWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
+- (BOOL)fetchUpdatesWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
{
NSString *method = [NSString stringWithFormat:@"updates"];
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@", self.baseUrl, self.apiVersion, @"user", self.user.guid, method];
@@ -147,10 +156,10 @@ - (void)fetchUpdatesWithStart:(NSInteger)start andCount:(NSInteger)count withDel
[client setRequestUrl:url];
[client setHTTPMethod:@"GET"];
[client setRequestParameters:requestParameters];
- [client sendAsyncRequestWithDelegate:delegate];
+ return [client sendAsyncRequestWithDelegate:delegate];
}
-- (void)fetchConnectionUpdatesWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
+- (BOOL)fetchConnectionUpdatesWithStart:(NSInteger)start andCount:(NSInteger)count withDelegate:(id)delegate
{
NSString *method = [NSString stringWithFormat:@"updates/connections"];
NSString *requestUrl = [NSString stringWithFormat:@"%@/%@/%@/%@/%@", baseUrl, apiVersion, @"user", user.guid, method];
@@ -172,7 +181,7 @@ - (void)fetchConnectionUpdatesWithStart:(NSInteger)start andCount:(NSInteger)cou
[client setRequestUrl:url];
[client setHTTPMethod:@"GET"];
[client setRequestParameters:requestParameters];
- [client sendAsyncRequestWithDelegate:delegate];
+ return [client sendAsyncRequestWithDelegate:delegate];
}
- (BOOL)insertUpdateWithTitle:(NSString *)aTitle
@@ -340,6 +349,16 @@ - (BOOL)setSmallViewWithContents:(NSString *)content
return (httpStatusCode == 200);
}
+- (BOOL)query:(NSString *)aQuery withDelegate:(id)delegate
+{
+ YQLQueryRequest *yqlRequest = [[YQLQueryRequest alloc] initWithYOSUser:[self user]];
+
+ BOOL connectionWasCreated = [yqlRequest query:aQuery withDelegate:delegate];
+ [yqlRequest release];
+
+ return connectionWasCreated;
+}
+
- (NSString *)generateUniqueSuid
{
NSString *generatedSuid = nil;

0 comments on commit 81c8c36

Please sign in to comment.