Permalink
Browse files

add support for query.multi, use new requestClient getter

  • Loading branch information...
1 parent 4db5c7b commit 10c5c38cf2dd2189a121196595f0453f8e446447 @zagraves zagraves committed Sep 16, 2009
Showing with 40 additions and 21 deletions.
  1. +17 −4 Source/YOSSocial/YQLQueryRequest.h
  2. +23 −17 Source/YOSSocial/YQLQueryRequest.m
@@ -38,23 +38,36 @@
- (YOSRequestClient *)generateRequest:(NSString *)aQuery;
/**
- * Sends a select query request to YQL.
+ * Sends a select query request to YQL asynchronously.
* @param aQuery A YQL query.
* @param delegate An object containing the methods to handle the request's response.
*/
-- (void)query:(NSString *)aQuery withDelegate:(id)delegate;
+- (BOOL)query:(NSString *)aQuery withDelegate:(id)delegate;
/**
- * Sends a query request to YQL.
+ * Sends a query request to YQL synchronously.
* @param aQuery A YQL query.
*/
- (YOSResponseData *)query:(NSString *)aQuery;
/**
- * Sends a query request to YQL.
+ * Sends an UPDATE/DELETE or INSERT query request to YQL synchronously.
* @param aQuery A YQL query.
*/
- (BOOL)updateQuery:(NSString *)aQuery;
+/**
+ * Sends an UPDATE/DELETE or INSERT query request to YQL asynchronously.
+ * @param aQuery A YQL query.
+ * @param delegate An object containing the methods to handle the request's response.
+ */
+- (BOOL)updateQuery:(NSString *)aQuery withDelegate:(id)delegate;
+
+/**
+ * Joins stuff.
+ * @param queries An array of strings
+ */
+- (NSString *)queryByJoiningQueries:(NSArray *)queries;
+
@end
@@ -34,20 +34,19 @@ + (id)requestWithSession:(YOSSession *)session
#pragma mark -
#pragma mark Public
-- (void)query:(NSString *)aQuery withDelegate:(id)delegate
+- (BOOL)query:(NSString *)aQuery withDelegate:(id)delegate
{
YOSRequestClient *client = [self generateRequest:aQuery];
-
[client setHTTPMethod:@"GET"];
[client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
- [client sendAsyncRequestWithDelegate:delegate];
+
+ return [client sendAsyncRequestWithDelegate:delegate];
}
- (YOSResponseData *)query:(NSString *)aQuery
{
YOSRequestClient *client = [self generateRequest:aQuery];
-
[client setHTTPMethod:@"GET"];
[client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
@@ -60,20 +59,30 @@ - (YOSResponseData *)query:(NSString *)aQuery
return response;
}
+- (BOOL)updateQuery:(NSString *)aQuery withDelegate:(id)delegate
+{
+ YOSRequestClient *client = [self generateRequest:aQuery];
+ [client setHTTPMethod:@"PUT"];
+ [client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
+
+ return [client sendAsyncRequestWithDelegate:delegate];
+}
+
- (BOOL)updateQuery:(NSString *)aQuery
{
YOSRequestClient *client = [self generateRequest:aQuery];
-
[client setHTTPMethod:@"PUT"];
[client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
YOSResponseData *response = [client sendSynchronousRequest];
- if (!response.didSucceed) {
- return NO;
- }
-
- return YES;
+ return (response.didSucceed);
+}
+
+- (NSString *)queryByJoiningQueries:(NSArray *)queries
+{
+ NSString *joinedQueries = [[queries componentsJoinedByString:@";"] stringByReplacingOccurrencesOfString:@"\"" withString:@"'"];
+ return [NSString stringWithFormat:@"select * from query.multi where queries=\"%@\"", joinedQueries];
}
@@ -86,9 +95,8 @@ - (YOSRequestClient *)generateRequest:(NSString *)aQuery
// If a consumer is not available, we can assume public tables are being used
// and we'll use the public yql endpoint.
- NSString *requestUrl = ([self consumerForRequest] != nil)
- ? [NSString stringWithFormat:@"%@/%@/%@",kYQLBaseUrl,self.apiVersion,@"yql"]
- : [NSString stringWithFormat:@"%@/%@/%@/%@",kYQLBaseUrl,self.apiVersion,@"public",@"yql"];
+ NSString *requestUrl = ([self oauthConsumer]) ? [NSString stringWithFormat:@"%@/%@/%@", kYQLBaseUrl, self.apiVersion, @"yql"]
+ : [NSString stringWithFormat:@"%@/%@/%@/%@", kYQLBaseUrl, self.apiVersion, @"public", @"yql"];
NSURL *url = [NSURL URLWithString:requestUrl];
@@ -100,13 +108,11 @@ - (YOSRequestClient *)generateRequest:(NSString *)aQuery
[requestParameters setObject:useDiagnostics forKey:@"diagnostics"];
[requestParameters setObject:self.environmentFile forKey:@"env"];
- YOSRequestClient *client = [[YOSRequestClient alloc] initWithConsumer:[self consumerForRequest]
- andToken:[self tokenForRequest]];
-
+ YOSRequestClient *client = [self requestClient];
[client setRequestUrl:url];
[client setRequestParameters:requestParameters];
- return [client autorelease];
+ return client;
}
@end

0 comments on commit 10c5c38

Please sign in to comment.