Skip to content

Commit

Permalink
Merge pull request #171 from OneSignal/outcomes_release
Browse files Browse the repository at this point in the history
Update for outcomes and release 3.6.0
  • Loading branch information
mikechoch committed Nov 5, 2019
2 parents 0f1f2c0 + c7a4d69 commit abe8fc0
Show file tree
Hide file tree
Showing 22 changed files with 330 additions and 114 deletions.
4 changes: 4 additions & 0 deletions Com.OneSignal.Abstractions/Delegates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ namespace Com.OneSignal.Abstractions

public delegate void OnSetEmailSuccess();
public delegate void OnSetEmailFailure(Dictionary<string, object> response);

// SendOutcomeEventSuccess - Delegate is called when a SendOutcome(...), SendUniqueOutcome(...), or SendOutcomeWithValue(...) is sent successfully
// outcomeEvent = The OutcomeEvent created in native SDK and sent along with request using measure endpoint
public delegate void SendOutcomeEventSuccess(OSOutcomeEvent outcomeEvent);
}
7 changes: 7 additions & 0 deletions Com.OneSignal.Abstractions/IOneSignal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public interface IOneSignal
void RemoveTriggersForKeys(List<String> keys);
object GetTriggerValueForKey(string key);
void PauseInAppMessages(bool pause);

void SendOutcome(string name);
void SendOutcome(string name, SendOutcomeEventSuccess sendOutcomeEventSuccess);
void SendUniqueOutcome(string name);
void SendUniqueOutcome(string name, SendOutcomeEventSuccess sendOutcomeEventSuccess);
void SendOutcomeWithValue(string name, float value);
void SendOutcomeWithValue(string name, float value, SendOutcomeEventSuccess sendOutcomeEventSuccess);
}
}

4 changes: 1 addition & 3 deletions Com.OneSignal.Abstractions/MiniJSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public static object Deserialize(string json)
{
// save the string for debug information
if (json == null)
{
return null;
}
return null;

return Parser.Parse(json);
}
Expand Down
72 changes: 72 additions & 0 deletions Com.OneSignal.Abstractions/OSOutcomeEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;

namespace Com.OneSignal.Abstractions
{
public class OSOutcomeEvent
{

public enum OSSession
{
DIRECT,
INDIRECT,
UNATTRIBUTED,
DISABLED
}

public OSSession session = OSSession.DISABLED;
public List<string> notificationIds = new List<string>();
public string name = "";
public long timestamp = 0;
public double weight = 0;

public OSOutcomeEvent() {}

public OSOutcomeEvent(Dictionary<string, object> outcomeObject)
{
// session;
if (outcomeObject.ContainsKey("session"))
this.session = SessionFromString(outcomeObject["session"] as string);

// notificationIds
if (outcomeObject.ContainsKey("notification_ids")) {
List<object> idObjects = outcomeObject["notification_ids"] as List<object>;
List<string> ids = new List<string>();
foreach (var id in idObjects)
ids.Add(id.ToString());

this.notificationIds = ids;
}

// id
if (outcomeObject.ContainsKey("id"))
this.name = outcomeObject["id"] as string;

// timestamp
if (outcomeObject.ContainsKey("timestamp"))
this.timestamp = (long) outcomeObject["timestamp"];

// weight
if (outcomeObject.ContainsKey("weight")) {
if (outcomeObject["weight"] is Int64)
this.weight = (Int64) outcomeObject["weight"];
if (outcomeObject["weight"] is Double)
this.weight = (Double) outcomeObject["weight"];
}

}

public static OSSession SessionFromString(string session)
{
session = session.ToLower();
if (session == "direct")
return OSSession.DIRECT;
if (session == "indirect")
return OSSession.INDIRECT;
if (session == "unattributed")
return OSSession.UNATTRIBUTED;

return OSSession.DISABLED;
}
}
}
17 changes: 14 additions & 3 deletions Com.OneSignal.Abstractions/OneSignalShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public XamarinBuilder StartInit(string appId)
[Obsolete("SyncHashedEmail has been deprecated. Please use SetEmail() instead.")]
public abstract void SyncHashedEmail(string email);



// logging
public LOG_LEVEL logLevel = LOG_LEVEL.INFO, visualLogLevel = LOG_LEVEL.NONE;

Expand Down Expand Up @@ -116,5 +114,18 @@ public void OnInAppMessageClicked(OSInAppMessageAction action)
public abstract object GetTriggerValueForKey(string key);

public abstract void PauseInAppMessages(bool pause);
}

public abstract void SendOutcome(string name);

public abstract void SendOutcome(string name, SendOutcomeEventSuccess sendOutcomeEventSuccess);

public abstract void SendUniqueOutcome(string name);

public abstract void SendUniqueOutcome(string name, SendOutcomeEventSuccess sendOutcomeEventSuccess);

public abstract void SendOutcomeWithValue(string name, float value);

public abstract void SendOutcomeWithValue(string name, float value, SendOutcomeEventSuccess sendOutcomeEventSuccess);

}
}
2 changes: 1 addition & 1 deletion Com.OneSignal.Abstractions/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("3.5.0")]
[assembly: AssemblyVersion("3.6.0")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
30 changes: 30 additions & 0 deletions Com.OneSignal.Android/OneSignalImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,35 @@ public override void PauseInAppMessages(bool pause)
{
Android.OneSignal.PauseInAppMessages(pause);
}

public override void SendOutcome(string name)
{
Android.OneSignal.SendOutcome(name);
}

public override void SendOutcome(string name, SendOutcomeEventSuccess sendOutcomeEventSuccess)
{
Android.OneSignal.SendOutcome(name, new SendOutcomeEventSuccessHandler(sendOutcomeEventSuccess));
}

public override void SendUniqueOutcome(string name)
{
Android.OneSignal.SendUniqueOutcome(name);
}

public override void SendUniqueOutcome(string name, SendOutcomeEventSuccess sendOutcomeEventSuccess)
{
Android.OneSignal.SendUniqueOutcome(name, new SendOutcomeEventSuccessHandler(sendOutcomeEventSuccess));
}

public override void SendOutcomeWithValue(string name, float value)
{
Android.OneSignal.SendOutcomeWithValue(name, value);
}

public override void SendOutcomeWithValue(string name, float value, SendOutcomeEventSuccess sendOutcomeEventSuccess)
{
Android.OneSignal.SendOutcomeWithValue(name, value, new SendOutcomeEventSuccessHandler(sendOutcomeEventSuccess));
}
}
}
50 changes: 25 additions & 25 deletions Com.OneSignal.Android/PostNotificationResponseHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@ namespace Com.OneSignal
{
public class PostNotificationResponseHandler : Java.Lang.Object, Android.OneSignal.IPostNotificationResponseHandler
{
readonly OnPostNotificationSuccess _success;
readonly OnPostNotificationFailure _failure;
readonly OnPostNotificationSuccess _success;
readonly OnPostNotificationFailure _failure;

public PostNotificationResponseHandler(OnPostNotificationSuccess success, OnPostNotificationFailure failure)
{
_success = success;
_failure = failure;
}
public PostNotificationResponseHandler(OnPostNotificationSuccess success, OnPostNotificationFailure failure)
{
_success = success;
_failure = failure;
}

public void OnSuccess(JSONObject jsonObject)
{
if (_success == null)
return;
public void OnSuccess(JSONObject jsonObject)
{
if (_success == null)
return;

Dictionary<string, object> dict = null;
if (jsonObject != null)
dict = Json.Deserialize(jsonObject.ToString()) as Dictionary<string, object>;
_success(dict);
}
Dictionary<string, object> dict = null;
if (jsonObject != null)
dict = Json.Deserialize(jsonObject.ToString()) as Dictionary<string, object>;
_success(dict);
}

public void OnFailure(JSONObject jsonObject)
{
if (_failure == null)
return;
public void OnFailure(JSONObject jsonObject)
{
if (_failure == null)
return;

Dictionary<string, object> dict = null;
if (jsonObject != null)
dict = Json.Deserialize(jsonObject.ToString()) as Dictionary<string, object>;
_failure(dict);
}
Dictionary<string, object> dict = null;
if (jsonObject != null)
dict = Json.Deserialize(jsonObject.ToString()) as Dictionary<string, object>;
_failure(dict);
}
}
}
2 changes: 1 addition & 1 deletion Com.OneSignal.Android/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("3.5.0")]
[assembly: AssemblyVersion("3.6.0")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
33 changes: 33 additions & 0 deletions Com.OneSignal.Android/SendOutcomeEventSuccessHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using Com.OneSignal.Abstractions;
using Com.OneSignal.Android;

namespace Com.OneSignal
{
public class SendOutcomeEventSuccessHandler : Java.Lang.Object, Android.OneSignal.IOutcomeCallback
{

readonly SendOutcomeEventSuccess _sendOutcomeEventSuccess;

public SendOutcomeEventSuccessHandler(SendOutcomeEventSuccess sendOutcomeEventSuccess) => _sendOutcomeEventSuccess = sendOutcomeEventSuccess;

public void OnSuccess(OutcomeEvent outcome)
{
OSOutcomeEvent outcomeEvent = OSSendOutcomeEventSuccessToNative(outcome);
_sendOutcomeEventSuccess(outcomeEvent);
}

private static OSOutcomeEvent OSSendOutcomeEventSuccessToNative(OutcomeEvent outcome)
{
if (outcome == null)
return new OSOutcomeEvent();

Dictionary<string, object> outcomeObject = Json.Deserialize(outcome.ToJSONObject().ToString()) as Dictionary<string, object>;

OSOutcomeEvent outcomeEvent = new OSOutcomeEvent(outcomeObject);

return outcomeEvent;
}
}
}
24 changes: 12 additions & 12 deletions Com.OneSignal.Android/TagsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@

namespace Com.OneSignal
{
public class TagsHandler : Java.Lang.Object, Android.OneSignal.IGetTagsHandler
{
readonly TagsReceived _tagsReceived;
public class TagsHandler : Java.Lang.Object, Android.OneSignal.IGetTagsHandler
{
readonly TagsReceived _tagsReceived;

public TagsHandler(TagsReceived tagsReceived) => _tagsReceived = tagsReceived;
public TagsHandler(TagsReceived tagsReceived) => _tagsReceived = tagsReceived;

public void TagsAvailable(JSONObject jsonObject)
{
if (_tagsReceived == null)
return;
public void TagsAvailable(JSONObject jsonObject)
{
if (_tagsReceived == null)
return;

Dictionary<string, object> dict = null;
if (jsonObject != null)
dict = Json.Deserialize(jsonObject.ToString()) as Dictionary<string, object>;
_tagsReceived(dict);
}
}
dict = Json.Deserialize(jsonObject.ToString()) as Dictionary<string, object>;
_tagsReceived(dict);
}
}
}
46 changes: 38 additions & 8 deletions Com.OneSignal.iOS/OneSignalImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ private OSNotificationOpenedResult OSNotificationOpenedResultToXam(iOS.OSNotific
return openresult;
}

private OSNotification OSNotificationToXam(iOS.OSNotification notif)
{
var notification = new OSNotification();
notification.displayType = (OSNotification.DisplayType)notif.DisplayType;
notification.shown = notif.Shown;
notification.silentNotification = notif.SilentNotification;
notification.isAppInFocus = notif.IsAppInFocus;
notification.payload = new OSNotificationPayload();
private OSNotification OSNotificationToXam(iOS.OSNotification notif)
{
var notification = new OSNotification();
notification.displayType = (OSNotification.DisplayType)notif.DisplayType;
notification.shown = notif.Shown;
notification.silentNotification = notif.SilentNotification;
notification.isAppInFocus = notif.IsAppInFocus;
notification.payload = new OSNotificationPayload();


notification.payload.actionButtons = new List<Dictionary<string, object>>();
Expand Down Expand Up @@ -358,5 +358,35 @@ public override void PauseInAppMessages(bool pause)
{
iOS.OneSignal.PauseInAppMessages(pause);
}

public override void SendOutcome(string name)
{
Debug.WriteLine("Method SendOutcome() has has not been implemented yet!");
}

public override void SendOutcome(string name, SendOutcomeEventSuccess sendOutcomeEventSuccess)
{
Debug.WriteLine("Method SendOutcome() has has not been implemented yet!");
}

public override void SendUniqueOutcome(string name)
{
Debug.WriteLine("Method SendUniqueOutcome() has has not been implemented yet!");
}

public override void SendUniqueOutcome(string name, SendOutcomeEventSuccess sendOutcomeEventSuccess)
{
Debug.WriteLine("Method SendUniqueOutcome() has has not been implemented yet!");
}

public override void SendOutcomeWithValue(string name, float value)
{
Debug.WriteLine("Method SendOutcomeWithValue() has has not been implemented yet!");
}

public override void SendOutcomeWithValue(string name, float value, SendOutcomeEventSuccess sendOutcomeEventSuccess)
{
Debug.WriteLine("Method SendOutcomeWithValue() has has not been implemented yet!");
}
}
}
2 changes: 1 addition & 1 deletion Com.OneSignal.iOS/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("3.5.0")]
[assembly: AssemblyVersion("3.6.0")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
2 changes: 1 addition & 1 deletion Com.OneSignal.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Com.OneSignal</id>
<version>3.5.0</version>
<version>3.6.0</version>
<title>OneSignal SDK for Xamarin</title>
<authors>OneSignal, Martijn van Dijk</authors>
<owners>OneSignal</owners>
Expand Down
Loading

0 comments on commit abe8fc0

Please sign in to comment.