Permalink
Browse files

adding experimental opensocial component

  • Loading branch information...
1 parent 10c5c38 commit 9f2ded71265df9590b075e6ff3286ce453580271 @zagraves zagraves committed Sep 16, 2009
Showing with 163 additions and 0 deletions.
  1. +63 −0 Source/YOSSocial/YOSOpenSocialRequest.h
  2. +100 −0 Source/YOSSocial/YOSOpenSocialRequest.m
@@ -0,0 +1,63 @@
+//
+// YOSOpenSocialRequest.h
+// YahooSocialSdk
+//
+// Created by Zach Graves on 9/2/09.
+// Copyright 2009 Yahoo! Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "YOSBaseRequest.h"
+
+/**
+ * Experimental OpenSocial request class.
+ */
+@interface YOSOpenSocialRequest : YOSBaseRequest {
+
+}
+
+/**
+ * Fetches an OpenSocial data source.
+ * @param relativeUrl The relative opensocial url.
+ * @param params A dictionary of parameters to be included in the request.
+ * @param delegate An object containing the methods to handle the request's response.
+ */
+- (BOOL) getDataForUrl:(NSString *)relativeUrl andParameters:(NSMutableDictionary *)params delegate:(id)delegate;
+
+/**
+ * Retrieves a users collection of connections.
+ * @param guid The GUID of the user.
+ * @param delegate An object containing the methods to handle the request's response.
+ */
+- (BOOL) fetchConnectionsForUser:(NSString *)guid delegate:(id)delegate;
+
+/**
+ * Retrieves a users profile.
+ * @param guid The GUID of the user.
+ * @param delegate An object containing the methods to handle the request's response.
+ */
+- (BOOL) fetchProfileForUser:(NSString *)guid delegate:(id)delegate;
+
+/**
+ * Retrieves a collection of user activities.
+ * @param guid The GUID of the user.
+ * @param delegate An object containing the methods to handle the request's response.
+ */
+- (BOOL) fetchActivitiesForUser:(NSString *)guid delegate:(id)delegate;
+
+/**
+ * Retrieves a collection of user activities from an application.
+ * @param guid The GUID of the user.
+ * @param delegate An object containing the methods to handle the request's response.
+ */
+- (BOOL) fetchApplicationActivitiesForUser:(NSString *)guid delegate:(id)delegate;
+
+/**
+ * Retrieves a single user activity from an application.
+ * @param guid The GUID of the user.
+ * @param activityID An activity indentifier.
+ * @param delegate An object containing the methods to handle the request's response.
+ */
+- (BOOL) fetchApplicationActivityForUser:(NSString *)guid andActivityId:(NSString *)activityID delegate:(id)delegate;
+
+@end
@@ -0,0 +1,100 @@
+//
+// YOSOpenSocialRequest.m
+// YahooSocialSdk
+//
+// Created by Zach Graves on 9/2/09.
+// Copyright 2009 Yahoo! Inc. All rights reserved.
+//
+
+#import "YOSOpenSocialRequest.h"
+#import "YOSRequestClient.h"
+
+static NSString *const kOpenSocialBaseUrl = @"http://appstore.apps.yahooapis.com/social/rest";
+
+@implementation YOSOpenSocialRequest
+
++ (id)requestWithSession:(YOSSession *)session
+{
+ YOSUser *sessionedUser = [[YOSUser alloc] initWithSession:session];
+ YOSOpenSocialRequest *request = [[YOSOpenSocialRequest alloc] initWithYOSUser:sessionedUser];
+
+ [sessionedUser autorelease];
+ [request autorelease];
+
+ [request setBaseUrl:kOpenSocialBaseUrl];
+
+ return request;
+}
+
+- (BOOL)getDataForUrl:(NSString *)relativeUrl andParameters:(NSMutableDictionary *)params delegate:(id)aDelegate
+{
+ NSString *dataUrl = [self.baseUrl stringByAppendingString:relativeUrl];
+ NSURL *url = [NSURL URLWithString:dataUrl];
+
+ YOSRequestClient *client = [self requestClient];
+
+ [client setRequestUrl:url];
+ [client setRequestParameters:params];
+ [client setHTTPMethod:@"GET"];
+ [client setOauthParamsLocation:@"OAUTH_PARAMS_IN_QUERY_STRING"];
+
+ return [client sendAsyncRequestWithDelegate:aDelegate];
+}
+
+- (BOOL) fetchConnectionsForUser:(NSString *)guid delegate:(id)delegate
+{
+ if(!guid) guid = @"@me";
+
+ NSMutableDictionary *requestParameters = [NSMutableDictionary dictionary];
+ [requestParameters setValue:@"100" forKey:@"count"];
+
+ return [self getDataForUrl:[NSString stringWithFormat:@"/people/%@/@friends", guid]
+ andParameters:requestParameters
+ delegate:delegate];
+}
+
+- (BOOL) fetchProfileForUser:(NSString *)guid delegate:(id)delegate
+{
+ if(!guid) guid = @"@me";
+
+ NSMutableDictionary *requestParameters = [NSMutableDictionary dictionary];
+ [requestParameters setObject:@"displayName" forKey:@"fields"];
+
+ return [self getDataForUrl:[NSString stringWithFormat:@"/people/%@/@self", guid]
+ andParameters:requestParameters
+ delegate:delegate];
+}
+
+- (BOOL) fetchActivitiesForUser:(NSString *)guid delegate:(id)delegate
+{
+ if(!guid) guid = @"@me";
+
+ NSMutableDictionary *requestParameters = [NSMutableDictionary dictionary];
+ [requestParameters setObject:@"100" forKey:@"count"];
+
+ return [self getDataForUrl:[NSString stringWithFormat:@"/activities/%@/@self", guid]
+ andParameters:requestParameters
+ delegate:delegate];
+}
+
+- (BOOL) fetchApplicationActivitiesForUser:(NSString *)guid delegate:(id)delegate
+{
+ YOSSession *session = user.session;
+
+ return [self getDataForUrl:[NSString stringWithFormat:@"/activities/%@/@self/%@", guid, session.applicationId]
+ andParameters:nil
+ delegate:delegate];
+}
+
+- (BOOL) fetchApplicationActivityForUser:(NSString *)guid andActivityId:(NSString *)activityID delegate:(id)delegate
+{
+ if(!guid) guid = @"@me";
+
+ YOSSession *session = user.session;
+
+ return [self getDataForUrl:[NSString stringWithFormat:@"/activities/%@/@self/%@/%@", guid, session.applicationId, activityID]
+ andParameters:nil
+ delegate:delegate];
+}
+
+@end

0 comments on commit 9f2ded7

Please sign in to comment.