Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Construct all the server call URLs using string concatenation #30

Merged
merged 1 commit into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="cordova-plugin-em-server-communication"
version="1.2.3">
version="1.2.4">

<name>ServerComm</name>
<description>Abstraction for communication settings, and for making both GET
Expand Down
1 change: 0 additions & 1 deletion src/ios/BEMCommunicationHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
+(void)createUserProfile:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler;
+(void)getUnclassifiedSections:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler;
+(void)setClassifiedSections:(NSArray*)sectionDicts completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler;
+(void)movesCallback:(NSMutableDictionary*)movesParams completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler;
+(void)phone_to_server:(NSArray*) entriesToPush completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler;;

// Generic GET and POST methods
Expand Down
40 changes: 14 additions & 26 deletions src/ios/BEMCommunicationHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
static NSString* kUncommittedSectionsPath = @"/tripManager/getUnclassifiedSections";
static NSString* kUsercachePutPath = @"/usercache/put";
static NSString* kSaveSectionsPath = @"/tripManager/setSectionClassification";
static NSString* kMovesCallbackPath = @"/movesCallback";
static NSString* kSetStatsPath = @"/stats/set";
static NSString* kCustomSettingsPath = @"/profile/settings";
static NSString* kRegisterPath = @"/profile/create";
Expand All @@ -39,8 +38,8 @@ @implementation CommunicationHelper
+(void)getCustomSettings:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler {
NSLog(@"CommunicationHelper.getCustomSettings called!");
NSMutableDictionary *blankDict = [[NSMutableDictionary alloc] init];
NSURL *kBaseURL = [[ConnectionSettings sharedInstance] getConnectUrl];
NSURL *kCustomSettingsURL = [NSURL URLWithString:kCustomSettingsPath relativeToURL:kBaseURL];
NSString *kBaseURLString = [[ConnectionSettings sharedInstance] getConnectString];
NSURL *kCustomSettingsURL = [NSURL URLWithString:[kBaseURLString stringByAppendingString:kCustomSettingsPath]];

CommunicationHelper *executor = [[CommunicationHelper alloc] initPost:kCustomSettingsURL data:blankDict completionHandler:completionHandler];
[executor execute];
Expand All @@ -49,8 +48,8 @@ +(void)getCustomSettings:(void (^)(NSData *data, NSURLResponse *response, NSErro
+(void)createUserProfile:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler {
NSLog(@"CommunicationHelper.getCustomSettings called!");
NSMutableDictionary *blankDict = [[NSMutableDictionary alloc] init];
NSURL *kBaseURL = [[ConnectionSettings sharedInstance] getConnectUrl];
NSURL *kRegisterPathURL = [NSURL URLWithString:kRegisterPath relativeToURL:kBaseURL];
NSString *kBaseURLString = [[ConnectionSettings sharedInstance] getConnectString];
NSURL *kRegisterPathURL = [NSURL URLWithString:[kBaseURLString stringByAppendingString:kRegisterPath]];

CommunicationHelper *executor = [[CommunicationHelper alloc] initPost:kRegisterPathURL data:blankDict completionHandler:completionHandler];
[executor execute];
Expand All @@ -59,39 +58,27 @@ +(void)createUserProfile:(void (^)(NSData *data, NSURLResponse *response, NSErro
+(void)getUnclassifiedSections:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler {
NSLog(@"CommunicationHelper.getUnclassifiedSections called!");
NSMutableDictionary *blankDict = [[NSMutableDictionary alloc] init];
NSURL* kBaseURL = [[ConnectionSettings sharedInstance] getConnectUrl];
NSURL* kUncommittedSectionsURL = [NSURL URLWithString:kUncommittedSectionsPath
relativeToURL:kBaseURL];
NSString* kBaseURLString = [[ConnectionSettings sharedInstance] getConnectString];
NSURL* kUncommittedSectionsURL = [NSURL URLWithString:[kBaseURLString stringByAppendingString:kUncommittedSectionsPath]];
CommunicationHelper *executor = [[CommunicationHelper alloc] initPost:kUncommittedSectionsURL data:blankDict completionHandler:completionHandler];
[executor execute];
}

+(void)setClassifiedSections:(NSArray*)sectionDicts completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler {
NSMutableDictionary *toPush = [[NSMutableDictionary alloc] init];
[toPush setObject:sectionDicts forKey:@"updates"];
NSURL* kBaseURL = [[ConnectionSettings sharedInstance] getConnectUrl];
NSURL* kSaveSectionsURL = [NSURL URLWithString:kSaveSectionsPath
relativeToURL:kBaseURL];
NSString* kBaseURLString = [[ConnectionSettings sharedInstance] getConnectString];
NSURL* kSaveSectionsURL = [NSURL URLWithString:[kBaseURLString stringByAppendingString:kSaveSectionsPath]];
CommunicationHelper *executor = [[CommunicationHelper alloc] initPost:kSaveSectionsURL data:toPush completionHandler:completionHandler];
[executor execute];
}

+(void)movesCallback:(NSMutableDictionary*)movesParams completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler {
NSURL* kBaseURL = [[ConnectionSettings sharedInstance] getConnectUrl];
NSURL* kMovesCallbackURL = [NSURL URLWithString:kMovesCallbackPath
relativeToURL:kBaseURL];

CommunicationHelper *executor = [[CommunicationHelper alloc] initPost:kMovesCallbackURL data:movesParams completionHandler:completionHandler];
[executor execute];
}

+(void)phone_to_server:(NSArray *)entriesToPush completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler {
NSMutableDictionary *toPush = [[NSMutableDictionary alloc] init];
[toPush setObject:entriesToPush forKey:@"phone_to_server"];

NSURL* kBaseURL = [[ConnectionSettings sharedInstance] getConnectUrl];
NSURL* kUsercachePutURL = [NSURL URLWithString:kUsercachePutPath
relativeToURL:kBaseURL];
NSString* kBaseURLString = [[ConnectionSettings sharedInstance] getConnectString];
NSURL* kUsercachePutURL = [NSURL URLWithString:[kBaseURLString stringByAppendingString:kUsercachePutPath]];

CommunicationHelper *executor = [[CommunicationHelper alloc] initPost:kUsercachePutURL data:toPush completionHandler:completionHandler];
[executor execute];
Expand All @@ -100,9 +87,10 @@ +(void)phone_to_server:(NSArray *)entriesToPush completionHandler:(void (^)(NSDa
+(void)pushGetJSON:(NSDictionary*)toSend toURL:(NSString*)relativeURL completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler {
NSMutableDictionary *toPush = [NSMutableDictionary dictionaryWithDictionary:toSend];

NSURL* kBaseURL = [[ConnectionSettings sharedInstance] getConnectUrl];
NSURL* absoluteURL = [NSURL URLWithString:relativeURL
relativeToURL:kBaseURL];
NSString* kBaseURLString = [[ConnectionSettings sharedInstance] getConnectString];
NSString* absoluteURLString = [kBaseURLString stringByAppendingString:relativeURL];
NSURL* absoluteURL = [NSURL URLWithString:absoluteURLString];
// NSLog(@"absoluteURL right after creation = %@", [absoluteURL absoluteURL]);

CommunicationHelper *executor = [[CommunicationHelper alloc] initPost:absoluteURL data:toPush completionHandler:completionHandler];
[executor execute];
Expand Down