From 977ad77da8fdf485f33ed06ef7cae29b8e8d2c9a Mon Sep 17 00:00:00 2001 From: Ben Stovold Date: Fri, 5 Oct 2012 15:39:59 +1000 Subject: [PATCH] Added happy path notifications for key discovery and auth events --- TPTentClient/TPTentClient.h | 17 +++++++++++---- TPTentClient/TPTentClient.m | 41 +++++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/TPTentClient/TPTentClient.h b/TPTentClient/TPTentClient.h index cd968c3..63d4b3f 100644 --- a/TPTentClient/TPTentClient.h +++ b/TPTentClient/TPTentClient.h @@ -72,10 +72,19 @@ extern NSString * const TPTentClientPostTypeProfileModification; extern NSString * const TPTentClientPostTypeDeleteNotification; // Notifications and UserInfo dict keys -extern NSString * const TPTentClientDidRegisterWithEntityNotification; -extern NSString * const TPTentClientDidRegisterWithEntityNotificationURLKey; +extern NSString * const TPTentServerDiscoveryCheckingHeadResponseForProfileLinkNotification; +extern NSString * const TPTentServerDiscoveryFellBackToGetResponseForProfileLinkNotification; +extern NSString * const TPTentServerDiscoveryFetchingCanonicalURLsFromProfileNotification; +extern NSString * const TPTentServerDiscoveryCompleteNotification; +extern NSString * const TPTentServerDiscoveryCompleteNotificationCanonicalServerURLKey; +extern NSString * const TPTentServerDiscoveryCompleteNotificationCanonicalEntityURLKey; +extern NSString * const TPTentClientWillAuthorizeWithTentServerNotification; +extern NSString * const TPTentClientDidAuthorizeWithTentServerNotification; +extern NSString * const TPTentClientAuthorizingWithTentServerURLKey; @protocol TPTentClientDelegate @optional -- (void)tentClient:(TPTentClient *)tentClient didAuthorizeWithTentServerURL:(NSURL *)url; -@end \ No newline at end of file +// TODO: notes and delegate calls should map one-to-one +- (void)tentClient:(TPTentClient *)tentClient didAuthorizeWithTentServerURL:(NSURL *)canonicalServerURL; +@end + diff --git a/TPTentClient/TPTentClient.m b/TPTentClient/TPTentClient.m index 4373800..5a2826e 100644 --- a/TPTentClient/TPTentClient.m +++ b/TPTentClient/TPTentClient.m @@ -29,6 +29,7 @@ #pragma mark - Constants +#pragma mark Post Types NSString * const TPTentClientPostTypeStatus = @"https://tent.io/types/post/status/v0.1.0"; NSString * const TPTentClientPostTypeEssay = @"https://tent.io/types/post/essay/v0.1.0"; NSString * const TPTentClientPostTypePhoto = @"https://tent.io/types/post/photo/v0.1.0"; @@ -37,13 +38,21 @@ NSString * const TPTentClientPostTypeProfileModification = @"https://tent.io/types/post/profile/v0.1.0"; NSString * const TPTentClientPostTypeDeleteNotification = @"https://tent.io/types/post/delete/v0.1.0"; +#pragma mark Notifications +NSString * const TPTentServerDiscoveryCheckingHeadResponseForProfileLinkNotification = @"com.thoughtfulpixel.tptentclient.note.discovery.headprofile"; +NSString * const TPTentServerDiscoveryFellBackToGetResponseForProfileLinkNotification = @"com.thoughtfulpixel.tptentclient.note.discovery.getprofile"; +NSString * const TPTentServerDiscoveryFetchingCanonicalURLsFromProfileNotification = @"com.thoughtfulpixel.tptentclient.note.discovery.locateservers"; +NSString * const TPTentServerDiscoveryCompleteNotification = @"com.thoughtfulpixel.tptentclient.note.discovery.complete"; +NSString * const TPTentServerDiscoveryCompleteNotificationCanonicalServerURLKey = @"TPTentClientCanonicalServerURLKey"; +NSString * const TPTentServerDiscoveryCompleteNotificationCanonicalEntityURLKey = @"TPTentClientCanonicalEntityURLKey"; +NSString * const TPTentClientWillAuthorizeWithTentServerNotification = @"com.thoughtfulpixel.tptentclient.note.authorization.willauthorise"; +NSString * const TPTentClientDidAuthorizeWithTentServerNotification = @"com.thoughtfulpixel.tptentclient.note.authorization.didauthorise"; +NSString * const TPTentClientAuthorizingWithTentServerURLKey = @"TPTentClientServerURLKey"; + +#pragma mark Private static NSString * const TPTentClientProfileInfoTypeCore = @"https://tent.io/types/info/core/v0.1.0"; static NSString * const TPTentClientProfileInfoTypeBasic = @"https://tent.io/types/info/basic/v0.1.0"; -NSString * const TPTentClientDidRegisterWithEntityNotification = @"com.thoughtfulpixel.tptentclient.notification.didregisterwithentity"; -NSString * const TPTentClientDidRegisterWithEntityNotificationURLKey = @"TPTentClientDidRegisterWithEntityURL"; - - #pragma mark @@ -97,6 +106,10 @@ - (void)authorizeForTentServerURL:(NSURL *)url self.httpClient.delegate = self; } + [[NSNotificationCenter defaultCenter] postNotificationName:TPTentClientWillAuthorizeWithTentServerNotification + object:nil + userInfo:@{TPTentClientAuthorizingWithTentServerURLKey: url}]; + [self.httpClient registerForBaseURLWithSuccess:success failure:failure]; } @@ -174,9 +187,9 @@ - (void)postPostWithType:(NSString *)postType permissions:(NSDictionary *)permis - (void)httpClientDidRegisterWithBaseURL:(TPTentHTTPClient *)httpClient { - [[NSNotificationCenter defaultCenter] postNotificationName:TPTentClientDidRegisterWithEntityNotification + [[NSNotificationCenter defaultCenter] postNotificationName:TPTentClientDidAuthorizeWithTentServerNotification object:nil - userInfo:@{TPTentClientDidRegisterWithEntityNotification: httpClient.baseURL}]; + userInfo:@{TPTentClientAuthorizingWithTentServerURLKey: httpClient.baseURL}]; if ([self.delegate respondsToSelector:@selector(tentClient:didAuthorizeWithTentServerURL:)]) { [self.delegate tentClient:self didAuthorizeWithTentServerURL:httpClient.baseURL]; @@ -191,6 +204,10 @@ - (void)headTentServerWithDiscoveryHTTPClient:(AFHTTPClient *)discoveryHTTPClien success:(void (^)(NSURL *canonicalServerURL, NSURL *canonicalEntityURL))success failure:(void (^)(NSError *error))failure { + [[NSNotificationCenter defaultCenter] postNotificationName:TPTentServerDiscoveryCheckingHeadResponseForProfileLinkNotification + object:nil + userInfo:nil]; + NSMutableURLRequest *headRequest = [discoveryHTTPClient requestWithMethod:@"HEAD" path:@"/" parameters:nil]; AFHTTPRequestOperation *headOperation = [[AFHTTPRequestOperation alloc] initWithRequest:headRequest]; @@ -253,6 +270,10 @@ - (void)getTentServerWithDiscoveryHTTPClient:(AFHTTPClient *)discoveryHTTPClient success:(void (^)(NSURL *canonicalServerURL, NSURL *canonicalEntityURL))success failure:(void (^)(NSError *error))failure { + [[NSNotificationCenter defaultCenter] postNotificationName:TPTentServerDiscoveryFellBackToGetResponseForProfileLinkNotification + object:nil + userInfo:nil]; + [discoveryHTTPClient getPath:@"/" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSURL *profileURL = [self profileURLFromCompletedGetOperation:operation responseString:[[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]]; @@ -323,6 +344,10 @@ - (void)getCanonicalURLsFromProfileURL:(NSURL *)url success:(void (^)(NSURL *canonicalServerURL, NSURL *canonicalEntityURL))success failure:(void (^)(NSError *error))failure { + [[NSNotificationCenter defaultCenter] postNotificationName:TPTentServerDiscoveryFetchingCanonicalURLsFromProfileNotification + object:nil + userInfo:nil]; + AFHTTPClient *aHTTPClient = [[TPTentHTTPClient alloc] initWithBaseURL:url]; NSMutableURLRequest *getRequest = [aHTTPClient requestWithMethod:@"GET" path:[NSString string] parameters:nil]; @@ -347,6 +372,10 @@ - (void)getCanonicalURLsFromProfileURL:(NSURL *)url return; } + [[NSNotificationCenter defaultCenter] postNotificationName:TPTentServerDiscoveryCompleteNotification + object:nil + userInfo:@{TPTentServerDiscoveryCompleteNotificationCanonicalServerURLKey: tentServerURL, + TPTentServerDiscoveryCompleteNotificationCanonicalEntityURLKey: tentEntityURL}]; if (success) { success(tentServerURL, tentEntityURL); }