summaryrefslogtreecommitdiff
path: root/Juick
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
parent9a0a039c5df78526bba67f6bef93e431cf94430a (diff)
Local and Production Debug configurations
Diffstat (limited to 'Juick')
-rw-r--r--Juick/APIClient.m22
-rw-r--r--Juick/Model/User.m4
-rw-r--r--Juick/Supporting Files/Juick-Info.plist13
-rw-r--r--Juick/Supporting Files/Local.xcconfig12
-rw-r--r--Juick/Supporting Files/Production.xcconfig12
5 files changed, 51 insertions, 12 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
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 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
+ <key>NSAppTransportSecurity</key>
+ <dict>
+ <key>NSExceptionDomains</key>
+ <dict>
+ <key>localhost</key>
+ <dict>
+ <key>NSExceptionAllowsInsecureHTTPLoads</key>
+ <true/>
+ </dict>
+ </dict>
+ </dict>
+ <key>base_url</key>
+ <string>${API_BASE_URL}</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
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