Skip to content

Update user-streams branch to use AFNetworking 2 #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: user-streams
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
876acc6
Look for "file_token", not "derived_files" when parsing responses int…
tonyarnold Apr 7, 2014
64ef296
Add "youMuted" property to ANKChannel
tonyarnold Apr 7, 2014
179b841
Update to AFNetworking 2.x, XCTest, Objective-C modules
tonyarnold Apr 7, 2014
2658e6e
Latest AFNetworking and SocketShuttle
tonyarnold Apr 7, 2014
b773a07
Bump to version 1.9.99
tonyarnold Apr 7, 2014
f46a379
Set default parameters on client initialization
tonyarnold Apr 7, 2014
82c2bc4
Whoops, forgot to pass along the parameters…
tonyarnold Apr 7, 2014
2199b4f
Add auto_subscribe parameter to channel object
tonyarnold Apr 13, 2014
384c666
Add support for deactivating a channel
tonyarnold Apr 13, 2014
dc0fa82
Lock submodule to AFNetworking 2.2.1
tonyarnold Apr 14, 2014
e1f5a2a
Add method to pass parameters to the initial streaming request
tonyarnold Apr 14, 2014
f4487d2
Add support for the various annotation types to the general parameter…
tonyarnold Apr 14, 2014
85086ef
Fix busted fetchMessagesWithIDs method
rrbrambley Apr 13, 2014
e84c956
Ensure that the default parameters are always present in the request URL
tonyarnold Apr 14, 2014
cc6b4ec
Respect the include_annotation request sent through from the parameters
tonyarnold Apr 14, 2014
f0d26a5
Add rate limiting information, and serialise responses properly (incl…
tonyarnold Apr 14, 2014
9b94cd9
Update submodule to AFNetworking 2.2.3
tonyarnold Apr 19, 2014
69a6761
Update `ANKClientFileUploadProgressBlock` to use `long long` in place…
tonyarnold Apr 19, 2014
4a5f4a2
AFNetworking 2.2.4
tonyarnold May 23, 2014
0a9bdf1
Handle streamed deletions
tonyarnold May 23, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[submodule "External/AFNetworking"]
path = External/AFNetworking
url = https://github.com/AFNetworking/AFNetworking
ignore = dirty
[submodule "SocketShuttle"]
url = https://github.com/AFNetworking/AFNetworking.git
[submodule "External/SocketShuttle"]
path = External/SocketShuttle
url=https://github.com/joeldev/SocketShuttle.git
url = https://github.com/tonyarnold/SocketShuttle.git
2 changes: 1 addition & 1 deletion ADNKit-OSX/ADNKit-OSX-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.2</string>
<string>1.9.99</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
422 changes: 168 additions & 254 deletions ADNKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions ADNKit/ADNKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@
#import <ADNKit/ANKOEmbed.h>

#import <ADNKit/ANKValueTransformations.h>
#import <ADNKit/ANKJSONRequestOperation.h>
#import <ADNKit/ANKAPIResponse.h>
#import <ADNKit/ANKAPIResponseMeta.h>
#import <ADNKit/ANKJSONRequestOperation.h>
#import <ADNKit/ANKPaginationSettings.h>
#import <ADNKit/ANKGeneralParameters.h>
#import <ADNKit/ANKSearchQuery.h>

#import <ADNKit/ANKAPIRequestSerializer.h>
#import <ADNKit/ANKAPIResponseSerializer.h>

#import <ADNKit/ANKUsernameFormatter.h>

#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
Expand Down
11 changes: 11 additions & 0 deletions ADNKit/ANKAPIRequestSerializer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Created by Tony Arnold on 7/04/2014.
//

#import "AFURLRequestSerialization.h"

@interface ANKAPIRequestSerializer : AFJSONRequestSerializer

@property (strong) NSDictionary *defaultParameters;

@end
32 changes: 32 additions & 0 deletions ADNKit/ANKAPIRequestSerializer.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Created by Tony Arnold on 7/04/2014.
//

#import "ANKAPIRequestSerializer.h"
#import "ADNKit.h"

@implementation ANKAPIRequestSerializer

- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
URLString:(NSString *)URLString
parameters:(id)parameters
error:(NSError *__autoreleasing *)error
{
if ((self.defaultParameters.count > 0) && [parameters isKindOfClass:[NSDictionary class]]) {
parameters = [(NSDictionary *)parameters ank_dictionaryByAppendingDictionary : self.defaultParameters];
}

NSMutableString *modifiedURLString = [URLString mutableCopy];

[self.defaultParameters enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) {
NSString *delimiter = (NSNotFound == [modifiedURLString rangeOfString:@"?"].location) ? @"?" : @"&";
[modifiedURLString appendFormat:@"%@%@=%@", delimiter, key, obj];
}];

return [super requestWithMethod:method
URLString:modifiedURLString
parameters:parameters
error:error];
}

@end
6 changes: 3 additions & 3 deletions ADNKit/ANKAPIResponse.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
Copyright (c) 2013, Joel Levin
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of ADNKit nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
Expand All @@ -23,6 +23,6 @@ static NSString *const kANKAPIResponseKey = @"ANKAPIResponse";
@property (readonly, strong) id data;
@property (readonly, strong) ANKAPIResponseMeta *meta;

- (id)initWithResponseObject:(id)responseObject;
- (id)initWithResponseObject:(id)responseObject andHeaders:(NSDictionary*)headers;

@end
17 changes: 13 additions & 4 deletions ADNKit/ANKAPIResponse.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/*
Copyright (c) 2013, Joel Levin
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of ADNKit nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#import "ANKAPIResponse.h"
#import "ANKResourceMap.h"
#import "ANKAPIResponseMeta.h"


Expand All @@ -24,12 +25,20 @@ @interface ANKAPIResponse ()

@implementation ANKAPIResponse

- (id)initWithResponseObject:(id)responseObject {
- (id)initWithResponseObject:(id)responseObject andHeaders:(NSDictionary*)headers{
if ((self = [super init])) {
if ([responseObject isKindOfClass:[NSDictionary class]]) {
NSDictionary *responseDictionary = (NSDictionary *)responseObject;
self.data = responseDictionary[@"data"];
self.meta = [ANKAPIResponseMeta objectFromJSONDictionary:responseDictionary[@"meta"]];
self.meta = [ANKResolve(ANKAPIResponseMeta) objectFromJSONDictionary:responseDictionary[@"meta"]];

if (headers)
{
self.meta.rateLimitReset = [headers objectForKey:@"X-RateLimit-Reset"];
self.meta.rateLimitRemaining = [headers objectForKey:@"X-RateLimit-Remaining"];
self.meta.rateLimitLimit = [headers objectForKey:@"X-RateLimit-Limit"];
self.meta.rateLimitRetryAfter = [headers objectForKey:@"Retry-After"];
}
}
}
return self;
Expand Down
6 changes: 6 additions & 0 deletions ADNKit/ANKAPIResponseMeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ static NSString *const kANKErrorIDKey = @"ANKErrorID";
@property (strong) NSString *errorSlug;
@property (strong) NSString *errorID;

// rate limits
@property (strong) NSString *rateLimitRemaining;
@property (strong) NSString *rateLimitLimit;
@property (strong) NSString *rateLimitReset;
@property (strong) NSString *rateLimitRetryAfter;

// user streaming properties
@property (assign) BOOL isDeleted;
@property (strong) NSString *deletedID;
Expand Down
9 changes: 9 additions & 0 deletions ADNKit/ANKAPIResponseSerializer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// Created by Tony Arnold on 7/04/2014.
//

#import "AFURLResponseSerialization.h"

@interface ANKAPIResponseSerializer : AFJSONResponseSerializer

@end
34 changes: 34 additions & 0 deletions ADNKit/ANKAPIResponseSerializer.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Created by Tony Arnold on 7/04/2014.
//

#import "ANKAPIResponseSerializer.h"
#import "ADNKit.h"

@implementation ANKAPIResponseSerializer

- (id)responseObjectForResponse:(NSURLResponse *)response
data:(NSData *)data
error:(NSError *__autoreleasing *)error
{
NSError *responseError;

id originalResponse = [super responseObjectForResponse:response data:data error:&responseError];

NSDictionary* headers = [(NSHTTPURLResponse *)response allHeaderFields];
ANKAPIResponse *apiResponse = [[ANKAPIResponse alloc] initWithResponseObject:originalResponse andHeaders:headers];

if (responseError) {
NSMutableDictionary *modifiedUserInfo = [responseError.userInfo mutableCopy];
modifiedUserInfo[kANKAPIResponseKey] = apiResponse;
responseError = [NSError errorWithDomain:responseError.domain code:responseError.code userInfo:modifiedUserInfo];
}

if (error && responseError) {
*error = responseError;
}

return apiResponse;
}

@end
2 changes: 2 additions & 0 deletions ADNKit/ANKChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
@property (assign) BOOL isEditableByCurrentUser;
@property (assign) BOOL isInactive;
@property (assign) BOOL hasUnreadMessages;
@property (assign) BOOL youMuted;
@property (assign) BOOL autoSubscribe;

- (BOOL)isPrivateMessageChannel;

Expand Down
4 changes: 3 additions & 1 deletion ADNKit/ANKChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ + (NSDictionary *)JSONToLocalKeyMapping {
@"has_unread": @"hasUnreadMessages",
@"recent_message_id": @"latestMessageID",
@"recent_message": @"latestMessage",
@"is_inactive" : @"isInactive"}];
@"is_inactive" : @"isInactive",
@"you_muted" : @"youMuted",
@"auto_subscribe" : @"autoSubscribe"}];
}


Expand Down
67 changes: 35 additions & 32 deletions ADNKit/ANKClient+ANKChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,40 @@

@interface ANKClient (ANKChannel)

- (ANKJSONRequestOperation *)fetchCurrentUserSubscribedChannelsWithCompletion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)fetchCurrentUserSubscribedChannelsWithTypes:(NSArray *)types completion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)fetchCurrentUserPrivateMessageChannelsWithCompletion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)fetchCurrentUserCreatedChannelsWithCompletion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)fetchUnreadPMChannelsCountWithCompletion:(ANKClientCompletionBlock)completionHandler;

- (ANKJSONRequestOperation *)fetchChannelWithID:(NSString *)channelID completion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)fetchChannelsWithIDs:(NSArray *)channelIDs completion:(ANKClientCompletionBlock)completionHandler;

- (ANKJSONRequestOperation *)fetchUsersSubscribedToChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)fetchUsersSubscribedToChannelWithID:(NSString *)channelID completion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)fetchUserIDsSubscribedToChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)fetchUserIDsSubscribedToChannelWithID:(NSString *)channelID completion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)fetchUserIDsSubscribedToChannelIDs:(NSArray *)channelIDs completion:(ANKClientCompletionBlock)completionHandler;

- (ANKJSONRequestOperation *)fetchMutedChannelsForCurrentUserWithCompletion:(ANKClientCompletionBlock)completionHandler;

- (ANKJSONRequestOperation *)createChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)createChannelWithType:(NSString *)type readers:(ANKACL *)readersACL writers:(ANKACL *)writersACL completion:(ANKClientCompletionBlock)completionHandler;

- (ANKJSONRequestOperation *)updateChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)updateChannelWithID:(NSString *)channelID readers:(ANKACL *)readersACL writers:(ANKACL *)writersACL completion:(ANKClientCompletionBlock)completionHandler;

- (ANKJSONRequestOperation *)subscribeToChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)subscribeToChannelWithID:(NSString *)channelID completion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)unsubscribeToChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)unsubscribeToChannelWithID:(NSString *)channelID completion:(ANKClientCompletionBlock)completionHandler;

- (ANKJSONRequestOperation *)muteChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)muteChannelWithID:(NSString *)channelID completion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)unmuteChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (ANKJSONRequestOperation *)unmuteChannelWithID:(NSString *)channelID completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)fetchCurrentUserSubscribedChannelsWithCompletion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)fetchCurrentUserSubscribedChannelsWithTypes:(NSArray *)types completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)fetchCurrentUserPrivateMessageChannelsWithCompletion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)fetchCurrentUserCreatedChannelsWithCompletion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)fetchUnreadPMChannelsCountWithCompletion:(ANKClientCompletionBlock)completionHandler;

- (AFHTTPRequestOperation *)fetchChannelWithID:(NSString *)channelID completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)fetchChannelsWithIDs:(NSArray *)channelIDs completion:(ANKClientCompletionBlock)completionHandler;

- (AFHTTPRequestOperation *)fetchUsersSubscribedToChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)fetchUsersSubscribedToChannelWithID:(NSString *)channelID completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)fetchUserIDsSubscribedToChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)fetchUserIDsSubscribedToChannelWithID:(NSString *)channelID completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)fetchUserIDsSubscribedToChannelIDs:(NSArray *)channelIDs completion:(ANKClientCompletionBlock)completionHandler;

- (AFHTTPRequestOperation *)fetchMutedChannelsForCurrentUserWithCompletion:(ANKClientCompletionBlock)completionHandler;

- (AFHTTPRequestOperation *)createChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)createChannelWithType:(NSString *)type readers:(ANKACL *)readersACL writers:(ANKACL *)writersACL completion:(ANKClientCompletionBlock)completionHandler;

- (AFHTTPRequestOperation *)updateChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)updateChannelWithID:(NSString *)channelID readers:(ANKACL *)readersACL writers:(ANKACL *)writersACL completion:(ANKClientCompletionBlock)completionHandler;

- (AFHTTPRequestOperation *)subscribeToChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)subscribeToChannelWithID:(NSString *)channelID completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)unsubscribeToChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)unsubscribeToChannelWithID:(NSString *)channelID completion:(ANKClientCompletionBlock)completionHandler;

- (AFHTTPRequestOperation *)muteChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)muteChannelWithID:(NSString *)channelID completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)unmuteChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)unmuteChannelWithID:(NSString *)channelID completion:(ANKClientCompletionBlock)completionHandler;

- (AFHTTPRequestOperation *)deactivateChannel:(ANKChannel *)channel completion:(ANKClientCompletionBlock)completionHandler;
- (AFHTTPRequestOperation *)deactivateChannelWithID:(NSString *)channelID completion:(ANKClientCompletionBlock)completionHandler;

@end
Loading