Skip to content
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

Minor changes to adjust to API spec. #202

Merged
merged 4 commits into from
Feb 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 16 additions & 4 deletions ably-ios/ARTConnectionDetails.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,22 @@

ART_ASSUME_NONNULL_BEGIN

@property (readonly, strong, nonatomic, nullable) NSString *clientId;
@property (readonly, strong, nonatomic, nullable) NSString *connectionKey;

- (instancetype)initWithClientId:(NSString *__art_nullable)clientId connectionKey:(NSString *__art_nullable)connectionKey;
@property (readonly, strong, nonatomic, art_nullable) NSString *clientId;
@property (readonly, strong, nonatomic, art_nullable) NSString *connectionKey;
// In those, -1 means 'undefined'.
@property (readonly, nonatomic) NSInteger maxMessageSize;
@property (readonly, nonatomic) NSInteger maxFrameSize;
@property (readonly, nonatomic) NSInteger maxInboundRate;
@property (readonly, nonatomic) NSTimeInterval connectionStateTtl;
@property (readonly, strong, nonatomic, art_nullable) NSString *serverId;

- (instancetype)initWithClientId:(NSString *__art_nullable)clientId
connectionKey:(NSString *__art_nullable)connectionKey
maxMessageSize:(NSInteger)maxMessageSize
maxFrameSize:(NSInteger)maxFrameSize
maxInboundRate:(NSInteger)maxInboundRate
connectionStateTtl:(NSTimeInterval)connectionStateTtl
serverId:(NSString *)serverId;

ART_ASSUME_NONNULL_END

Expand Down
13 changes: 12 additions & 1 deletion ably-ios/ARTConnectionDetails.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@

@implementation ARTConnectionDetails

- (instancetype)initWithClientId:(NSString *__art_nullable)clientId connectionKey:(NSString *__art_nullable)connectionKey {
- (instancetype)initWithClientId:(NSString *__art_nullable)clientId
connectionKey:(NSString *__art_nullable)connectionKey
maxMessageSize:(NSInteger)maxMessageSize
maxFrameSize:(NSInteger)maxFrameSize
maxInboundRate:(NSInteger)maxInboundRate
connectionStateTtl:(NSTimeInterval)connectionStateTtl
serverId:(NSString *)serverId {
if (self == [super init]) {
_clientId = clientId;
_connectionKey = connectionKey;
_maxMessageSize = maxMessageSize;
_maxFrameSize = maxFrameSize;
_maxInboundRate = maxInboundRate;
_connectionStateTtl = connectionStateTtl;
_serverId = serverId;
}
return self;
}
Expand Down
7 changes: 6 additions & 1 deletion ably-ios/ARTJsonEncoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,12 @@ - (ARTConnectionDetails *)connectionDetailsFromDictionary:(NSDictionary *)input
}

return [[ARTConnectionDetails alloc] initWithClientId:[input artString:@"clientId"]
connectionKey:[input artString:@"connectionKey"]];
connectionKey:[input artString:@"connectionKey"]
maxMessageSize:[input artInteger:@"maxMessageSize"]
maxFrameSize:[input artInteger:@"maxFrameSize"]
maxInboundRate:[input artInteger:@"maxInboundRate"]
connectionStateTtl:(NSTimeInterval)[input artInteger:@"connectionStateTtl"]
serverId:[input artString:@"serverId"]];
}

- (NSArray *)statsFromArray:(NSArray *)input {
Expand Down
1 change: 1 addition & 0 deletions ably-ios/ARTNSDictionary+ARTDictionaryUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- (NSDate *)artDate:(id)key;
- (NSArray *)artArray:(id)key;
- (NSDictionary *)artDictionary:(id)key;
- (NSInteger)artInteger:(id)key;

- (id)artTyped:(Class)cls key:(id)key;

Expand Down
8 changes: 8 additions & 0 deletions ably-ios/ARTNSDictionary+ARTDictionaryUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ - (id)artTyped:(Class)cls key:(id)key {
return nil;
}

- (NSInteger)artInteger:(id)key {
NSNumber *number = [self artNumber:key];
if (!key) {
return -1;
}
return [number integerValue];
}

@end
5 changes: 0 additions & 5 deletions ably-ios/ARTPaginatedResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,12 @@ ART_ASSUME_NONNULL_BEGIN
typedef void(^ARTPaginatedResultCallback)(__GENERIC(ARTPaginatedResult, ItemType) *__art_nullable result, NSError *__art_nullable error);

@property (nonatomic, strong, readonly) __GENERIC(NSArray, ItemType) *items;

@property (nonatomic, readonly) BOOL hasFirst;
@property (nonatomic, readonly) BOOL hasCurrent;
@property (nonatomic, readonly) BOOL hasNext;

@property (nonatomic, readonly) BOOL isLast;

- (instancetype)init UNAVAILABLE_ATTRIBUTE;

- (void)first:(ARTPaginatedResultCallback)callback;
- (void)current:(ARTPaginatedResultCallback)callback;
- (void)next:(ARTPaginatedResultCallback)callback;

@end
Expand Down
6 changes: 0 additions & 6 deletions ably-ios/ARTPaginatedResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ - (instancetype)initWithItems:(NSArray *)items
_items = items;

_relFirst = relFirst;
_hasFirst = !!relFirst;

_relCurrent = relCurrent;
_hasCurrent = !!relCurrent;

_relNext = relNext;
_hasNext = !!relNext;
Expand All @@ -50,10 +48,6 @@ - (void)first:(ARTPaginatedResultCallback)callback {
[self.class executePaginated:_rest withRequest:_relFirst andResponseProcessor:_responseProcessor callback:callback];
}

- (void)current:(ARTPaginatedResultCallback)callback {
[self.class executePaginated:_rest withRequest:_relCurrent andResponseProcessor:_responseProcessor callback:callback];
}

- (void)next:(ARTPaginatedResultCallback)callback {
[self.class executePaginated:_rest withRequest:_relNext andResponseProcessor:_responseProcessor callback:callback];
}
Expand Down
2 changes: 2 additions & 0 deletions ably-ios/ARTPresenceMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ typedef NS_ENUM(NSUInteger, ARTPresenceAction) {

@property (readwrite, assign, nonatomic) ARTPresenceAction action;

- (NSString *)memberKey;

@end
4 changes: 4 additions & 0 deletions ably-ios/ARTPresenceMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ - (NSString *)description {
return description;
}

- (NSString *)memberKey {
return [NSString stringWithFormat:@"%@:%@", self.connectionId, self.clientId];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it return an empty string if the connectionId or clientId are nil?
It will return (null):(null) if both properties are nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In PresenceMessage both connectionId and clientId are defined as non-nullable, so that's something we don't have to worry about.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry. I thought both were nullable.

}

@end
2 changes: 2 additions & 0 deletions ably-ios/ARTRealtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Instance the Ably library using a key only. This is simply a convenience constru
*/
- (instancetype)initWithKey:(NSString *)key;

- (instancetype)initWithToken:(NSString *)token;

/**
Instance the Ably library with the given options.
:param options: see ARTClientOptions for options
Expand Down
4 changes: 4 additions & 0 deletions ably-ios/ARTRealtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ - (instancetype)initWithKey:(NSString *)key {
return [self initWithOptions:[[ARTClientOptions alloc] initWithKey:key]];
}

- (instancetype)initWithToken:(NSString *)token {
return [self initWithOptions:[[ARTClientOptions alloc] initWithToken:token]];
}

- (instancetype)initWithLogger:(ARTLog *)logger andOptions:(ARTClientOptions *)options {
self = [super init];
if (self) {
Expand Down
9 changes: 0 additions & 9 deletions ably-iosTests/ARTRealtimeChannelHistoryTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ -(void) testHistoryForwardPagination {

[channel history:query callback:^(ARTPaginatedResult *result, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result hasFirst]);
XCTAssertTrue([result hasNext]);
NSArray * items = [result items];
XCTAssertEqual([items count], 2);
Expand All @@ -196,7 +195,6 @@ -(void) testHistoryForwardPagination {
XCTAssertEqualObjects(@"testString1", [secondMessage content]);
[result next:^(ARTPaginatedResult *result2, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result2 hasFirst]);
NSArray * items = [result2 items];
XCTAssertEqual([items count], 2);
ARTMessage * firstMessage = [items objectAtIndex:0];
Expand All @@ -206,15 +204,13 @@ -(void) testHistoryForwardPagination {

[result2 next:^(ARTPaginatedResult *result3, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result3 hasFirst]);
XCTAssertFalse([result3 hasNext]);
NSArray * items = [result3 items];
XCTAssertEqual([items count], 1);
ARTMessage * firstMessage = [items objectAtIndex:0];
XCTAssertEqualObjects(@"testString4", [firstMessage content]);
[result3 first:^(ARTPaginatedResult *result4, NSError *error) {
XCTAssertEqual(ARTStateOk, status.state);
XCTAssertTrue([result4 hasFirst]);
XCTAssertTrue([result4 hasNext]);
NSArray * items = [result4 items];
XCTAssertEqual([items count], 2);
Expand Down Expand Up @@ -247,7 +243,6 @@ -(void) testHistoryBackwardPagination {

[channel history:query callback:^(ARTPaginatedResult *result, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result hasFirst]);
XCTAssertTrue([result hasNext]);
NSArray * items = [result items];
XCTAssertEqual([items count], 2);
Expand All @@ -257,7 +252,6 @@ -(void) testHistoryBackwardPagination {
XCTAssertEqualObjects(@"testString3", [secondMessage content]);
[result next:^(ARTPaginatedResult *result2, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result2 hasFirst]);
NSArray * items = [result2 items];
XCTAssertEqual([items count], 2);
ARTMessage * firstMessage = [items objectAtIndex:0];
Expand All @@ -268,15 +262,13 @@ -(void) testHistoryBackwardPagination {

[result2 next:^(ARTPaginatedResult *result3, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result3 hasFirst]);
XCTAssertFalse([result3 hasNext]);
NSArray * items = [result3 items];
XCTAssertEqual([items count], 1);
ARTMessage * firstMessage = [items objectAtIndex:0];
XCTAssertEqualObjects(@"testString0", [firstMessage content]);
[result3 first:^(ARTPaginatedResult *result4, NSError *error) {
XCTAssertEqual(ARTStateOk, status.state);
XCTAssertTrue([result4 hasFirst]);
XCTAssertTrue([result4 hasNext]);
NSArray * items = [result4 items];
XCTAssertEqual([items count], 2);
Expand All @@ -286,7 +278,6 @@ -(void) testHistoryBackwardPagination {
XCTAssertEqualObjects(@"testString3", [secondMessage content]);
[result2 first:^(ARTPaginatedResult *result, NSError *error) {
XCTAssertEqual(ARTStateOk, status.state);
XCTAssertTrue([result hasFirst]);
XCTAssertTrue([result hasNext]);
NSArray * items = [result items];
XCTAssertEqual([items count], 2);
Expand Down
10 changes: 0 additions & 10 deletions ably-iosTests/ARTRestChannelHistoryTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ - (void)testHistoryForwardPagination {

[channel history:query callback:^(ARTPaginatedResult *result, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result hasFirst]);
XCTAssertTrue([result hasNext]);
NSArray *page = [result items];
XCTAssertEqual([page count], 2);
Expand All @@ -210,7 +209,6 @@ - (void)testHistoryForwardPagination {

[result next:^(ARTPaginatedResult *result2, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result2 hasFirst]);
NSArray * page = [result2 items];
XCTAssertEqual([page count], 2);
ARTMessage * firstMessage = [page objectAtIndex:0];
Expand All @@ -220,7 +218,6 @@ - (void)testHistoryForwardPagination {

[result2 next:^(ARTPaginatedResult *result3, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result3 hasFirst]);
XCTAssertFalse([result3 hasNext]);
NSArray * page = [result3 items];
XCTAssertEqual([page count], 1);
Expand All @@ -229,7 +226,6 @@ - (void)testHistoryForwardPagination {

[result3 first:^(ARTPaginatedResult *result4, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result4 hasFirst]);
XCTAssertTrue([result4 hasNext]);
NSArray * page = [result4 items];
XCTAssertEqual([page count], 2);
Expand Down Expand Up @@ -266,7 +262,6 @@ - (void)testHistoryBackwardPagination {

[channel history:query callback:^(ARTPaginatedResult *result, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result hasFirst]);
XCTAssertTrue([result hasNext]);
NSArray * page = [result items];
XCTAssertEqual([page count], 2);
Expand All @@ -277,7 +272,6 @@ - (void)testHistoryBackwardPagination {

[result next:^(ARTPaginatedResult *result2, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result2 hasFirst]);
NSArray * page = [result2 items];
XCTAssertEqual([page count], 2);
ARTMessage * firstMessage = [page objectAtIndex:0];
Expand All @@ -288,7 +282,6 @@ - (void)testHistoryBackwardPagination {

[result2 next:^(ARTPaginatedResult *result3, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result3 hasFirst]);
XCTAssertFalse([result3 hasNext]);
NSArray * page = [result3 items];
XCTAssertEqual([page count], 1);
Expand All @@ -297,7 +290,6 @@ - (void)testHistoryBackwardPagination {

[result3 first:^(ARTPaginatedResult *result4, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result4 hasFirst]);
XCTAssertTrue([result4 hasNext]);
NSArray * page = [result4 items];
XCTAssertEqual([page count], 2);
Expand Down Expand Up @@ -333,7 +325,6 @@ - (void)testHistoryBackwardDefault {

[channel history:query callback:^(ARTPaginatedResult *result, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result hasFirst]);
XCTAssertTrue([result hasNext]);
NSArray * page = [result items];
XCTAssertEqual([page count], 2);
Expand Down Expand Up @@ -373,7 +364,6 @@ -(void) testHistoryTwoClients {

[channelTwo history:query callback:^(ARTPaginatedResult *result, NSError *error) {
XCTAssert(!error);
XCTAssertTrue([result hasFirst]);
XCTAssertTrue([result hasNext]);
NSArray * page = [result items];
XCTAssertEqual([page count], 2);
Expand Down
2 changes: 0 additions & 2 deletions ablySpec/RestClientStats.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ class RestClientStats: QuickSpec {
let thirdPage = getPage(secondPage.next)
expect(thirdPage.items.count).to(equal(1))
expect((thirdPage.items as! [ARTStats])[0].inbound.all.messages.data).to(equal(5000))
expect(thirdPage.hasFirst).to(beTrue())
expect(thirdPage.isLast).to(beTrue())

let firstPageAgain = getPage(thirdPage.first)
Expand Down Expand Up @@ -299,7 +298,6 @@ class RestClientStats: QuickSpec {
let thirdPage = getPage(secondPage.next)
expect(thirdPage.items.count).to(equal(1))
expect((thirdPage.items as! [ARTStats])[0].inbound.all.messages.data).to(equal(7000))
expect(thirdPage.hasFirst).to(beTrue())
expect(thirdPage.isLast).to(beTrue())

let firstPageAgain = getPage(thirdPage.first)
Expand Down