Skip to content

Commit

Permalink
Merge pull request #5 from wingify/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
aman400 authored Jun 4, 2018
2 parents 5ec613c + 6204f92 commit 4a3264e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 21 deletions.
37 changes: 25 additions & 12 deletions src/android/VWOCordovaPlugin.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import com.vwo.mobile.Initializer;
import com.vwo.mobile.VWO;
import com.vwo.mobile.VWOConfig;
import com.vwo.mobile.events.VWOStatusListener;
Expand Down Expand Up @@ -38,7 +37,6 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) {

public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
if (action.equals("launchSynchronously")) {

String apiKey = args.getString(0);
Double timeoutInSeconds = args.getDouble(1) * 1000;
// Convert timeout to milliseconds
Expand All @@ -48,31 +46,26 @@ public boolean execute(String action, JSONArray args, final CallbackContext call
return true;

} else if (action.equals("launch")) {

String apiKey = args.getString(0);
VWOConfig vwoConfig = parseJSONToConfig(args.getJSONObject(1));
launch(apiKey, vwoConfig, callbackContext);
return true;

} else if (action.equals("version")) {

getVersion(callbackContext);
return true;

} else if (action.equals("variationForKey")) {

} else if (action.equals("objectForKey")) {
String key = args.getString(0);
getVariationForKey(key, callbackContext);
return true;

} else if (action.equals("trackConversion")) {

String goalIdentifier = args.getString(0);
trackConversion(goalIdentifier, callbackContext);
return true;

} else if (action.equals("trackConversionWithValue")) {

String goalIdentifier = args.getString(0);
double value = Double.parseDouble(args.getString(1));
trackConversionWithValue(goalIdentifier, value, callbackContext);
Expand All @@ -81,6 +74,13 @@ public boolean execute(String action, JSONArray args, final CallbackContext call
} else if (action.equals("setLogLevel")) {
int logLevel = args.getInt(0);
setLogLevel(logLevel, callbackContext);
return true;

} else if (action.equals("variationNameForTestKey")) {
String testKey = args.getString(0);
variationNameForTestKey(testKey, callbackContext);
return true;

}
return false;
}
Expand Down Expand Up @@ -121,6 +121,19 @@ public void run() {
});
}

private void variationNameForTestKey(final String testKey, final CallbackContext callbackContext) {
cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
callbackContext.success(VWO.getVariationNameForTestKey(testKey));
} catch (Exception exception) {
VWOLog.e(VWOLog.DATA_LOGS, exception, true, true);
}
}
});
}

private void trackConversion(final String goalIdentifier, final CallbackContext callbackContext) {
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
Expand Down Expand Up @@ -160,7 +173,7 @@ private static Map<String, String> JSONtoMap(JSONObject object) throws JSONExcep
Iterator<String> keysItr = object.keys();
while (keysItr.hasNext()) {
String key = keysItr.next();
if(object.isNull(key)) {
if (object.isNull(key)) {
map.put(key, null);
} else {
map.put(key, object.getString(key));
Expand All @@ -173,21 +186,21 @@ private void getVariationForKey(final String key, final CallbackContext callback
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
JSONObject wrapperObject = new JSONObject();
Object object = VWO.getVariationForKey(key, null);
Object object = VWO.getObjectForKey(key, null);

if (object == null) {
try {
wrapperObject.put(key, JSONObject.NULL);
callbackContext.success(wrapperObject);
} catch (JSONException exception) {
VWOLog.e(VWOLog.DATA, exception, false, false);
VWOLog.e(VWOLog.DATA_LOGS, exception, false, false);
}
} else {
try {
wrapperObject.put(key, object);
callbackContext.success(wrapperObject);
} catch (JSONException exception) {
VWOLog.e(VWOLog.DATA, exception, false, false);
VWOLog.e(VWOLog.DATA_LOGS, exception, false, false);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/android/build-extras.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repositories {
}

dependencies {
compile 'com.vwo:mobile:2.3.1@aar'
compile 'com.vwo:mobile:2.4.0@aar'
compile ('io.socket:socket.io-client:1.0.0') {
// excluding org.json which is provided by Android
exclude group: 'org.json', module: 'json'
Expand Down
4 changes: 3 additions & 1 deletion src/ios/VWOCordovaPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

- (void)launch:(CDVInvokedUrlCommand *)command;

- (void)variationForKey:(CDVInvokedUrlCommand *)command;
- (void)objectForKey:(CDVInvokedUrlCommand *)command;

- (void)variationNameForTestKey:(CDVInvokedUrlCommand *)command;

- (void)trackConversion:(CDVInvokedUrlCommand *)command;

Expand Down
15 changes: 13 additions & 2 deletions src/ios/VWOCordovaPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ - (void)launch:(CDVInvokedUrlCommand *)command {
}];
}

- (void)variationForKey:(CDVInvokedUrlCommand *)command {
- (void)objectForKey:(CDVInvokedUrlCommand *)command {
NSString *key = [command argumentAtIndex:0];
id variation = [VWO variationForKey:key];

// default value is always nil as Java does not support General object type.
// Hence value is inserted in Dictionary and then sent
id variation = [VWO objectForKey:key defaultValue:nil];

CDVPluginResult* result;
if (variation == nil) {
Expand All @@ -63,6 +66,14 @@ - (void)variationForKey:(CDVInvokedUrlCommand *)command {
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}

- (void)variationNameForTestKey:(CDVInvokedUrlCommand *)command {
NSString *testKey = [command argumentAtIndex:0];

NSString *variationName = [VWO variationNameForTestKey:testKey];
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:variationName];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}

- (void)trackConversion:(CDVInvokedUrlCommand *)command {
NSString *goal = [command argumentAtIndex:0];
[VWO trackConversion:goal];
Expand Down
15 changes: 10 additions & 5 deletions www/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,8 @@ VWO.launch = function(apiKey, config, success, error){
* @param key {string} Key for the campaign
* @param defaultValue {value} Default Value
* @return Variation object
*
* @deprecated Deprecated in favour of variationForKeyWithDefaultValue
*/
VWO.variationForKey = function (key, defaultValue, success) {
console.warn("Deprecated. Use VWO.variationForKeyWithDefaultValue instead.");
VWO.objectForKey = function (key, defaultValue, success) {
if (!key) {
throw new Error('Must pass Key for Campaign');
}
Expand All @@ -104,9 +101,17 @@ VWO.variationForKey = function (key, defaultValue, success) {
} else {
success(data[key]);
}
}, function(error) {}, PLUGIN_NAME, 'variationForKey', [key]);
}, function(error) {}, PLUGIN_NAME, 'objectForKey', [key]);
};


VWO.variationNameForTestKey = function(testKey, success) {
if(!testKey) {
throw new Error('Must pass valid testKey');
}
exec(success, function(error) {}, PLUGIN_NAME, 'variationNameForTestKey', [testKey]);
}

/** Mark the conversion for goal
*
* @param success {callback} Success Callback
Expand Down

0 comments on commit 4a3264e

Please sign in to comment.