summaryrefslogtreecommitdiff
path: root/Juick/APIClient.m
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-01 20:45:54 +0300
committerGravatar Vitaly Takmazov2018-11-01 20:45:54 +0300
commitebee043d87d1ceae6ebe7cad8225c96470762c1e (patch)
tree813846d239bf0444d112afce6f281e94b4be1066 /Juick/APIClient.m
parent9a0a039c5df78526bba67f6bef93e431cf94430a (diff)
Local and Production Debug configurations
Diffstat (limited to 'Juick/APIClient.m')
-rw-r--r--Juick/APIClient.m22
1 files changed, 12 insertions, 10 deletions
diff --git a/Juick/APIClient.m b/Juick/APIClient.m
index 5c21f19..6d9878d 100644
--- a/Juick/APIClient.m
+++ b/Juick/APIClient.m
@@ -27,7 +27,9 @@
-(id)init {
if (self = [super init]) {
- self.manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.juick.com"]];
+ NSString *baseURLString = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"base_url"];
+ NSLog(@"Initializing with %@ base URL", baseURLString);
+ self.manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:baseURLString]];
self.manager.requestSerializer = [AFJSONRequestSerializer new];
[self.manager.requestSerializer setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
self.backgroundQueue = [NSOperationQueue new];
@@ -65,7 +67,7 @@
-(void) postMessage:(NSString *)text result:(void (^)(Message *, NSError *))callback {
AFHTTPSessionManager *manager = [APIClient sharedClient].manager;
[self.backgroundQueue addOperationWithBlock:^{
- [manager POST:@"/post" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
+ [manager POST:@"post" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
[formData appendPartWithFormData:[text dataUsingEncoding:NSUTF8StringEncoding] name:@"body"];
} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"Success!");
@@ -85,7 +87,7 @@
-(void) postReplyToThread:(NSNumber *)mid inReplyTo:(NSNumber *)rid text:(NSString *)text result:(void(^)(Message *, NSError *))callback {
AFHTTPSessionManager *manager = [APIClient sharedClient].manager;
[self.backgroundQueue addOperationWithBlock:^{
- [manager POST:@"/comment" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
+ [manager POST:@"comment" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
[formData appendPartWithFormData:[[mid stringValue] dataUsingEncoding:NSUTF8StringEncoding] name:@"mid"];
[formData appendPartWithFormData:[[NSString stringWithFormat:@"%d", [rid intValue]] dataUsingEncoding:NSUTF8StringEncoding] name:@"rid"];
[formData appendPartWithFormData:[text dataUsingEncoding:NSUTF8StringEncoding] name:@"body"];
@@ -106,7 +108,7 @@
-(void) postPMToUser:(NSString *)uname text:(NSString *)text result:(void (^)(NSError *))callback {
AFHTTPSessionManager *manager = [APIClient sharedClient].manager;
[self.backgroundQueue addOperationWithBlock:^{
- [manager POST:@"/pm" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
+ [manager POST:@"pm" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
[formData appendPartWithFormData:[text dataUsingEncoding:NSUTF8StringEncoding] name:@"body"];
[formData appendPartWithFormData:[uname dataUsingEncoding:NSUTF8StringEncoding] name:@"uname"];
} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
@@ -125,7 +127,7 @@
-(void) fetchChats:(void (^)(NSArray *, NSError *))callback {
AFHTTPSessionManager *manager = [APIClient sharedClient].manager;
[self.backgroundQueue addOperationWithBlock:^{
- [manager GET:@"/groups_pms" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
+ [manager GET:@"groups_pms" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSMutableArray *groups = [NSMutableArray new];
NSArray *pms = [(NSDictionary *)responseObject objectForKey:@"pms"];
[pms enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
@@ -146,7 +148,7 @@
AFHTTPSessionManager *manager = [APIClient sharedClient].manager;
NSDictionary *params = @{@"uname": uname};
[self.backgroundQueue addOperationWithBlock:^{
- [manager GET:@"/pm" parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
+ [manager GET:@"pm" parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSMutableArray *messages = [NSMutableArray new];
NSArray *messagesList = (NSArray *)responseObject;
[messagesList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
@@ -166,19 +168,19 @@
+(NSString *) messagesUrl {
- return @"/messages";
+ return @"messages";
}
+(NSString *) discussionsUrl {
- return @"/messages/discussions";
+ return @"messages/discussions";
}
+(NSString *) threadUrl {
- return @"/thread";
+ return @"thread";
}
+(NSString *) feedUrl {
- return @"/home";
+ return @"home";
}
@end