Skip to content

Commit

Permalink
Support for filter reading requests
Browse files Browse the repository at this point in the history
  • Loading branch information
beccadax committed Oct 21, 2012
1 parent 46244e6 commit f6e5813
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ANCompletions.h
Expand Up @@ -10,10 +10,13 @@

@class ANUser;
@class ANPost;
@class ANFilter;
@class ANResponse;

typedef void (^ANAccessTokenInformationRequestCompletion)(ANResponse * response, NSArray * scopes, ANUser * user, NSError * error);
typedef void (^ANUserRequestCompletion)(ANResponse * response, ANUser * user, NSError * error);
typedef void (^ANUserListRequestCompletion)(ANResponse * response, NSArray * users, NSError * error);
typedef void (^ANPostRequestCompletion)(ANResponse * response, ANPost * post, NSError * error);
typedef void (^ANPostListRequestCompletion)(ANResponse * response, NSArray * posts, NSError * error);
typedef void (^ANFilterRequestCompletion)(ANResponse * response, ANFilter * filter, NSError * error);
typedef void (^ANFilterListRequestCompletion)(ANResponse * response, NSArray * filters, NSError * error);
4 changes: 4 additions & 0 deletions ANFilter.h
Expand Up @@ -8,6 +8,8 @@

#import "ANIdentifiedResource.h"

//@class ANDraftFilter;

typedef enum {
ANFilterMatchPolicyIncludeAny,
ANFilterMatchPolicyIncludeAll,
Expand All @@ -28,6 +30,8 @@ extern ANFilterMatchPolicy ANFilterMatchPolicyFromString(NSString * string);
@property (nonatomic,readonly) ANFilterMatchPolicy matchPolicy;
@property (nonatomic,readonly) NSString * matchPolicyRepresentation;

//- (ANDraftFilter*)draftFilter;

@end

typedef enum {
Expand Down
17 changes: 17 additions & 0 deletions ANFilterRequest.h
@@ -0,0 +1,17 @@
//
// ANFilterRequest.h
// Alef
//
// Created by Brent Royal-Gordon on 10/21/12.
// Copyright (c) 2012 Architechies. All rights reserved.
//

#import "ANAuthenticatedRequest.h"

@interface ANFilterRequest : ANAuthenticatedRequest

@property (nonatomic,assign) ANResourceID filterID;

- (void)sendRequestWithCompletion:(ANFilterRequestCompletion)completion;

@end
31 changes: 31 additions & 0 deletions ANFilterRequest.m
@@ -0,0 +1,31 @@
//
// ANFilterRequest.m
// Alef
//
// Created by Brent Royal-Gordon on 10/21/12.
// Copyright (c) 2012 Architechies. All rights reserved.
//

#import "ANFilterRequest.h"

@implementation ANFilterRequest

- (NSURL *)URL {
return [NSURL URLWithString:[NSString stringWithFormat:@"filters/%lld", self.filterID] relativeToURL:[self.session URLForStreamAPIVersion:ANStreamAPIVersion0]];
}

- (NSDictionary *)parameters {
return nil;
}

- (ANRequestMethod)method {
return ANRequestMethodGet;
}

- (void)sendRequestWithCompletion:(ANFilterRequestCompletion)completion {
[self sendRequestWithRepresentationCompletion:^(ANResponse *response, id rep, NSError *error) {
[self.session completeFilterRequest:completion withResponse:response representation:rep error:error];
}];
}

@end
15 changes: 15 additions & 0 deletions ANFiltersForCurrentUserRequest.h
@@ -0,0 +1,15 @@
//
// ANFiltersForCurrentUserRequest.h
// Alef
//
// Created by Brent Royal-Gordon on 10/21/12.
// Copyright (c) 2012 Architechies. All rights reserved.
//

#import "ANAuthenticatedRequest.h"

@interface ANFiltersForCurrentUserRequest : ANAuthenticatedRequest

- (void)sendRequestWithCompletion:(ANFilterListRequestCompletion)completion;

@end
31 changes: 31 additions & 0 deletions ANFiltersForCurrentUserRequest.m
@@ -0,0 +1,31 @@
//
// ANFiltersForCurrentUserRequest.m
// Alef
//
// Created by Brent Royal-Gordon on 10/21/12.
// Copyright (c) 2012 Architechies. All rights reserved.
//

#import "ANFiltersForCurrentUserRequest.h"

@implementation ANFiltersForCurrentUserRequest

- (NSURL *)URL {
return [NSURL URLWithString:@"filters" relativeToURL:[self.session URLForStreamAPIVersion:ANStreamAPIVersion0]];
}

- (NSDictionary *)parameters {
return nil;
}

- (ANRequestMethod)method {
return ANRequestMethodGet;
}

- (void)sendRequestWithCompletion:(ANFilterListRequestCompletion)completion {
[self sendRequestWithRepresentationCompletion:^(ANResponse *response, id rep, NSError *error) {
[self.session completeFilterListRequest:completion withResponse:response representation:rep error:error];
}];
}

@end
6 changes: 6 additions & 0 deletions ANSession+Requests.h
Expand Up @@ -55,4 +55,10 @@

- (void)usersWithPostWithIDReposted:(ANResourceID)postID completion:(ANUserListRequestCompletion)completion;

- (void)filtersWithCompletion:(ANFilterListRequestCompletion)completion;
- (void)filterWithID:(ANResourceID)ID completion:(ANFilterRequestCompletion)completion;
//- (void)createFilterFromDraft:(ANDraftFilter*)draftFilter completion:(ANFilterRequestCompletion)completion;
//- (void)deleteFilterWithID:(ANResourceID)ID completion:(ANFilterRequestCompletion)completion;
//- (void)updateFilterWithID:(ANResourceID)ID fromDraft:(ANDraftFilter*)draftFilter completion:(ANFilterRequestCompletion)completion;

@end
19 changes: 19 additions & 0 deletions ANSession+Requests.m
Expand Up @@ -34,6 +34,8 @@
#import "ANUnrepostPostRequest.h"
#import "ANUsersWithPostRepostedRequest.h"
#import "ANUsersMatchingSearchQueryRequest.h"
#import "ANFiltersForCurrentUserRequest.h"
#import "ANFilterRequest.h"

@implementation ANSession (Requests)

Expand Down Expand Up @@ -275,4 +277,21 @@ - (void)usersWithPostWithIDReposted:(ANResourceID)postID completion:(ANUserListR
[req sendRequestWithCompletion:completion];
}

- (void)filtersWithCompletion:(ANFilterListRequestCompletion)completion {
ANFiltersForCurrentUserRequest * req = [[ANFiltersForCurrentUserRequest alloc] initWithSession:self];
[req sendRequestWithCompletion:completion];
}

- (void)filterWithID:(ANResourceID)ID completion:(ANFilterRequestCompletion)completion {
ANFilterRequest * req = [[ANFilterRequest alloc] initWithSession:self];

req.filterID = ID;

[req sendRequestWithCompletion:completion];
}

//- (void)createFilterFromDraft:(ANDraftFilter*)draftFilter completion:(ANFilterRequestCompletion)completion;
//- (void)deleteFilterWithID:(ANResourceID)ID completion:(ANFilterRequestCompletion)completion;
//- (void)updateFilterWithID:(ANResourceID)ID fromDraft:(ANDraftFilter*)draftFilter completion:(ANFilterRequestCompletion)completion;

@end
3 changes: 3 additions & 0 deletions ANSession.h
Expand Up @@ -11,6 +11,7 @@

@class ANUser;
@class ANPost;
@class ANFilter;
@class ANResource;
@class ANDraft;

Expand Down Expand Up @@ -40,6 +41,8 @@ typedef enum {
- (void)completeUserListRequest:(ANUserListRequestCompletion)completion withResponse:(ANResponse*)response representation:(NSArray*)rep error:(NSError*)error;
- (void)completePostRequest:(ANPostRequestCompletion)completion withResponse:(ANResponse*)response representation:(NSDictionary*)rep error:(NSError*)error;
- (void)completePostListRequest:(ANPostListRequestCompletion)completion withResponse:(ANResponse*)response representation:(NSArray*)rep error:(NSError*)error;
- (void)completeFilterRequest:(ANFilterRequestCompletion)completion withResponse:(ANResponse*)response representation:(NSDictionary*)rep error:(NSError*)error;
- (void)completeFilterListRequest:(ANFilterListRequestCompletion)completion withResponse:(ANResponse *)response representation:(NSDictionary *)rep error:(NSError *)error;

@end

Expand Down
25 changes: 25 additions & 0 deletions ANSession.m
Expand Up @@ -136,6 +136,31 @@ - (void)completePostListRequest:(ANPostListRequestCompletion)completion withResp
}
}

- (void)completeFilterRequest:(ANFilterRequestCompletion)completion withResponse:(ANResponse*)response representation:(NSDictionary*)rep error:(NSError*)error {
if(rep) {
ANFilter * filter = [[ANFilter alloc] initWithRepresentation:rep session:self];
completion(response, filter, nil);
}
else {
completion(response, nil, error);
}
}

- (void)completeFilterListRequest:(ANFilterListRequestCompletion)completion withResponse:(ANResponse*)response representation:(NSArray*)rep error:(NSError*)error {
if(rep) {
NSMutableArray * filters = [[NSMutableArray alloc] initWithCapacity:rep.count];
for(NSDictionary * filterRep in rep) {
ANFilter * filter = [[ANFilter alloc] initWithRepresentation:filterRep session:self];
[filters addObject:filter];
}

completion(response, filters.copy, nil);
}
else {
completion(response, nil, error);
}
}

- (id)uniqueResource:(ANResource *)r {
__block ANResource * resource = r;

Expand Down
1 change: 1 addition & 0 deletions AppNetKit.h
Expand Up @@ -60,6 +60,7 @@ typedef enum {
#import "ANSession.h"
#import "ANUser.h"
#import "ANPost.h"
#import "ANFilter.h"
#import "ANAnnotation.h"
#import "ANEntity.h"
#import "ANSource.h"
Expand Down

0 comments on commit f6e5813

Please sign in to comment.