Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support for stream markers

  • Loading branch information...
commit 325165379311bc46381a8887476976fa9be4e55f 1 parent 7122201
Brent Royal-Gordon authored
View
2  ANCompletions.h
@@ -11,6 +11,7 @@
@class ANUser;
@class ANPost;
@class ANFilter;
+@class ANStreamMarker;
@class ANResponse;
typedef void (^ANAccessTokenInformationRequestCompletion)(ANResponse * response, NSArray * scopes, ANUser * user, NSError * error);
@@ -20,3 +21,4 @@ typedef void (^ANPostRequestCompletion)(ANResponse * response, ANPost * post, NS
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);
+typedef void (^ANStreamMarkerRequestCompletion)(ANResponse * response, ANStreamMarker * marker, NSError * error);
View
3  ANResponse.h
@@ -9,6 +9,7 @@
#import <Foundation/Foundation.h>
#import "ANResource.h"
#import "ANDefines.h"
+#import "ANStreamMarker.h"
@interface ANResponse : ANResource
@@ -19,4 +20,6 @@
@property (nonatomic,readonly) ANResourceID latestID;
@property (nonatomic,readonly) BOOL hasMore;
+@property (nonatomic,readonly) ANStreamMarker * marker;
+
@end
View
2  ANSession+Requests.h
@@ -66,4 +66,6 @@
- (void)deleteFilterWithID:(ANResourceID)ID completion:(ANFilterRequestCompletion)completion;
- (void)updateFilterWithID:(ANResourceID)ID fromDraft:(ANDraftFilter*)draftFilter completion:(ANFilterRequestCompletion)completion;
+- (void)updateStreamMarkerWithDraft:(ANDraftStreamMarker*)draftMarker completion:(ANStreamMarkerRequestCompletion)completion;
+
@end
View
9 ANSession+Requests.m
@@ -41,6 +41,7 @@
#import "ANDeleteFiltersForUserRequest.h"
#import "ANUpdateFilterRequest.h"
#import "ANPostsInUserUnifiedStreamRequest.h"
+#import "ANUpdateStreamMarkerRequest.h"
@implementation ANSession (Requests)
@@ -338,4 +339,12 @@ - (void)updateFilterWithID:(ANResourceID)ID fromDraft:(ANDraftFilter*)draftFilte
[req sendRequestWithCompletion:completion];
}
+- (void)updateStreamMarkerWithDraft:(ANDraftStreamMarker*)draftMarker completion:(ANStreamMarkerRequestCompletion)completion {
+ ANUpdateStreamMarkerRequest * req = [[ANUpdateStreamMarkerRequest alloc] initWithSession:self];
+
+ req.draftMarker = draftMarker;
+
+ [req sendRequestWithCompletion:completion];
+}
+
@end
View
2  ANSession.h
@@ -15,6 +15,7 @@
@class ANResource;
@class ANDraft;
@class ANDraftFilter;
+@class ANDraftStreamMarker;
extern const ANResourceID ANMeUserID;
extern const ANResourceID ANUnspecifiedPostID;
@@ -45,6 +46,7 @@ typedef enum {
- (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;
+- (void)completeStreamMarkerRequest:(ANStreamMarkerRequestCompletion)completion withResponse:(ANResponse *)response representation:(NSDictionary *)rep error:(NSError *)error;
@end
View
10 ANSession.m
@@ -172,6 +172,16 @@ - (void)completeFilterListRequest:(ANFilterListRequestCompletion)completion with
}
}
+- (void)completeStreamMarkerRequest:(ANStreamMarkerRequestCompletion)completion withResponse:(ANResponse *)response representation:(NSDictionary *)rep error:(NSError *)error {
+ if(rep) {
+ ANStreamMarker * marker = [[ANStreamMarker alloc] initWithRepresentation:rep session:self];
+ completion(response, marker, nil);
+ }
+ else {
+ completion(response, nil, error);
+ }
+}
+
- (id)uniqueResource:(ANIdentifiedResource *)r {
__block ANIdentifiedResource * resource = r;
View
42 ANStreamMarker.h
@@ -0,0 +1,42 @@
+//
+// ANStreamMarker.h
+// Alef
+//
+// Created by Brent Royal-Gordon on 11/13/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANResource.h"
+#import "ANDefines.h"
+#import "ANCompletions.h"
+
+extern const NSUInteger ANStreamMarkerUnspecifiedPercentage;
+@class ANDraftStreamMarker;
+
+@interface ANStreamMarker : ANResource
+
+@property (nonatomic,readonly) NSString * name;
+@property (nonatomic,readonly,getter=isMarked) BOOL marked;
+
+@property (nonatomic,readonly) ANResourceID postID;
+@property (nonatomic,readonly) NSUInteger percentage;
+
+@property (nonatomic,readonly) NSDate * updatedAt;
+@property (nonatomic,readonly) NSString * version;
+
+- (ANDraftStreamMarker*)draftStreamMarkerWithPostID:(ANResourceID)postID percentage:(NSUInteger)percentage;
+- (void)updateWithPostID:(ANResourceID)postID percentage:(NSUInteger)percentage completion:(ANStreamMarkerRequestCompletion)completion;
+
+@end
+
+@interface ANDraftStreamMarker : NSObject
+
+@property (nonatomic,copy) NSString * name;
+@property (nonatomic,assign) ANResourceID postID;
+@property (nonatomic,assign) NSUInteger percentage;
+
+@property (nonatomic,copy) NSDictionary * representation;
+
+- (void)updateViaSession:(ANSession*)session completion:(ANStreamMarkerRequestCompletion)completion;
+
+@end
View
78 ANStreamMarker.m
@@ -0,0 +1,78 @@
+//
+// ANStreamMarker.m
+// Alef
+//
+// Created by Brent Royal-Gordon on 11/13/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANStreamMarker.h"
+#import "ANSession+Requests.h"
+
+const NSUInteger ANStreamMarkerUnspecifiedPercentage = 0;
+
+@interface ANStreamMarker ()
+
+@property (nonatomic,readonly) ANResourceID ID;
+
+@end
+
+@implementation ANStreamMarker
+
+@dynamic name;
+@dynamic ID;
+@dynamic percentage;
+@dynamic updatedAt;
+@dynamic version;
+
+- (ANResourceID)postID {
+ return self.ID;
+}
+
+- (BOOL)isMarked {
+ return [self.representation objectForKey:@"id"] != nil;
+}
+
+- (ANDraftStreamMarker*)draftStreamMarkerWithPostID:(ANResourceID)postID percentage:(NSUInteger)percentage {
+ ANDraftStreamMarker * draft = [ANDraftStreamMarker new];
+
+ draft.name = self.name;
+ draft.postID = postID;
+ draft.percentage = percentage;
+
+ return draft;
+}
+
+- (void)updateWithPostID:(ANResourceID)postID percentage:(NSUInteger)percentage completion:(ANStreamMarkerRequestCompletion)completion {
+ [[self draftStreamMarkerWithPostID:postID percentage:percentage] updateViaSession:self.session completion:completion];
+}
+
+@end
+
+@implementation ANDraftStreamMarker
+
+- (NSDictionary *)representation {
+ NSMutableDictionary * rep = [NSMutableDictionary new];
+
+ [rep setObject:self.name forKey:@"name"];
+ if(self.postID) {
+ [rep setObject:[ANResource.IDFormatter stringFromNumber:[NSNumber numberWithUnsignedLongLong:self.postID]] forKey:@"id"];
+ }
+ if(self.percentage) {
+ [rep setObject:[NSString stringWithFormat:@"%d", self.percentage] forKey:@"percentage"];
+ }
+
+ return rep;
+}
+
+- (void)setRepresentation:(NSDictionary *)rep {
+ self.name = [rep objectForKey:@"name"];
+ self.postID = [[ANResource.IDFormatter numberFromString:[rep objectForKey:@"id"]] unsignedLongLongValue];
+ self.percentage = [[rep objectForKey:@"percentage"] integerValue];
+}
+
+- (void)updateViaSession:(ANSession *)session completion:(ANStreamMarkerRequestCompletion)completion {
+ [session updateStreamMarkerWithDraft:self completion:completion];
+}
+
+@end
View
18 ANUpdateStreamMarkerRequest.h
@@ -0,0 +1,18 @@
+//
+// ANUpdateStreamMarkerRequest.h
+// Alef
+//
+// Created by Brent Royal-Gordon on 11/13/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANAuthenticatedRequest.h"
+#import "ANStreamMarker.h"
+
+@interface ANUpdateStreamMarkerRequest : ANAuthenticatedRequest
+
+@property (nonatomic,strong) ANDraftStreamMarker * draftMarker;
+
+- (void)sendRequestWithCompletion:(ANStreamMarkerRequestCompletion)completion;
+
+@end
View
31 ANUpdateStreamMarkerRequest.m
@@ -0,0 +1,31 @@
+//
+// ANUpdateStreamMarkerRequest.m
+// Alef
+//
+// Created by Brent Royal-Gordon on 11/13/12.
+// Copyright (c) 2012 Architechies. All rights reserved.
+//
+
+#import "ANUpdateStreamMarkerRequest.h"
+
+@implementation ANUpdateStreamMarkerRequest
+
+- (NSURL *)URL {
+ return [NSURL URLWithString:@"posts/marker" relativeToURL:[self.session URLForStreamAPIVersion:ANStreamAPIVersion0]];
+}
+
+- (NSDictionary *)parameters {
+ return self.draftMarker.representation;
+}
+
+- (ANRequestMethod)method {
+ return ANRequestMethodPost;
+}
+
+- (void)sendRequestWithCompletion:(ANStreamMarkerRequestCompletion)completion {
+ [self sendRequestWithRepresentationCompletion:^(ANResponse *response, id rep, NSError *error) {
+ [self.session completeStreamMarkerRequest:completion withResponse:response representation:rep error:error];
+ }];
+}
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.