From 6fe2696d476deb02ab0ca72099e537da61ce0a81 Mon Sep 17 00:00:00 2001 From: Brent Royal-Gordon Date: Thu, 25 Oct 2012 01:01:28 -0700 Subject: [PATCH] Note which requests require authentication --- ANAuthenticatedRequest.h | 6 +++++- ANAuthenticatedRequest.m | 13 ++++++++++--- ANPostRequest.m | 4 ++++ ANPostsInGlobalStreamRequest.m | 4 ++++ ANPostsWithTagRequest.m | 4 ++++ ANResource.h | 8 ++++---- 6 files changed, 31 insertions(+), 8 deletions(-) diff --git a/ANAuthenticatedRequest.h b/ANAuthenticatedRequest.h index 691b077..f2e8924 100644 --- a/ANAuthenticatedRequest.h +++ b/ANAuthenticatedRequest.h @@ -10,7 +10,11 @@ #import "ANRequest.h" -@interface ANAuthenticatedRequest : ANRequest @end +@interface ANAuthenticatedRequest : ANRequest + +@property (readonly,assign) BOOL requiresAccessToken; + +@end @interface ANMutableAuthenticatedRequest : ANRequest diff --git a/ANAuthenticatedRequest.m b/ANAuthenticatedRequest.m index 90b7129..8c05901 100644 --- a/ANAuthenticatedRequest.m +++ b/ANAuthenticatedRequest.m @@ -21,12 +21,19 @@ - (id)mutableCopyWithZone:(NSZone *)zone { return req; } +- (BOOL)requiresAccessToken { + return YES; +} + - (NSMutableURLRequest *)URLRequest { - NSAssert(self.session.accessToken, @"Session's access token has not been set"); - NSMutableURLRequest * req = super.URLRequest; - [req setValue:[NSString stringWithFormat:@"Bearer %@", self.session.accessToken] forHTTPHeaderField:@"Authorization"]; + if(self.session.accessToken) { + [req setValue:[NSString stringWithFormat:@"Bearer %@", self.session.accessToken] forHTTPHeaderField:@"Authorization"]; + } + else { + NSAssert(!self.requiresAccessToken, @"Session's access token has not been set"); + } return req; } diff --git a/ANPostRequest.m b/ANPostRequest.m index ee548d1..66fd0ae 100644 --- a/ANPostRequest.m +++ b/ANPostRequest.m @@ -22,6 +22,10 @@ - (ANRequestMethod)method { return ANRequestMethodGet; } +- (BOOL)requiresAccessToken { + return NO; +} + - (void)sendRequestWithCompletion:(ANPostRequestCompletion)completion { [self sendRequestWithRepresentationCompletion:^(ANResponse * response, id rep, NSError *error) { [self.session completePostRequest:completion withResponse:response representation:rep error:error]; diff --git a/ANPostsInGlobalStreamRequest.m b/ANPostsInGlobalStreamRequest.m index 908856f..ef090ac 100644 --- a/ANPostsInGlobalStreamRequest.m +++ b/ANPostsInGlobalStreamRequest.m @@ -14,4 +14,8 @@ - (NSURL *)URL { return [NSURL URLWithString:@"posts/stream/global" relativeToURL:[self.session URLForStreamAPIVersion:ANStreamAPIVersion0]]; } +- (BOOL)requiresAccessToken { + return NO; +} + @end diff --git a/ANPostsWithTagRequest.m b/ANPostsWithTagRequest.m index 1266081..c305dcd 100644 --- a/ANPostsWithTagRequest.m +++ b/ANPostsWithTagRequest.m @@ -14,4 +14,8 @@ - (NSURL *)URL { return [NSURL URLWithString:[NSString stringWithFormat:@"posts/tag/%@", self.tag] relativeToURL:[self.session URLForStreamAPIVersion:ANStreamAPIVersion0]]; } +- (BOOL)requiresAccessToken { + return NO; +} + @end diff --git a/ANResource.h b/ANResource.h index a915526..644ab7a 100644 --- a/ANResource.h +++ b/ANResource.h @@ -17,10 +17,10 @@ extern NSString * const ANResourceDidUpdateNotification; @protocol ANTextualResource -@property (readonly) NSString * text; -@property (readonly) NSString * HTML; -@property (readonly) ANEntitySet * entities; -@property (readonly) NSDictionary * entitiesRepresentation; +@property (nonatomic,readonly) NSString * text; +@property (nonatomic,readonly) NSString * HTML; +@property (nonatomic,readonly) ANEntitySet * entities; +@property (nonatomic,readonly) NSDictionary * entitiesRepresentation; @end