|
#pragma mark - Service |
|
|
|
+ (BOOL) isLocalHost { |
|
return kLocalHostTesting; |
|
} |
|
|
|
|
|
+ (GTLServiceGraderecorder*) getService { |
|
if (__graderecorderService == nil) { |
|
__graderecorderService = [[GTLServiceGraderecorder alloc] init]; |
|
if (kLocalHostTesting) { |
|
__graderecorderService.rpcURL = [NSURL URLWithString:kLocalHostUrl]; |
|
__graderecorderService.fetcherService.allowLocalhostRequest = YES; // NEW!!! (added since video was made) |
|
} |
|
__graderecorderService.retryEnabled = YES; |
|
[GTMHTTPFetcher setLoggingEnabled:YES]; |
|
} |
|
return __graderecorderService; |
|
} |
|
|
|
|
|
#pragma mark - Authorizer |
|
|
|
+ (BOOL) hasAuthorizer { |
|
return [RHOAuthUtils _getAuthorizer] != nil; // Very important to use the _getAuthorizer function. |
|
} |
|
|
|
|
|
// Returns the current authorizer if available, otherwise attempt to return the saved authorizer. |
|
+ (GTMOAuth2Authentication*) _getAuthorizer { |
|
if (__authorizer == nil) { |
|
GTMOAuth2Authentication* savedAuthorizer; |
|
savedAuthorizer = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName |
|
clientID:kIosClientID |
|
clientSecret:kIosClientSecret]; |
|
if (savedAuthorizer.canAuthorize && savedAuthorizer.userEmail != nil) { |
|
NSLog(@"Using a saved authorizer"); |
|
[RHOAuthUtils _setAuthorizer:savedAuthorizer]; |
|
} |
|
} |
|
__authorizer.authorizationTokenKey = @"id_token"; |
|
if (kLocalHostTesting) { |
|
NSLog(@"Authorizing all requests."); |
|
__authorizer.shouldAuthorizeAllRequests = YES; |
|
} |
|
return __authorizer; |
|
} |
|
|
|
|
|
// Set the authorizer and link the authorizer to the service. |
|
+ (void) _setAuthorizer:(GTMOAuth2Authentication*) authorizer { |
|
if (authorizer != nil) { |
|
NSAssert(authorizer.userEmail != nil, @"Authorizer has no user email"); |
|
NSAssert(authorizer.canAuthorize, @"Authorizer can't authorize"); |
|
} |
|
__authorizer = authorizer; |
|
[RHOAuthUtils getService].authorizer = [RHOAuthUtils _getAuthorizer]; |
|
} |