diff --git a/plugin.xml b/plugin.xml index f4507ce..9a99e6a 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,7 +1,7 @@ + version="1.0.0"> ServerComm Abstraction for communication settings, and for making both GET diff --git a/src/ios/BEMCommunicationHelper.h b/src/ios/BEMCommunicationHelper.h index 16e8430..e8dba88 100644 --- a/src/ios/BEMCommunicationHelper.h +++ b/src/ios/BEMCommunicationHelper.h @@ -7,7 +7,7 @@ // #import -#import "GTMSessionFetcherService.h" +#import @interface CommunicationHelper : NSObject // Wrappers for our specific functionality diff --git a/src/ios/BEMCommunicationHelper.m b/src/ios/BEMCommunicationHelper.m index 1659e35..99b04b1 100644 --- a/src/ios/BEMCommunicationHelper.m +++ b/src/ios/BEMCommunicationHelper.m @@ -10,11 +10,11 @@ // #import "BEMCommunicationHelper.h" -#import "AuthCompletionHandler.h" #import "BEMConnectionSettings.h" #import "BEMConstants.h" #import "LocalNotificationManager.h" -#import "GTMSessionFetcher.h" +#import +#import "AuthCompletionHandler.h" // This is the base URL // We need to append the username to it, and then we need to authenticate the user as well @@ -34,10 +34,6 @@ return aBool? @"YES" : @"NO"; } -@interface CommunicationHelper() { -} -@end - @implementation CommunicationHelper +(void)getCustomSettings:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler { @@ -143,18 +139,17 @@ -(void)execute { return; } - [[AuthCompletionHandler sharedInstance] getValidAuth:^(GTMOAuth2Authentication *auth,NSError* error) { + [[AuthCompletionHandler sharedInstance] getValidAuth:^(GIDGoogleUser *user,NSError* error) { if (error != NULL) { self.mCompletionHandler(jsonData, NULL, error); } else { - // TODO: have postToHost take the auth token as input instead of re-reading it - [self postToHost]; + [self postToHost:user.authentication.idToken]; } - } forceRefresh:FALSE]; + }]; } -- (void)postToHost { +- (void)postToHost:(NSString*)idToken { [LocalNotificationManager addNotification:[NSString stringWithFormat: @"postToHost called with url = %@", self.mUrl] showUI:FALSE]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] @@ -164,7 +159,7 @@ - (void)postToHost { [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; - NSString *userToken = [AuthCompletionHandler sharedInstance].getIdToken; + NSString *userToken = idToken; // At this point, we assume that all the authentication is done correctly // Should I try to verify making a remote call or add that to a debug screen? [self.mJsonDict setObject:userToken forKey:@"user"]; @@ -204,39 +199,4 @@ - (void)postToHost { } } -- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error usingController:(UIViewController *)viewController { - NSLog(@"CommunicationHelper.finishedWithAuth called with auth = %@ and error = %@", auth, error); - if (error != NULL) { - NSLog(@"Got error %@ while authenticating", error); - self.mCompletionHandler(NULL, NULL, error); - // modify some kind of error count and notify that user needs to sign in again - } else { - [[AuthCompletionHandler sharedInstance] unregisterFinishDelegate:self]; - [self postToHost]; - } -} - -- (void)finishRefreshSelector:(GTMOAuth2Authentication *)auth - request:(NSMutableURLRequest *)request - finishedWithError:(NSError *)error { - [LocalNotificationManager addNotification:[NSString stringWithFormat: - @"CommunicationHelper.finishRefreshSelector called with auth = %@, request = %@, error = %@", auth, request, error] showUI:FALSE]; - - if (error != NULL) { - self.mCompletionHandler(NULL, NULL, error); - } else { - BOOL stillExpired = ([auth.expirationDate compare:[NSDate date]] == NSOrderedAscending); - if (stillExpired) { - [LocalNotificationManager addNotification:[NSString stringWithFormat: - @"No more methods to try, I GIVE UP!"] showUI:TRUE]; - } else { - // Check to see whether the sharedInstance auth token has been updated - [LocalNotificationManager addNotification:[NSString stringWithFormat: - @"Auth token in the shared instance is %@, posting to host", [AuthCompletionHandler sharedInstance].currAuth] showUI:FALSE]; - [self postToHost]; - } - } - -} - @end