Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support for filter reading requests

  • Loading branch information...
commit f6e58133010565f50c7883a3bd498e8c411d0fb4 1 parent 46244e6
Brent Royal-Gordon authored
View
3  ANCompletions.h
@@ -10,6 +10,7 @@
@class ANUser;
@class ANPost;
+@class ANFilter;
@class ANResponse;
typedef void (^ANAccessTokenInformationRequestCompletion)(ANResponse * response, NSArray * scopes, ANUser * user, NSError * error);
@@ -17,3 +18,5 @@ typedef void (^ANUserRequestCompletion)(ANResponse * response, ANUser * user, NS
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);
View
4 ANFilter.h
@@ -8,6 +8,8 @@
#import "ANIdentifiedResource.h"
+//@class ANDraftFilter;
+
typedef enum {
ANFilterMatchPolicyIncludeAny,
ANFilterMatchPolicyIncludeAll,
@@ -28,6 +30,8 @@ extern ANFilterMatchPolicy ANFilterMatchPolicyFromString(NSString * string);
@property (nonatomic,readonly) ANFilterMatchPolicy matchPolicy;
@property (nonatomic,readonly) NSString * matchPolicyRepresentation;
+//- (ANDraftFilter*)draftFilter;
+
@end
typedef enum {
View
17 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
View
31 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
View
15 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
View
31 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
View
6 ANSession+Requests.h
@@ -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
View
19 ANSession+Requests.m
@@ -34,6 +34,8 @@
#import "ANUnrepostPostRequest.h"
#import "ANUsersWithPostRepostedRequest.h"
#import "ANUsersMatchingSearchQueryRequest.h"
+#import "ANFiltersForCurrentUserRequest.h"
+#import "ANFilterRequest.h"
@implementation ANSession (Requests)
@@ -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
View
3  ANSession.h
@@ -11,6 +11,7 @@
@class ANUser;
@class ANPost;
+@class ANFilter;
@class ANResource;
@class ANDraft;
@@ -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
View
25 ANSession.m
@@ -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;
View
1  AppNetKit.h
@@ -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"
Please sign in to comment.
Something went wrong with that request. Please try again.