Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'refs/heads/filters'

Conflicts:
	ANSession+Requests.m
  • Loading branch information...
commit 46d481f1a4d915c69be5e52767d29b86c22b897a 2 parents c3950e8 + bb09576
Brent Royal-Gordon authored
3  ANCompletions.h
View
@@ -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);
17 ANCreateFilterRequest.h
View
@@ -0,0 +1,17 @@
+//
+// ANCreateFilterRequest.h
+// Alef
+//
+// Created by Brent Royal-Gordon on 10/21/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANAuthenticatedRequest.h"
+
+@interface ANCreateFilterRequest : ANAuthenticatedRequest
+
+@property (nonatomic,strong) ANDraftFilter * draftFilter;
+
+- (void)sendRequestWithCompletion:(ANFilterRequestCompletion)completion;
+
+@end
31 ANCreateFilterRequest.m
View
@@ -0,0 +1,31 @@
+//
+// ANCreateFilterRequest.m
+// Alef
+//
+// Created by Brent Royal-Gordon on 10/21/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANCreateFilterRequest.h"
+
+@implementation ANCreateFilterRequest
+
+- (NSURL *)URL {
+ return [NSURL URLWithString:@"filters" relativeToURL:[self.session URLForStreamAPIVersion:ANStreamAPIVersion0]];
+}
+
+- (NSDictionary *)parameters {
+ return self.draftFilter.representation;
+}
+
+- (ANRequestMethod)method {
+ return ANRequestMethodPost;
+}
+
+- (void)sendRequestWithCompletion:(ANFilterRequestCompletion)completion {
+ [self sendRequestWithRepresentationCompletion:^(ANResponse *response, id rep, NSError *error) {
+ [self.session completeFilterRequest:completion withResponse:response representation:rep error:error];
+ }];
+}
+
+@end
17 ANDeleteFilterRequest.h
View
@@ -0,0 +1,17 @@
+//
+// ANDeleteFilterRequest.h
+// Alef
+//
+// Created by Brent Royal-Gordon on 10/21/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANAuthenticatedRequest.h"
+
+@interface ANDeleteFilterRequest : ANAuthenticatedRequest
+
+@property (nonatomic,assign) ANResourceID filterID;
+
+- (void)sendRequestWithCompletion:(ANFilterRequestCompletion)completion;
+
+@end
31 ANDeleteFilterRequest.m
View
@@ -0,0 +1,31 @@
+//
+// ANDeleteFilterRequest.m
+// Alef
+//
+// Created by Brent Royal-Gordon on 10/21/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANDeleteFilterRequest.h"
+
+@implementation ANDeleteFilterRequest
+
+- (NSURL *)URL {
+ return [NSURL URLWithString:[NSString stringWithFormat:@"filters/%lld", self.filterID] relativeToURL:[self.session URLForStreamAPIVersion:ANStreamAPIVersion0]];
+}
+
+- (NSDictionary *)parameters {
+ return nil;
+}
+
+- (ANRequestMethod)method {
+ return ANRequestMethodDelete;
+}
+
+- (void)sendRequestWithCompletion:(ANFilterRequestCompletion)completion {
+ [self sendRequestWithRepresentationCompletion:^(ANResponse *response, id rep, NSError *error) {
+ [self.session completeFilterRequest:completion withResponse:response representation:rep error:error];
+ }];
+}
+
+@end
15 ANDeleteFiltersForUserRequest.h
View
@@ -0,0 +1,15 @@
+//
+// ANDeleteFiltersForUserRequest.h
+// Alef
+//
+// Created by Brent Royal-Gordon on 10/21/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANAuthenticatedRequest.h"
+
+@interface ANDeleteFiltersForUserRequest : ANAuthenticatedRequest
+
+- (void)sendRequestWithCompletion:(ANFilterListRequestCompletion)completion;
+
+@end
31 ANDeleteFiltersForUserRequest.m
View
@@ -0,0 +1,31 @@
+//
+// ANDeleteFiltersForUserRequest.m
+// Alef
+//
+// Created by Brent Royal-Gordon on 10/21/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANDeleteFiltersForUserRequest.h"
+
+@implementation ANDeleteFiltersForUserRequest
+
+- (NSURL *)URL {
+ return [NSURL URLWithString:@"filters" relativeToURL:[self.session URLForStreamAPIVersion:ANStreamAPIVersion0]];
+}
+
+- (NSDictionary *)parameters {
+ return nil;
+}
+
+- (ANRequestMethod)method {
+ return ANRequestMethodDelete;
+}
+
+- (void)sendRequestWithCompletion:(ANFilterListRequestCompletion)completion {
+ [self sendRequestWithRepresentationCompletion:^(ANResponse *response, id rep, NSError *error) {
+ [self.session completeFilterListRequest:completion withResponse:response representation:rep error:error];
+ }];
+}
+
+@end
100 ANFilter.h
View
@@ -0,0 +1,100 @@
+//
+// ANFilter.h
+// Alef
+//
+// Created by Brent Royal-Gordon on 10/19/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANIdentifiedResource.h"
+#import "ANCompletions.h"
+
+@class ANDraftFilter;
+@class ANDraftFilterClause;
+
+typedef enum {
+ ANFilterMatchPolicyIncludeAny,
+ ANFilterMatchPolicyIncludeAll,
+ ANFilterMatchPolicyExcludeAny,
+ ANFilterMatchPolicyExcludeAll
+} ANFilterMatchPolicy;
+
+extern NSString * ANStringFromFilterMatchPolicy(ANFilterMatchPolicy matchPolicy);
+extern ANFilterMatchPolicy ANFilterMatchPolicyFromString(NSString * string);
+
+@interface ANFilter : ANIdentifiedResource
+
+@property (nonatomic,readonly) NSString * name;
+
+@property (nonatomic,readonly) NSArray * clauses;
+@property (nonatomic,readonly) NSArray * clauseRepresentations;
+
+@property (nonatomic,readonly) ANFilterMatchPolicy matchPolicy;
+@property (nonatomic,readonly) NSString * matchPolicyRepresentation;
+
+- (void)deleteWithCompletion:(ANFilterRequestCompletion)completion;
+- (void)updateFromDraft:(ANDraftFilter*)draftFilter completion:(ANFilterRequestCompletion)completion;
+
+- (ANDraftFilter*)draftFilter;
+
+@end
+
+typedef enum {
+ ANFilterClauseObjectTypePost,
+ ANFilterClauseObjectTypeStar,
+ ANFilterClauseObjectTypeUserFollow
+} ANFilterClauseObjectType;
+
+extern NSString * ANStringFromFilterClauseObjectType(ANFilterClauseObjectType objectType);
+extern ANFilterClauseObjectType ANFilterClauseObjectTypeFromString(NSString * string);
+
+typedef enum {
+ ANFilterClauseOperatorEquals,
+ ANFilterClauseOperatorMatches,
+ ANFilterClauseOperatorLess,
+ ANFilterClauseOperatorLessOrEquals,
+ ANFilterClauseOperatorGreater,
+ ANFilterClauseOperatorGreaterOrEquals,
+ ANFilterClauseOperatorOneOf
+} ANFilterClauseOperator;
+
+extern NSString * ANStringFromFilterClauseOperator(ANFilterClauseOperator operator);
+extern ANFilterClauseOperator ANFilterClauseOperatorFromString(NSString * string);
+
+@interface ANFilterClause : ANResource
+
+@property (nonatomic,readonly) ANFilterClauseObjectType objectType;
+@property (nonatomic,readonly) NSString * objectTypeRepresentation;
+
+@property (nonatomic,readonly) ANFilterClauseOperator operator;
+@property (nonatomic,readonly) NSString * operatorRepresentation;
+
+@property (nonatomic,readonly) NSString * field;
+@property (nonatomic,readonly) id value;
+
+- (ANDraftFilterClause*)draftFilterClause;
+
+@end
+
+@interface ANDraftFilter : NSObject
+
+@property (nonatomic,readwrite) NSString * name;
+@property (nonatomic,readonly) NSMutableArray * clauses;
+@property (nonatomic,readwrite) ANFilterMatchPolicy matchPolicy;
+
+@property (nonatomic,copy) NSDictionary * representation;
+
+- (void)createFilterViaSession:(ANSession*)session completion:(ANFilterRequestCompletion)completion;
+
+@end
+
+@interface ANDraftFilterClause : NSObject
+
+@property (nonatomic,assign) ANFilterClauseObjectType objectType;
+@property (nonatomic,assign) ANFilterClauseOperator operator;
+@property (nonatomic,strong) NSString * field;
+@property (nonatomic,strong) id value;
+
+@property (nonatomic,copy) NSDictionary * representation;
+
+@end
242 ANFilter.m
View
@@ -0,0 +1,242 @@
+//
+// ANFilter.m
+// Alef
+//
+// Created by Brent Royal-Gordon on 10/19/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANFilter.h"
+#import "ANSession+Requests.h"
+
+@implementation ANFilter
+
+@dynamic name;
+@dynamic clauseRepresentations;
+@dynamic matchPolicyRepresentation;
+
++ (NSSet*)keyPathsForValuesAffectingClauses {
+ return [NSSet setWithObject:@"clauseRepresentations"];
+}
+
+- (NSArray *)clauses {
+ NSMutableArray * array = [NSMutableArray new];
+
+ for(NSDictionary * rep in self.clauseRepresentations) {
+ [array addObject:[[ANFilterClause alloc] initWithRepresentation:rep session:self.session]];
+ }
+
+ return array;
+}
+
++ (NSSet *)keyPathsForValuesAffectingMatchPolicy {
+ return [NSSet setWithObject:@"matchPolicyRepresentation"];
+}
+
+- (ANFilterMatchPolicy)matchPolicy {
+ return ANFilterMatchPolicyFromString(self.matchPolicyRepresentation);
+}
+
+- (ANDraftFilter *)draftFilter {
+ ANDraftFilter * draft = [ANDraftFilter new];
+ draft.representation = self.representation;
+ return draft;
+}
+
+- (void)updateFromDraft:(ANDraftFilter *)draftFilter completion:(ANFilterRequestCompletion)completion {
+ [self.session updateFilterWithID:self.ID fromDraft:draftFilter completion:completion];
+}
+
+- (void)deleteWithCompletion:(ANFilterRequestCompletion)completion {
+ [self.session deleteFilterWithID:self.ID completion:completion];
+}
+
+@end
+
+@implementation ANFilterClause
+
+@dynamic objectTypeRepresentation;
+@dynamic operatorRepresentation;
+@dynamic field;
+@dynamic value;
+
++ (NSSet *)keyPathsForValuesAffectingObjectType {
+ return [NSSet setWithObject:@"objectTypeRepresentation"];
+}
+
+- (ANFilterClauseObjectType)objectType {
+ return ANFilterClauseObjectTypeFromString(self.objectTypeRepresentation);
+}
+
++ (NSSet *)keyPathsForValuesAffectingOperator {
+ return [NSSet setWithObject:@"operatorRepresentation"];
+}
+
+- (ANFilterClauseOperator)operator {
+ return ANFilterClauseOperatorFromString(self.operatorRepresentation);
+}
+
+- (ANDraftFilterClause *)draftFilterClause {
+ ANDraftFilterClause * draftClause = [ANDraftFilterClause new];
+ draftClause.representation = self.representation;
+ return draftClause;
+}
+
+@end
+
+@implementation ANDraftFilter
+
+- (id)init {
+ if((self = [super init])) {
+ _clauses = [NSMutableArray new];
+ }
+ return self;
+}
+
+- (NSDictionary *)representation {
+ return @{
+ @"name": self.name,
+ @"clauses": [self.clauses valueForKey:@"representation"],
+ @"match_policy": ANStringFromFilterMatchPolicy(self.matchPolicy),
+ };
+}
+
+- (void)setRepresentation:(NSDictionary *)representation {
+ self.name = representation[@"name"];
+ self.matchPolicy = ANFilterMatchPolicyFromString(representation[@"match_policy"]);
+
+ [self.clauses removeAllObjects];
+ for(NSDictionary * clauseRep in representation[@"clauses"]) {
+ ANDraftFilterClause * clause = [ANDraftFilterClause new];
+ clause.representation = clauseRep;
+ [self.clauses addObject:clause];
+ }
+}
+
+- (void)createFilterViaSession:(ANSession *)session completion:(ANFilterRequestCompletion)completion {
+ [session createFilterFromDraft:self completion:completion];
+}
+
+@end
+
+@implementation ANDraftFilterClause
+
+- (NSDictionary *)representation {
+ return @{
+ @"object_type": ANStringFromFilterClauseObjectType(self.objectType),
+ @"operator": ANStringFromFilterClauseOperator(self.operator),
+ @"field": self.field,
+ @"value": self.value
+ };
+}
+
+- (void)setRepresentation:(NSDictionary *)representation {
+ self.objectType = ANFilterClauseObjectTypeFromString(representation[@"object_type"]);
+ self.operator = ANFilterClauseOperatorFromString(representation[@"operator"]);
+ self.field = representation[@"field"];
+ self.value = representation[@"value"];
+}
+
+@end
+
+NSString * ANStringFromFilterMatchPolicy(ANFilterMatchPolicy matchPolicy) {
+ static NSDictionary * table;
+ static dispatch_once_t once;
+
+ dispatch_once(&once, ^{
+ table = @{
+ @(ANFilterMatchPolicyIncludeAll): @"include_all",
+ @(ANFilterMatchPolicyIncludeAny): @"include_any",
+ @(ANFilterMatchPolicyExcludeAll): @"exclude_all",
+ @(ANFilterMatchPolicyExcludeAny): @"exclude_any",
+ };
+ });
+
+ return table[@(matchPolicy)];
+}
+
+ANFilterMatchPolicy ANFilterMatchPolicyFromString(NSString * string) {
+ static NSDictionary * table;
+ static dispatch_once_t once;
+
+ dispatch_once(&once, ^{
+ table = @{
+ @"include_all": @(ANFilterMatchPolicyIncludeAll),
+ @"include_any": @(ANFilterMatchPolicyIncludeAny),
+ @"exclude_all": @(ANFilterMatchPolicyExcludeAll),
+ @"exclude_any": @(ANFilterMatchPolicyExcludeAny),
+ };
+ });
+
+ return [table[string] integerValue];
+}
+
+NSString * ANStringFromFilterClauseObjectType(ANFilterClauseObjectType objectType) {
+ static NSDictionary * table;
+ static dispatch_once_t once;
+
+ dispatch_once(&once, ^{
+ table = @{
+ @(ANFilterClauseObjectTypePost): @"post",
+ @(ANFilterClauseObjectTypeStar): @"star",
+ @(ANFilterClauseObjectTypeUserFollow): @"user_follow",
+ };
+ });
+
+ return table[@(objectType)];
+}
+
+ANFilterClauseObjectType ANFilterClauseObjectTypeFromString(NSString * string) {
+ static NSDictionary * table;
+ static dispatch_once_t once;
+
+ dispatch_once(&once, ^{
+ table = @{
+ @"post": @(ANFilterClauseObjectTypePost),
+ @"star": @(ANFilterClauseObjectTypeStar),
+ @"user_follow": @(ANFilterClauseObjectTypeUserFollow),
+ };
+ });
+
+ return [table[string] integerValue];
+}
+
+
+NSString * ANStringFromFilterClauseOperator(ANFilterClauseOperator operator) {
+ static NSDictionary * table;
+ static dispatch_once_t once;
+
+ dispatch_once(&once, ^{
+ table = @{
+ @(ANFilterClauseOperatorEquals): @"equals",
+ @(ANFilterClauseOperatorGreater): @"gt",
+ @(ANFilterClauseOperatorGreaterOrEquals): @"ge",
+ @(ANFilterClauseOperatorLess): @"lt",
+ @(ANFilterClauseOperatorLessOrEquals): @"le",
+ @(ANFilterClauseOperatorMatches): @"matches",
+ @(ANFilterClauseOperatorOneOf): @"one_of",
+ };
+ });
+
+ return table[@(operator)];
+}
+
+ANFilterClauseOperator ANFilterClauseOperatorFromString(NSString * string) {
+ static NSDictionary * table;
+ static dispatch_once_t once;
+
+ dispatch_once(&once, ^{
+ table = @{
+ @"equals": @(ANFilterClauseOperatorEquals),
+ @"gt": @(ANFilterClauseOperatorGreater),
+ @"ge": @(ANFilterClauseOperatorGreaterOrEquals),
+ @"lt": @(ANFilterClauseOperatorLess),
+ @"le": @(ANFilterClauseOperatorLessOrEquals),
+ @"matches": @(ANFilterClauseOperatorMatches),
+ @"one_of": @(ANFilterClauseOperatorOneOf),
+ };
+ });
+
+ return [table[string] integerValue];
+}
+
17 ANFilterRequest.h
View
@@ -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 ANFilterRequest.m
View
@@ -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 ANFiltersForCurrentUserRequest.h
View
@@ -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 ANFiltersForCurrentUserRequest.m
View
@@ -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
5 ANRequest.h
View
@@ -14,7 +14,8 @@
typedef enum {
ANRequestMethodGet,
ANRequestMethodPost,
- ANRequestMethodDelete
+ ANRequestMethodDelete,
+ ANRequestMethodPut
} ANRequestMethod;
typedef enum {
@@ -26,7 +27,7 @@ typedef enum {
- (id)initWithSession:(ANSession*)session;
-@property (readonly,weak) ANSession * session;
+@property (weak) ANSession * session;
@property (readonly) NSURL * URL;
@property (readonly) NSDictionary * parameters;
15 ANRequest.m
View
@@ -50,6 +50,9 @@ - (NSString*)methodString {
case ANRequestMethodDelete:
return @"DELETE";
+ case ANRequestMethodPut:
+ return @"PUT";
+
default:
NSAssert(NO, @"Unknown method %d", self.method);
return nil;
@@ -203,9 +206,17 @@ - (void)sendRequestWithRepresentationCompletion:(void (^)(ANResponse *, id, NSEr
if(!error) {
error = jsonError;
}
- if(error && json) {
+ if(error && (response || json)) {
NSMutableDictionary *userInfo = [error.userInfo mutableCopy];
- [userInfo setObject:json forKey:@"json"];
+
+ [userInfo setObject:error forKey:NSUnderlyingErrorKey];
+ if(json) {
+ [userInfo setObject:json forKey:@"json"];
+ }
+ if(response.errorMessage) {
+ [userInfo setObject:response.errorMessage forKey:NSLocalizedDescriptionKey];
+ }
+
error = [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo];
json = nil;
1  ANResponse.h
View
@@ -13,6 +13,7 @@
@interface ANResponse : ANResource
@property (nonatomic,readonly) NSUInteger statusCode;
+@property (nonatomic,readonly) NSString * errorMessage;
@property (nonatomic,readonly) ANResourceID earliestID;
@property (nonatomic,readonly) ANResourceID latestID;
1  ANResponse.m
View
@@ -23,6 +23,7 @@ @implementation ANResponse
@dynamic minID;
@dynamic maxID;
@dynamic more;
+@dynamic errorMessage;
- (NSUInteger)statusCode {
return self.code;
8 ANSession+Requests.h
View
@@ -58,4 +58,12 @@
- (void)usersWithPostWithIDReposted:(ANResourceID)postID completion:(ANUserListRequestCompletion)completion;
+- (void)filtersWithCompletion:(ANFilterListRequestCompletion)completion;
+- (void)deleteFiltersWithCompletion:(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
49 ANSession+Requests.m
View
@@ -34,6 +34,12 @@
#import "ANUnrepostPostRequest.h"
#import "ANUsersWithPostRepostedRequest.h"
#import "ANUsersMatchingSearchQueryRequest.h"
+#import "ANFiltersForCurrentUserRequest.h"
+#import "ANFilterRequest.h"
+#import "ANCreateFilterRequest.h"
+#import "ANDeleteFilterRequest.h"
+#import "ANDeleteFiltersForUserRequest.h"
+#import "ANUpdateFilterRequest.h"
#import "ANPostsInUserUnifiedStreamRequest.h"
@implementation ANSession (Requests)
@@ -289,4 +295,47 @@ - (void)usersWithPostWithIDReposted:(ANResourceID)postID completion:(ANUserListR
[req sendRequestWithCompletion:completion];
}
+- (void)filtersWithCompletion:(ANFilterListRequestCompletion)completion {
+ ANFiltersForCurrentUserRequest * req = [[ANFiltersForCurrentUserRequest alloc] initWithSession:self];
+ [req sendRequestWithCompletion:completion];
+}
+
+- (void)deleteFiltersWithCompletion:(ANFilterListRequestCompletion)completion {
+ ANDeleteFiltersForUserRequest * req = [[ANDeleteFiltersForUserRequest 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 {
+ ANCreateFilterRequest * req = [[ANCreateFilterRequest alloc] initWithSession:self];
+
+ req.draftFilter = draftFilter;
+
+ [req sendRequestWithCompletion:completion];
+}
+
+- (void)deleteFilterWithID:(ANResourceID)ID completion:(ANFilterRequestCompletion)completion {
+ ANDeleteFilterRequest * req = [[ANDeleteFilterRequest alloc] initWithSession:self];
+
+ req.filterID = ID;
+
+ [req sendRequestWithCompletion:completion];
+}
+
+- (void)updateFilterWithID:(ANResourceID)ID fromDraft:(ANDraftFilter*)draftFilter completion:(ANFilterRequestCompletion)completion {
+ ANUpdateFilterRequest * req = [[ANUpdateFilterRequest alloc] initWithSession:self];
+
+ req.filterID = ID;
+ req.draftFilter = draftFilter;
+
+ [req sendRequestWithCompletion:completion];
+}
+
@end
5 ANSession.h
View
@@ -11,8 +11,10 @@
@class ANUser;
@class ANPost;
+@class ANFilter;
@class ANResource;
@class ANDraft;
+@class ANDraftFilter;
extern const ANResourceID ANMeUserID;
extern const ANResourceID ANUnspecifiedPostID;
@@ -30,6 +32,7 @@ typedef enum {
+ (BOOL)isUsingNetwork;
+ (ANSession*)defaultSession;
++ (void)setDefaultSession:(ANSession*)defaultSession;
@property (strong) NSString * accessToken;
@@ -40,6 +43,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
37 ANSession.m
View
@@ -50,7 +50,7 @@ - (id)init {
return self;
}
-+ (ANSession *)defaultSession {
++ (ANSession *)defaultDefaultSession {
static ANSession * singleton;
static dispatch_once_t once;
@@ -61,6 +61,16 @@ + (ANSession *)defaultSession {
return singleton;
}
+static ANSession * DefaultSession = nil;
+
++ (ANSession*)defaultSession {
+ return DefaultSession ?: [self defaultDefaultSession];
+}
+
++ (void)setDefaultSession:(ANSession*)defaultSession {
+ DefaultSession = defaultSession;
+}
+
- (NSURL *)URLForStreamAPIVersion:(ANStreamAPIVersion)version {
switch(version) {
case ANStreamAPIVersion0:
@@ -136,6 +146,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;
18 ANUpdateFilterRequest.h
View
@@ -0,0 +1,18 @@
+//
+// ANUpdateFilterRequest.h
+// Alef
+//
+// Created by Brent Royal-Gordon on 10/21/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANAuthenticatedRequest.h"
+
+@interface ANUpdateFilterRequest : ANAuthenticatedRequest
+
+@property (nonatomic,assign) ANResourceID filterID;
+@property (nonatomic,strong) ANDraftFilter * draftFilter;
+
+- (void)sendRequestWithCompletion:(ANFilterRequestCompletion)completion;
+
+@end
31 ANUpdateFilterRequest.m
View
@@ -0,0 +1,31 @@
+//
+// ANUpdateFilterRequest.m
+// Alef
+//
+// Created by Brent Royal-Gordon on 10/21/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANUpdateFilterRequest.h"
+
+@implementation ANUpdateFilterRequest
+
+- (NSURL *)URL {
+ return [NSURL URLWithString:[NSString stringWithFormat:@"filters/%lld", self.filterID] relativeToURL:[self.session URLForStreamAPIVersion:ANStreamAPIVersion0]];
+}
+
+- (NSDictionary *)parameters {
+ return self.draftFilter.representation;
+}
+
+- (ANRequestMethod)method {
+ return ANRequestMethodPut;
+}
+
+- (void)sendRequestWithCompletion:(ANFilterRequestCompletion)completion {
+ [self sendRequestWithRepresentationCompletion:^(ANResponse *response, id rep, NSError *error) {
+ [self.session completeFilterRequest:completion withResponse:response representation:rep error:error];
+ }];
+}
+
+@end
1  AppNetKit.h
View
@@ -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.