Skip to content
Browse files

Add filter-updating request

  • Loading branch information...
1 parent 584938d commit 0ad63e7bb554cac5e4ffcd36da8b9c940065077d Brent Royal-Gordon committed Oct 21, 2012
Showing with 63 additions and 6 deletions.
  1. +1 −1 ANFilter.h
  2. +3 −3 ANFilter.m
  3. +1 −1 ANSession+Requests.h
  4. +9 −1 ANSession+Requests.m
  5. +18 −0 ANUpdateFilterRequest.h
  6. +31 −0 ANUpdateFilterRequest.m
View
2 ANFilter.h
@@ -33,7 +33,7 @@ extern ANFilterMatchPolicy ANFilterMatchPolicyFromString(NSString * string);
@property (nonatomic,readonly) NSString * matchPolicyRepresentation;
- (void)deleteWithCompletion:(ANFilterRequestCompletion)completion;
-//- (void)updateFromDraft:(ANDraftFilter*)draftFilter completion:(ANFilterRequestCompletion)completion;
+- (void)updateFromDraft:(ANDraftFilter*)draftFilter completion:(ANFilterRequestCompletion)completion;
- (ANDraftFilter*)draftFilter;
View
6 ANFilter.m
@@ -43,9 +43,9 @@ - (ANDraftFilter *)draftFilter {
return draft;
}
-//- (void)updateFromDraft:(ANDraftFilter *)draftFilter completion:(ANFilterRequestCompletion)completion {
-// [self.session updateFilterWithID:self.ID fromDraft:draftFilter completion:completion];
-//}
+- (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];
View
2 ANSession+Requests.h
@@ -61,6 +61,6 @@
- (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;
+- (void)updateFilterWithID:(ANResourceID)ID fromDraft:(ANDraftFilter*)draftFilter completion:(ANFilterRequestCompletion)completion;
@end
View
10 ANSession+Requests.m
@@ -39,6 +39,7 @@
#import "ANCreateFilterRequest.h"
#import "ANDeleteFilterRequest.h"
#import "ANDeleteFiltersForUserRequest.h"
+#import "ANUpdateFilterRequest.h"
@implementation ANSession (Requests)
@@ -314,6 +315,13 @@ - (void)deleteFilterWithID:(ANResourceID)ID completion:(ANFilterRequestCompletio
[req sendRequestWithCompletion:completion];
}
-//- (void)updateFilterWithID:(ANResourceID)ID fromDraft:(ANDraftFilter*)draftFilter completion:(ANFilterRequestCompletion)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
View
18 ANUpdateFilterRequest.h
@@ -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
View
31 ANUpdateFilterRequest.m
@@ -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

0 comments on commit 0ad63e7

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