Skip to content

Commit

Permalink
Merge pull request #15 from thevixac/master
Browse files Browse the repository at this point in the history
Presence Map, Fallback and Exceptions
  • Loading branch information
mattheworiordan committed Aug 8, 2015
2 parents 28ada7b + 15e80b6 commit 71489c9
Show file tree
Hide file tree
Showing 78 changed files with 5,769 additions and 2,868 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
An iOS client library for [ably.io](https://www.ably.io), the realtime messaging service, written in Objective-C.

## CocoaPod Installation
add pod ably to your Podfile. While ably-ios is in development, use this line instead:
* pod "ably", :git => 'https://github.com/thevixac/ably-ios.git', :commit => 'be670f5e6c3'
add pod ably to your Podfile.

## Manual Installation

Expand All @@ -31,25 +30,27 @@ add pod ably to your Podfile. While ably-ios is in development, use this line in

```
ARTRealtimeChannel * channel = [client channel:@"test"];
[channel subscribe:^(ARTMessage * message) {
NSString * content =[message content];
NSLog(@" message is %@", content);
[channel subscribe:^(ARTMessage *message) {
NSString *content =[message content];
NSLog(@"message is %@", content);
}];
```

### Publishing to a channel
```
[channel publish:@"Hello, Channel!" cb:^(ARTStatus status) {
if(status != ARTStatusOk) {
[channel publish:@"Hello, Channel!" cb:^(ARTStatus *status) {
if(status.status != ARTStatusOk) {
//something went wrong.
}
}];
```

### Querying the History
```
[channel history:^(ARTStatus status, id<ARTPaginatedResult> messagesPage) {
XCTAssertEqual(status, ARTStatusOk);
[channel history:^(ARTStatus *status, id<ARTPaginatedResult> messagesPage) {
if(status.status != ARTStatusOk) {
//something went wrong.
}
NSArray *messages = [messagesPage currentItems];
NSLog(@"this page has %d messages", [messages count]);
ARTMessage *message = messages[0];
Expand All @@ -65,7 +66,7 @@ ARTRealtimeChannel * channel = [client channel:@"test"];
options.clientId = @"john.doe";
ARTRealtime * client = [[ARTRealtime alloc] initWithOptions:options];
ARTRealtimeChannel * channel = [client channel:@"test"];
[channel publishPresenceEnter:@"I'm here" cb:^(ARTStatus status) {
[channel publishPresenceEnter:@"I'm here" cb:^(ARTStatus *status) {
if(status != ARTStatusOk) {
//something went wrong
}
Expand All @@ -74,7 +75,10 @@ ARTRealtimeChannel * channel = [client channel:@"test"];

### Querying the Presence History
```
[channel presenceHistory:^(ARTStatus status, id<ARTPaginatedResult> presencePage) {
[channel presenceHistory:^(ARTStatus *status, id<ARTPaginatedResult> presencePage) {
if(status.status != ARTStatusOk) {
//something went wrong
}
NSArray *messages = [presencePage currentItems];
if(messages) {
ARTPresenceMessage *firstMessage = messages[0];
Expand All @@ -92,8 +96,8 @@ ARTRealtimeChannel * channel = [client channel:@"test"];

## Publishing a message to a channel
```
[channel publish:@"Hello, channel!" cb:^(ARTStatus status){
if(status != ARTStatusOk) {
[channel publish:@"Hello, channel!" cb:^(ARTStatus *status){
if(status.status != ARTStatusOk) {
//something went wrong
}
}];
Expand All @@ -109,10 +113,6 @@ The following features are not implemented yet:

* msgpack transportation

The following features are do not have sufficient test coverage:

* app stats

## Support and feedback

Please visit https://support.ably.io/ for access to our knowledgebase and to ask for any assistance.
Expand Down
25 changes: 15 additions & 10 deletions ably-ios/ARTAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

@class ARTRest;

@class ARTLog;
@interface ARTTokenDetails : NSObject

@property (readonly, strong, nonatomic) NSString *token;
Expand All @@ -25,8 +26,6 @@

- (instancetype)initWithId:(NSString *)id expires:(int64_t)expires issued:(int64_t)issued capability:(NSString *)capability clientId:(NSString *)clientId;

+ (instancetype)authTokenWithId:(NSString *)id expires:(int64_t)expires issued:(int64_t)issued capability:(NSString *)capability clientId:(NSString *)clientId;

@end

@interface ARTAuthTokenParams : NSObject
Expand All @@ -44,12 +43,10 @@

- (instancetype)initWithId:(NSString *)id ttl:(int64_t)ttl capability:(NSString *)capability clientId:(NSString *)clientId timestamp:(int64_t)timestamp nonce:(NSString *)nonce mac:(NSString *)mac;

+ (instancetype)authTokenParamsWithId:(NSString *)id ttl:(int64_t)ttl capability:(NSString *)capability clientId:(NSString *)clientId timestamp:(int64_t)timestamp nonce:(NSString *)nonce mac:(NSString *)mac;

-(NSDictionary *) asDictionary;
@end

typedef id<ARTCancellable>(^ARTAuthCb)(void(^continuation)(ARTStatus,ARTTokenDetails *));
typedef id<ARTCancellable>(^ARTAuthCb)(void(^continuation)(ARTStatus *,ARTTokenDetails *));
typedef id<ARTCancellable>(^ARTSignedTokenRequestCb)(ARTAuthTokenParams *, void(^continuation)(ARTAuthTokenParams *));
typedef NS_ENUM(NSUInteger, ARTAuthMethod) {
ARTAuthMethodBasic,
Expand All @@ -58,17 +55,22 @@ typedef NS_ENUM(NSUInteger, ARTAuthMethod) {

@interface ARTAuthOptions : NSObject

@property (nonatomic, weak) ARTLog * logger;
@property (readwrite, strong, nonatomic) ARTAuthCb authCallback;
@property (readwrite, strong, nonatomic) ARTSignedTokenRequestCb signedTokenRequestCallback;
@property (readwrite, strong, nonatomic) ARTAuthTokenParams *tokenParams;
@property (readwrite, strong, nonatomic) NSURL *authUrl;
@property (readwrite, strong, nonatomic) NSString *keyName;
@property (readwrite, strong, nonatomic) NSString *keySecret;
@property (readwrite, strong, nonatomic) NSString *token;
@property (readwrite, strong, nonatomic) NSString *capability;
@property (readwrite, strong, nonatomic) NSString *nonce;
@property (readwrite, assign, nonatomic) int64_t ttl;
@property (readwrite, strong, nonatomic) NSDictionary *authHeaders;
@property (readwrite, strong, nonatomic) NSString *clientId;
@property (readwrite, assign, nonatomic) BOOL queryTime;
@property (readwrite, assign, nonatomic) BOOL useTokenAuth;
@property (readwrite, assign, nonatomic) ARTTokenDetails * tokenDetails;


- (instancetype)init;
Expand All @@ -83,14 +85,17 @@ typedef NS_ENUM(NSUInteger, ARTAuthMethod) {

@interface ARTAuth : NSObject

- (instancetype)initWithRest:(ARTRest *)rest options:(ARTAuthOptions *)options;
- (instancetype)initWithRest:(ARTRest *) rest options:(ARTAuthOptions *) options;
- (ARTAuthOptions *)getAuthOptions;
- (ARTAuthMethod)getAuthMethod;


- (ARTAuthMethod) getAuthMethod;
- (ARTAuthTokenParams *) getTokenParams;
- (id<ARTCancellable>)authHeadersUseBasic:(BOOL)useBasic cb:(id<ARTCancellable>(^)(NSDictionary *))cb;
- (id<ARTCancellable>)authParams:(id<ARTCancellable>(^)(NSDictionary *))cb;
- (id<ARTCancellable>)authToken:(id<ARTCancellable>(^)(ARTTokenDetails *))cb;
- (id<ARTCancellable>)requestToken:(id<ARTCancellable>(^)(ARTTokenDetails *))cb;
- (id<ARTCancellable>)authTokenForceReauth:(BOOL)force cb:(id<ARTCancellable>(^)(ARTTokenDetails *))cb;
- (void)attemptTokenFetch:(void (^)()) cb;
- (bool)canRequestToken;


+ (ARTSignedTokenRequestCb)defaultSignedTokenRequestCallback:(ARTAuthOptions *)authOptions rest:(ARTRest *)rest;
@end
Loading

0 comments on commit 71489c9

Please sign in to comment.