Permalink
Browse files

* RSNetflixEngine now supports all 3 types of requests, unsigned, sig…

…ned and protected!

* Added retrieveUserInformationForUserId: to RSNetflixEngine, as proof of work
* The current flow of the "test" app is:

1) Request an oAuthToken (oauth/request_token)
2) Make the user sign in to Netflix
3) Request the access token (oauth/access_token)
4) Make a protected request (users/user_id)

Unfortunately you don't see much, so you'll have to breakpoint the code to see it working (or check your Console)
  • Loading branch information...
1 parent ed45405 commit 6d74f45c5803616705b9f4927674dd688fd9b69e @rsattar committed Nov 26, 2011
Showing with 61 additions and 0 deletions.
  1. +6 −0 RSNetflixEngine.h
  2. +48 −0 RSNetflixEngine.m
  3. +7 −0 RSNetflixEngine/RSNetflixEngineAppDelegate.m
View
@@ -23,6 +23,7 @@
- (void)netflixEngine:(RSNetflixEngine *)engine oAuthTokenRequestSucceededWithLoginUrlString:(NSString *)loginUrl forRequestId:(NSString *)requestId;
- (void)netflixEngine:(RSNetflixEngine *)engine oAuthTokenAccessSucceededForRequestId:(NSString *)requestId;
+- (void)netflixEngine:(RSNetflixEngine *)engine userInformationRetrieved:(NSDictionary *)information forRequestId:(NSString *)requestId;
@end
@@ -45,13 +46,18 @@
- (id)initWithAPIContext:(RSNetflixAPIContext *)inAPIContext;
+#pragma mark - Protected Requests (requires subsciber-granted access)
// Methods for making Protected (subscriber granted access) calls
- (NSString *)requestOAuthToken;
- (NSString *)requestOAuthTokenWithSuccessBlock:(void (^)(NSString *))successBlock errorBlock:(void (^)(NSError *))errorBlock;
- (NSString *)accessOAuthToken;
- (NSString *)accessOAuthTokenWithSuccessBlock:(void (^)(void))successBlock errorBlock:(void (^)(NSError *))errorBlock;
+- (NSString *)retrieveUserInformationForUserId:(NSString *)userId;
+- (NSString *)retrieveUserInformationForUserId:(NSString *)userId withSuccessBlock:(void (^)(NSDictionary *))successBlock errorBlock:(void (^)(NSError *))errorBlock;
+
+#pragma mark - Signed Requests
- (NSString *)searchForTitlesMatchingTerm:(NSString*)term;
- (NSString *)searchForTitlesMatchingTerm:(NSString*)term withMaxResults:(NSInteger)maxResults andPageOffset:(NSInteger)pageOffset;
View
@@ -186,6 +186,54 @@ - (NSString *)accessOAuthTokenWithSuccessBlock:(void (^)(void))successBlock erro
}];
}
+
+- (NSString *)retrieveUserInformationForUserId:(NSString *)userId
+{
+ return [self retrieveUserInformationForUserId:userId withSuccessBlock:nil errorBlock:nil];
+}
+
+- (NSString *)retrieveUserInformationForUserId:(NSString *)userId withSuccessBlock:(void (^)(NSDictionary *))successBlock errorBlock:(void (^)(NSError *))errorBlock
+{
+ RSNetflixAPIRequest *request = [[[RSNetflixAPIRequest alloc] initWithAPIContext:apiContext] autorelease];
+ // Even though we're using blocks, we still make ourselves a delegate of this request, so that
+ // we have a singular place we can account for active requests
+ request.delegate = self;
+
+ [self addRequest:request];
+
+ return [request callAPIMethod:[NSString stringWithFormat:@"users/%@",userId]
+ arguments:nil
+ isSigned:YES
+ withSuccessBlock:^(NSDictionary *response) {
+ NSLog(@"retrieveUserInformationForUserId completed in RSNetflixEngine with response: \n%@", response);
+
+ if([response objectForKey:@"error"] == nil) {
+ // we got no error!
+
+ // Now request specific
+ if([self isValidDelegateForSelector:@selector(netflixEngine:userInformationRetrieved:forRequestId:)]) {
+ [delegate netflixEngine:self userInformationRetrieved:response forRequestId:request.identifier];
+ }
+
+ if(successBlock) {
+ successBlock(response);
+ }
+
+ } else {
+ NSLog(@"Got a error response from the server: %@",response);
+ }
+
+ }
+ errorBlock:^(NSError *error) {
+ NSLog(@"retrieveUserInformationForUserId failed in RSNetflixEngine!");
+
+ if(errorBlock) {
+ errorBlock(error);
+ }
+
+ }];
+}
+
#pragma mark -
#pragma mark Catalog methods
@@ -159,6 +159,13 @@ - (void)netflixEngine:(RSNetflixEngine *)engine oAuthTokenRequestSucceededWithLo
[self.navigationController presentModalViewController:loginViewController animated:YES];
}
+- (void)netflixEngine:(RSNetflixEngine *)engine oAuthTokenAccessSucceededForRequestId:(NSString *)requestId
+{
+ // Make a access-only request, like users/user_id
+ [netflix retrieveUserInformationForUserId:netflix.apiContext.userId];
+
+}
+
#pragma - RSUserLoginViewControllerDelegate
- (void)userLoginViewControllerSucceeded:(RSUserLoginViewController *)viewController withResponse:(NSDictionary *)loginResponse {

0 comments on commit 6d74f45

Please sign in to comment.