-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from shankari/restore_hardcoded_jwt
Restore hardcoded jwt
- Loading branch information
Showing
8 changed files
with
163 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package edu.berkeley.eecs.emission.cordova.comm; | ||
|
||
import org.apache.cordova.*; | ||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import android.content.Context; | ||
import edu.berkeley.eecs.emission.cordova.comm.CommunicationHelper; | ||
import edu.berkeley.eecs.emission.cordova.connectionsettings.ConnectionSettings; | ||
|
||
public class CommunicationHelperPlugin extends CordovaPlugin { | ||
@Override | ||
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException { | ||
if (action.equals("pushGetJSON")) { | ||
try { | ||
Context ctxt = cordova.getActivity(); | ||
String relativeURL = data.getString(0); | ||
JSONObject filledMessage = data.getJSONObject(1); | ||
|
||
String commuteTrackerHost = ConnectionSettings.getConnectURL(ctxt); | ||
String fullURL = commuteTrackerHost + relativeURL; | ||
|
||
String resultString = CommunicationHelper.pushGetJSON(ctxt, fullURL, filledMessage); | ||
callbackContext.success(new JSONObject(resultString)); | ||
} catch (Exception e) { | ||
callbackContext.error("While pushing/getting from server "+e.getMessage()); | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#import <Cordova/CDV.h> | ||
|
||
@interface BEMCommunicationHelperPlugin: CDVPlugin <UINavigationControllerDelegate> | ||
|
||
- (void) pushGetJSON:(CDVInvokedUrlCommand*)command; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#import "BEMCommunicationHelperPlugin.h" | ||
#import "BEMCommunicationHelper.h" | ||
|
||
@implementation BEMCommunicationHelperPlugin | ||
|
||
- (void)pushGetJSON:(CDVInvokedUrlCommand *)command | ||
{ | ||
NSString* callbackId = [command callbackId]; | ||
|
||
@try { | ||
NSString* relativeURL = [[command arguments] objectAtIndex:0]; | ||
NSDictionary* filledMessage = [[command arguments] objectAtIndex:1]; | ||
|
||
[CommunicationHelper pushGetJSON:filledMessage toURL:relativeURL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { | ||
if (error != NULL) { | ||
[self sendError:error callBackID:callbackId]; | ||
} | ||
NSError *parseError; | ||
NSDictionary *parsedResult = [NSJSONSerialization JSONObjectWithData:data | ||
options:kNilOptions | ||
error: &parseError]; | ||
if (parseError != NULL) { | ||
[self sendError:parseError callBackID:callbackId]; | ||
} | ||
CDVPluginResult* result = [CDVPluginResult | ||
resultWithStatus:CDVCommandStatus_OK | ||
messageAsDictionary:parsedResult]; | ||
[self.commandDelegate sendPluginResult:result callbackId:callbackId]; | ||
}]; | ||
} | ||
@catch (NSException *exception) { | ||
[self sendError:exception callBackID:callbackId]; | ||
} | ||
} | ||
|
||
- (void) sendError:(id) error callBackID:(NSString*)callbackID { | ||
NSString* msg = [NSString stringWithFormat: @"During server call, error %@", error]; | ||
CDVPluginResult* result = [CDVPluginResult | ||
resultWithStatus:CDVCommandStatus_ERROR | ||
messageAsString:msg]; | ||
[self.commandDelegate sendPluginResult:result callbackId:callbackID]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters