Skip to content

Commit

Permalink
Added updated SDK methods
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaysharm committed Apr 11, 2017
1 parent 8796d78 commit 9e8d2fe
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public static void setServerEndpoint(String serverEndpoint) {
TestFairy.setServerEndpoint(serverEndpoint);
}

public static void setUserId(String userId) {
TestFairy.setUserId(userId);
}

public static boolean setAttribute(String key, String value) {
return TestFairy.setAttribute(key, value);
}

public static HashMap<String, Object> toHashMap(String traits) {
HashMap<String, Object> identityTraits = new HashMap<String, Object>();
for (String attribute : traits.split("\n")) {
Expand Down
45 changes: 44 additions & 1 deletion Plugins/TestFairy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ public class TestFairy : MonoBehaviour

[DllImport("__Internal")]
private static extern void TestFairy_log(string name);

[DllImport("__Internal")]
private static extern void TestFairy_hideWebViewElements(string cssSelector);

[DllImport("__Internal")]
private static extern void TestFairy_setUserId(string userId);

[DllImport("__Internal")]
private static extern bool TestFairy_setAttribute(string aKey, string aValue);
#elif UNITY_ANDROID && !UNITY_EDITOR
void Start () {
AndroidJNI.AttachCurrentThread();
Expand Down Expand Up @@ -316,7 +325,7 @@ public static void setScreenName(string name) {
pluginClass.CallStatic("setScreenName", name);
}
}
#endif
#endif
}

public static void log(string message) {
Expand All @@ -330,5 +339,39 @@ public static void log(string message) {
}
#endif
}

public static void hideWebViewElements(string cssSelector) {
#if UNITY_IPHONE && !UNITY_EDITOR
TestFairy_hideWebViewElements(cssSelector);
#elif UNITY_ANDROID && !UNITY_EDITOR
// no op on Android
#endif
}

public static void setUserId(string userId) {
#if UNITY_IPHONE && !UNITY_EDITOR
TestFairy_setUserId(userId);
#elif UNITY_ANDROID && !UNITY_EDITOR
using(AndroidJavaClass pluginClass = getTestFairyClass()) {
if(pluginClass != null) {
pluginClass.CallStatic("setUserId", "TestFairyUnity", userId);
}
}
#endif
}

public static bool setAttribute(string aKey, string aValue) {
bool added = false;
#if UNITY_IPHONE && !UNITY_EDITOR
added = TestFairy_setAttribute(aKey, aValue);
#elif UNITY_ANDROID && !UNITY_EDITOR
using(AndroidJavaClass pluginClass = getTestFairyClass()) {
if(pluginClass != null) {
added = pluginClass.CallStatic<bool>("setAttribute", "TestFairyUnity", aKey, aValue);
}
}
#endif
return added;
}
}
}
30 changes: 29 additions & 1 deletion Plugins/iOS/TestFairyUnityWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void TestFairy_resume()

void TestFairy_stop()
{
// No Op
[TestFairy stop];
}

const char * TestFairy_sessionUrl()
Expand Down Expand Up @@ -129,3 +129,31 @@ void TestFairy_log(char *message) {
NSString *value = message == NULL ? @"" : [NSString stringWithUTF8String:message];
TFLog(@"%@", value);
}

void TestFairy_hideWebViewElements(char *cssSelector) {
if (cssSelector == NULL) {
return;
}

NSString *value = [NSString stringWithUTF8String:cssSelector];
[TestFairy hideWebViewElements:value];
}

void TestFairy_setUserId(char *userId) {
if (userId == NULL) {
return;
}

NSString *value = [NSString stringWithUTF8String:userId];
[TestFairy setUserId:value];
}

bool TestFairy_setAttribute(char *aKey, char *aValue) {
if (aKey == NULL || aValue == NULL) {
return false;
}

NSString *key = [NSString stringWithUTF8String:aKey];
NSString *value = [NSString stringWithUTF8String:aValue];
return [TestFairy setAttribute:key withValue:value];
}

0 comments on commit 9e8d2fe

Please sign in to comment.