Skip to content

Commit

Permalink
Note which requests require authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
beccadax committed Oct 25, 2012
1 parent 0ad63e7 commit 6fe2696
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
6 changes: 5 additions & 1 deletion ANAuthenticatedRequest.h
Expand Up @@ -10,7 +10,11 @@

#import "ANRequest.h"

@interface ANAuthenticatedRequest : ANRequest <NSMutableCopying> @end
@interface ANAuthenticatedRequest : ANRequest <NSMutableCopying>

@property (readonly,assign) BOOL requiresAccessToken;

@end

@interface ANMutableAuthenticatedRequest : ANRequest

Expand Down
13 changes: 10 additions & 3 deletions ANAuthenticatedRequest.m
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions ANPostRequest.m
Expand Up @@ -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];
Expand Down
4 changes: 4 additions & 0 deletions ANPostsInGlobalStreamRequest.m
Expand Up @@ -14,4 +14,8 @@ - (NSURL *)URL {
return [NSURL URLWithString:@"posts/stream/global" relativeToURL:[self.session URLForStreamAPIVersion:ANStreamAPIVersion0]];
}

- (BOOL)requiresAccessToken {
return NO;
}

@end
4 changes: 4 additions & 0 deletions ANPostsWithTagRequest.m
Expand Up @@ -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
8 changes: 4 additions & 4 deletions ANResource.h
Expand Up @@ -17,10 +17,10 @@ extern NSString * const ANResourceDidUpdateNotification;

@protocol ANTextualResource <NSObject>

@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

Expand Down

0 comments on commit 6fe2696

Please sign in to comment.