forked from orta/Puttio
/
PutIOClient.m
58 lines (46 loc) · 1.28 KB
/
PutIOClient.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// PutIOClient.m
// Puttio
//
// Created by orta therox on 23/03/2012.
// Copyright (c) 2012 ortatherox.com. All rights reserved.
//
#import "PutIOClient.h"
#import "AFJSONRequestOperation.h"
#import "ORAppDelegate.h"
#import "V1PutIOClient.h"
#import "V2PutIOClient.h"
// http://put.io/v2/docs/
NSString* API_ADDRESS = @"http://api.put.io/v2/";
@interface PutIOClient ()
@property(strong) V1PutIOClient *v1Client;
@property(strong) V2PutIOClient *v2Client;
@end
@implementation PutIOClient
@synthesize v1Client, v2Client;
+ (PutIOClient *)sharedClient {
static PutIOClient *_sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedClient = [[PutIOClient alloc] initWithBaseURL:[NSURL URLWithString:API_ADDRESS]];
});
return _sharedClient;
}
- (id)initWithBaseURL:(NSURL *)url {
self = [super initWithBaseURL:url];
if (!self) {
return nil;
}
self.v1Client = [V1PutIOClient sharedClient];
self.v2Client = [V2PutIOClient setup];
return self;
}
- (BOOL)ready {
return ([self.v1Client ready] && [self.v2Client ready]);
}
- (void)getUserInfo:(void(^)(id userInfoObject))onComplete {
[self.v1Client getUserInfo:^(id userInfoObject) {
onComplete(userInfoObject);
}];
}
@end