From ebee043d87d1ceae6ebe7cad8225c96470762c1e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 1 Nov 2018 20:45:54 +0300 Subject: Local and Production Debug configurations --- Juick/APIClient.m | 22 ++++++++++++---------- Juick/Model/User.m | 4 ++-- Juick/Supporting Files/Juick-Info.plist | 13 +++++++++++++ Juick/Supporting Files/Local.xcconfig | 12 ++++++++++++ Juick/Supporting Files/Production.xcconfig | 12 ++++++++++++ 5 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 Juick/Supporting Files/Local.xcconfig create mode 100644 Juick/Supporting Files/Production.xcconfig (limited to 'Juick') 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 _Nonnull formData) { + [manager POST:@"post" parameters:nil constructingBodyWithBlock:^(id _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 _Nonnull formData) { + [manager POST:@"comment" parameters:nil constructingBodyWithBlock:^(id _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 _Nonnull formData) { + [manager POST:@"pm" parameters:nil constructingBodyWithBlock:^(id _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 diff --git a/Juick/Model/User.m b/Juick/Model/User.m index 1576a91..36a9b4c 100644 --- a/Juick/Model/User.m +++ b/Juick/Model/User.m @@ -32,7 +32,7 @@ +(void) checkIsValid:(void (^)(BOOL))callback { AFHTTPSessionManager *manager = [APIClient sharedClient].manager; [manager.requestSerializer setAuthorizationHeaderFieldWithUsername:[[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] password:[[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.password"]]; - [manager POST:@"/post" parameters:nil progress:nil success:nil failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + [manager POST:@"post" parameters:nil progress:nil success:nil failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSInteger statusCode = ((NSHTTPURLResponse *)task.response).statusCode; if (statusCode == 400) { callback(YES); @@ -45,7 +45,7 @@ +(void) get:(NSString *) name callback:(void(^)(User *))callback { AFHTTPSessionManager *manager = [APIClient sharedClient].manager; NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:name, @"uname", nil]; - [manager GET:@"/users" parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + [manager GET:@"users" parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { callback([User yy_modelWithJSON:[(NSArray *)responseObject firstObject]]); } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { callback(nil); diff --git a/Juick/Supporting Files/Juick-Info.plist b/Juick/Supporting Files/Juick-Info.plist index 3b9b7ba..5812a2d 100644 --- a/Juick/Supporting Files/Juick-Info.plist +++ b/Juick/Supporting Files/Juick-Info.plist @@ -2,6 +2,19 @@ + NSAppTransportSecurity + + NSExceptionDomains + + localhost + + NSExceptionAllowsInsecureHTTPLoads + + + + + base_url + ${API_BASE_URL} CFBundleDevelopmentRegion en CFBundleDisplayName diff --git a/Juick/Supporting Files/Local.xcconfig b/Juick/Supporting Files/Local.xcconfig new file mode 100644 index 0000000..d3b0acc --- /dev/null +++ b/Juick/Supporting Files/Local.xcconfig @@ -0,0 +1,12 @@ +// +// localhost.xcconfig +// Juick +// +// Created by Vitaly Takmazov on 01/11/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +// Configuration settings file format documentation can be found at: +// https://help.apple.com/xcode/#/dev745c5c974 + +API_BASE_URL = http:/$()/localhost:8080/api diff --git a/Juick/Supporting Files/Production.xcconfig b/Juick/Supporting Files/Production.xcconfig new file mode 100644 index 0000000..a57b0ad --- /dev/null +++ b/Juick/Supporting Files/Production.xcconfig @@ -0,0 +1,12 @@ +// +// Production.xcconfig +// Juick +// +// Created by Vitaly Takmazov on 01/11/2018. +// Copyright © 2018 com.juick. All rights reserved. +// + +// Configuration settings file format documentation can be found at: +// https://help.apple.com/xcode/#/dev745c5c974 + +API_BASE_URL = https:/$()/api.juick.com -- cgit v1.2.3