Skip to content
Browse files

Draft filters and draft clauses

  • Loading branch information...
1 parent bb73a03 commit 358b6273674967f04b1dbe7491d6f761384fc1de Brent Royal-Gordon committed Oct 21, 2012
Showing with 89 additions and 2 deletions.
  1. +26 −2 ANFilter.h
  2. +63 −0 ANFilter.m
View
28 ANFilter.h
@@ -8,7 +8,8 @@
#import "ANIdentifiedResource.h"
-//@class ANDraftFilter;
+@class ANDraftFilter;
+@class ANDraftFilterClause;
typedef enum {
ANFilterMatchPolicyIncludeAny,
@@ -30,7 +31,7 @@ extern ANFilterMatchPolicy ANFilterMatchPolicyFromString(NSString * string);
@property (nonatomic,readonly) ANFilterMatchPolicy matchPolicy;
@property (nonatomic,readonly) NSString * matchPolicyRepresentation;
-//- (ANDraftFilter*)draftFilter;
+- (ANDraftFilter*)draftFilter;
@end
@@ -67,4 +68,27 @@ extern ANFilterClauseOperator ANFilterClauseOperatorFromString(NSString * string
@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;
+
+@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
View
63 ANFilter.m
@@ -36,6 +36,12 @@ - (ANFilterMatchPolicy)matchPolicy {
return ANFilterMatchPolicyFromString(self.matchPolicyRepresentation);
}
+- (ANDraftFilter *)draftFilter {
+ ANDraftFilter * draft = [ANDraftFilter new];
+ draft.representation = self.representation;
+ return draft;
+}
+
@end
@implementation ANFilterClause
@@ -61,6 +67,63 @@ - (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];
+ }
+}
+
+@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) {

0 comments on commit 358b627

Please sign in to comment.
Something went wrong with that request. Please try again.