public static Create ( Engagement engagement ) : |
||
engagement | Engagement | |
return |
internal override bool Handle(EventTrigger trigger, ActionStore store) { if (trigger.GetAction() == Type()) { // copy the json to avoid modifying original var response = new JSONObject(trigger.GetResponse()); var persistedParams = store.Get(trigger); if (persistedParams != null) { response["parameters"] = persistedParams; } var image = ImageMessage.Create( ddna, new Engagement("dummy") { JSON = response }, null); if (image != null && image.IsReady()) { if (persistedParams != null) { store.Remove(trigger); } callback(image); return(true); } } return(false); }
public void CreateWithInvalidImageJSONReturnsNull() { var engagement = new Engagement("testDecisionPoint"); ImageMessage imageMessage; engagement.Raw = "{\"transactionID\":2184816393350012928,\"image\":{\"height\":256,\"format\":\"png\",\"spritemap\":{\"background\":{\"x\":2,\"y\":38,\"width\":319,\"height\":177},\"buttons\":[{\"x\":2,\"y\":2,\"width\":160,\"height\":34},{\"x\":323,\"y\":180,\"width\":157,\"height\":35}]},\"layout\":{\"landscape\":{\"background\":{\"contain\":{\"halign\":\"center\",\"valign\":\"center\",\"left\":\"10%\",\"right\":\"10%\",\"top\":\"10%\",\"bottom\":\"10%\"},\"action\":{\"type\":\"none\",\"value\":\"\"}},\"buttons\":[{\"x\":-1,\"y\":144,\"action\":{\"type\":\"dismiss\",\"value\":\"\"}},{\"x\":160,\"y\":143,\"action\":{\"type\":\"action\",\"value\":\"reward\"}}]}},\"shim\":{\"mask\":\"dimmed\",\"action\":{\"type\":\"none\"}},\"url\":\"http://download.deltadna.net/engagements/3eef962b51f84f9ca21643ca21fb3057.png\"},\"parameters\":{\"rewardName\":\"wrench\"}}"; imageMessage = ImageMessage.Create(engagement); Assert.IsNull(imageMessage); engagement.Raw = "{\"transactionID\":2184816393350012928,\"image\":{\"width\":512,\"format\":\"png\",\"spritemap\":{\"background\":{\"x\":2,\"y\":38,\"width\":319,\"height\":177},\"buttons\":[{\"x\":2,\"y\":2,\"width\":160,\"height\":34},{\"x\":323,\"y\":180,\"width\":157,\"height\":35}]},\"layout\":{\"landscape\":{\"background\":{\"contain\":{\"halign\":\"center\",\"valign\":\"center\",\"left\":\"10%\",\"right\":\"10%\",\"top\":\"10%\",\"bottom\":\"10%\"},\"action\":{\"type\":\"none\",\"value\":\"\"}},\"buttons\":[{\"x\":-1,\"y\":144,\"action\":{\"type\":\"dismiss\",\"value\":\"\"}},{\"x\":160,\"y\":143,\"action\":{\"type\":\"action\",\"value\":\"reward\"}}]}},\"shim\":{\"mask\":\"dimmed\",\"action\":{\"type\":\"none\"}},\"url\":\"http://download.deltadna.net/engagements/3eef962b51f84f9ca21643ca21fb3057.png\"},\"parameters\":{\"rewardName\":\"wrench\"}}"; imageMessage = ImageMessage.Create(engagement); Assert.IsNull(imageMessage); engagement.Raw = "{\"transactionID\":2184816393350012928,\"image\":{\"width\":512,\"height\":256,\"format\":\"png\",\"layout\":{\"landscape\":{\"background\":{\"contain\":{\"halign\":\"center\",\"valign\":\"center\",\"left\":\"10%\",\"right\":\"10%\",\"top\":\"10%\",\"bottom\":\"10%\"},\"action\":{\"type\":\"none\",\"value\":\"\"}},\"buttons\":[{\"x\":-1,\"y\":144,\"action\":{\"type\":\"dismiss\",\"value\":\"\"}},{\"x\":160,\"y\":143,\"action\":{\"type\":\"action\",\"value\":\"reward\"}}]}},\"shim\":{\"mask\":\"dimmed\",\"action\":{\"type\":\"none\"}},\"url\":\"http://download.deltadna.net/engagements/3eef962b51f84f9ca21643ca21fb3057.png\"},\"parameters\":{\"rewardName\":\"wrench\"}}"; imageMessage = ImageMessage.Create(engagement); Assert.IsNull(imageMessage); engagement.Raw = "{\"transactionID\":2184816393350012928,\"image\":{\"width\":512,\"height\":256,\"format\":\"png\",\"spritemap\":{\"background\":{\"x\":2,\"y\":38,\"width\":319,\"height\":177},\"buttons\":[{\"x\":2,\"y\":2,\"width\":160,\"height\":34},{\"x\":323,\"y\":180,\"width\":157,\"height\":35}]},\"shim\":{\"mask\":\"dimmed\",\"action\":{\"type\":\"none\"}},\"url\":\"http://download.deltadna.net/engagements/3eef962b51f84f9ca21643ca21fb3057.png\"},\"parameters\":{\"rewardName\":\"wrench\"}}"; imageMessage = ImageMessage.Create(engagement); Assert.IsNull(imageMessage); engagement.Raw = "{\"transactionID\":2184816393350012928,\"image\":{\"width\":512,\"height\":256,\"format\":\"png\",\"spritemap\":{\"background\":{\"x\":2,\"y\":38,\"width\":319,\"height\":177},\"buttons\":[{\"x\":2,\"y\":2,\"width\":160,\"height\":34},{\"x\":323,\"y\":180,\"width\":157,\"height\":35}]},\"layout\":{\"landscape\":{\"background\":{\"contain\":{\"halign\":\"center\",\"valign\":\"center\",\"left\":\"10%\",\"right\":\"10%\",\"top\":\"10%\",\"bottom\":\"10%\"},\"action\":{\"type\":\"none\",\"value\":\"\"}},\"buttons\":[{\"x\":-1,\"y\":144,\"action\":{\"type\":\"dismiss\",\"value\":\"\"}},{\"x\":160,\"y\":143,\"action\":{\"type\":\"action\",\"value\":\"reward\"}}]}},\"shim\":{\"mask\":\"dimmed\",\"action\":{\"type\":\"none\"}}},\"parameters\":{\"rewardName\":\"wrench\"}}"; imageMessage = ImageMessage.Create(engagement); Assert.IsNull(imageMessage); }
public void CreateWithInvalidEngagementResturnsNull() { var engagement = new Engagement("testDecisionPoint"); ImageMessage imageMessage = ImageMessage.Create(engagement); Assert.IsNull(imageMessage); }
public void CreateWithEngagementWithoutImageKeyReturnsNull() { var engagement = new Engagement("testDecisionPoint"); engagement.Raw = "{\n\t\"transactionID\": 2184799313132298240,\n\t\"trace\": {\n\t\t\"initialState\": {\n\t\t\t\"serverNow\": 1460107947856000,\n\t\t\t\"userCreated\": 1459296000000000,\n\t\t\t\"roeLimited\": false\n\t\t},\n\t\t\"engagements\": [{\n\t\t\t\"engagementID\": 4451,\n\t\t\t\"behaviour\": 0,\n\t\t\t\"silent\": false,\n\t\t\t\"enabled\": true,\n\t\t\t\"parameterCriteria\": [],\n\t\t\t\"metricCriteria\": [],\n\t\t\t\"existingVariant\": 8800,\n\t\t\t\"existingState\": null,\n\t\t\t\"existingStateTimestamp\": null,\n\t\t\t\"existingConverted\": 0,\n\t\t\t\"parameters\": {\n\t\t\t\t\"adShowSession\": true\n\t\t\t}\n\t\t}]\n\t},\n\t\"parameters\": {\n\t\t\"adShowSession\": true,\n\t\t\"adProviders\": [{\n\t\t\t\"adProvider\": \"ADMOB\",\n\t\t\t\"eCPM\": 294,\n\t\t\t\"adUnitId\": \"ca-app-pub-4857093250239318/9840016386\"\n\t\t}],\n\t\t\"adRewardedProviders\": [{\n\t\t\t\"adProvider\": \"UNITY\",\n\t\t\t\"eCPM\": 1060,\n\t\t\t\"gameId\": \"106546\",\n\t\t\t\"testMode\": false\n\t\t}, {\n\t\t\t\"adProvider\": \"ADCOLONY\",\n\t\t\t\"eCPM\": 1323,\n\t\t\t\"appId\": \"appdd80fa453e784901bc\",\n\t\t\t\"clientOptions\": \"version:1.0,store:google\",\n\t\t\t\"zoneId\": \"vzc9a5567db2d447d29a\"\n\t\t}, {\n\t\t\t\"adProvider\": \"CHARTBOOST\",\n\t\t\t\"eCPM\": 38,\n\t\t\t\"appId\": \"56e3e633da15274fc8aa6cbf\",\n\t\t\t\"appSignature\": \"a7f6e1592a33abbcc0ac1e311d0ea1f614fefe7c\",\n\t\t\t\"location\": \"Default\"\n\t\t}, {\n\t\t\t\"adProvider\": \"VUNGLE\",\n\t\t\t\"eCPM\": 4,\n\t\t\t\"appId\": \"961178606\"\n\t\t}],\n\t\t\"adFloorPrice\": 1,\n\t\t\"adMinimumInterval\": 200,\n\t\t\"adMaxPerSession\": 20,\n\t\t\"adMaxPerNetwork\": 1,\n\t\t\"adDemoteOnRequestCode\": 1\n\t}\n}"; ImageMessage imageMessage = ImageMessage.Create(engagement); Assert.IsNull(imageMessage); }
/// <summary> /// Requests an image message at a <code>decisionPoint</code>. /// </summary> /// <param name="decisionPoint">the decision point</param> /// <param name="parameters">an optional set of real-time parameters</param> /// <param name="callback">the callback to handle the result</param> public void RequestImageMessage(string decisionPoint, Params parameters, Action <ImageMessage> callback) { Engagement engagement = BuildEngagement(decisionPoint, parameters); ddna.RequestEngagement(engagement, (response) => { callback(ImageMessage.Create(response)); }, (exception) => { callback(null); }); }
public void OnImageMessageBtn_Clicked() { var engagement = new Engagement("testImageMessage") .AddParam("userLevel", 4) .AddParam("experience", 1000) .AddParam("missionName", "Disco Volante"); DDNA.Instance.RequestEngagement(engagement, (response) => { ImageMessage imageMessage = ImageMessage.Create(response); // Check we got an engagement with a valid image message. if (imageMessage != null) { Debug.Log("Engage returned a valid image message."); // This example will show the image as soon as the background // and button images have been downloaded. imageMessage.OnDidReceiveResources += () => { Debug.Log("Image Message loaded resources."); imageMessage.Show(); }; // Add a handler for the 'dismiss' action. imageMessage.OnDismiss += (ImageMessage.EventArgs obj) => { Debug.Log("Image Message dismissed by " + obj.ID); }; // Add a handler for the 'action' action. imageMessage.OnAction += (ImageMessage.EventArgs obj) => { Debug.Log("Image Message actioned by " + obj.ID + " with command " + obj.ActionValue); }; // Download the image message resources. imageMessage.FetchResources(); } else { Debug.Log("Engage didn't return an image message."); } }, (exception) => { Debug.Log("Engage reported an error: " + exception.Message); }); }
internal override bool Handle(EventTrigger trigger) { if (trigger.GetAction() == Type()) { var image = ImageMessage.Create( ddna, new Engagement("dummy") { JSON = trigger.GetResponse() }, null); if (image != null && image.IsReady()) { callback(image); return(true); } } return(false); }
public void CreateWithValidEngagement() { var engagement = new Engagement("testDecisionPoint"); engagement.Raw = "{\"transactionID\":2184816393350012928,\"image\":{\"width\":512,\"height\":256,\"format\":\"png\",\"spritemap\":{\"background\":{\"x\":2,\"y\":38,\"width\":319,\"height\":177},\"buttons\":[{\"x\":2,\"y\":2,\"width\":160,\"height\":34},{\"x\":323,\"y\":180,\"width\":157,\"height\":35}]},\"layout\":{\"landscape\":{\"background\":{\"contain\":{\"halign\":\"center\",\"valign\":\"center\",\"left\":\"10%\",\"right\":\"10%\",\"top\":\"10%\",\"bottom\":\"10%\"},\"action\":{\"type\":\"none\",\"value\":\"\"}},\"buttons\":[{\"x\":-1,\"y\":144,\"action\":{\"type\":\"dismiss\",\"value\":\"\"}},{\"x\":160,\"y\":143,\"action\":{\"type\":\"action\",\"value\":\"reward\"}}]}},\"shim\":{\"mask\":\"dimmed\",\"action\":{\"type\":\"none\"}},\"url\":\"http://download.deltadna.net/engagements/3eef962b51f84f9ca21643ca21fb3057.png\"},\"parameters\":{\"rewardName\":\"wrench\"}}"; Assert.IsNotNull(engagement.JSON); Assert.Contains("image", engagement.JSON.Keys); Assert.Contains("parameters", engagement.JSON.Keys); ImageMessage imageMessage = ImageMessage.Create(engagement); Assert.IsNotNull(imageMessage); Assert.That(!imageMessage.IsReady()); Assert.That(!imageMessage.IsShowing()); Assert.IsNotNull(imageMessage.Parameters); Assert.AreEqual(imageMessage.Parameters, new System.Collections.Generic.Dictionary <string, object>() { { "rewardName", "wrench" } }); }
void OnGUI() { int x = 10; int y = 10; int width = 180; int height = 70; int space = height + 5; GUI.skin.textField.wordWrap = true; GUI.skin.button.fontSize = 18; if (GUI.Button(new Rect(x, y, width, height), "Simple Event")) { GameEvent gameEvent = new GameEvent("options") .AddParam("option", "sword") .AddParam("action", "sell"); DDNA.Instance.RecordEvent(gameEvent); } if (GUI.Button(new Rect(x, y += space, width, height), "Achievement Event")) { GameEvent gameEvent = new GameEvent("achievement") .AddParam("achievementName", "Sunday Showdown Tournament Win") .AddParam("achievementID", "SS-2014-03-02-01") .AddParam("reward", new Params() .AddParam("rewardName", "Medal") .AddParam("rewardProducts", new Product() .AddVirtualCurrency("VIP Points", "GRIND", 20) .AddItem("Sunday Showdown Medal", "Victory Badge", 1) ) ); DDNA.Instance.RecordEvent(gameEvent); } if (GUI.Button(new Rect(x, y += space, width, height), "Transaction Event")) { Transaction transaction = new Transaction( "Weapon type 11 manual repair", "PURCHASE", new Product() .AddItem("WeaponsMaxConditionRepair:11", "WeaponMaxConditionRepair", 5) .AddVirtualCurrency("Credit", "PREMIUM", 710), new Product().SetRealCurrency("USD", Product.ConvertCurrency("USD", 12.34m))) // $12.34 .SetTransactorId("2.212.91.84:15116") .SetProductId("4019") .AddParam("paymentCountry", "GB"); DDNA.Instance.RecordEvent(transaction); } if (GUI.Button(new Rect(x, y += space, width, height), "Engagement")) { var engagement = new Engagement("gameLoaded") .AddParam("userLevel", 4) .AddParam("experience", 1000) .AddParam("missionName", "Disco Volante"); DDNA.Instance.RequestEngagement(engagement, (Dictionary <string, object> response) => { popupContent = DeltaDNA.MiniJSON.Json.Serialize(response); }); popupTitle = "Engage returned"; } if (GUI.Button(new Rect(x, y += space, width, height), "Image Message")) { var engagement = new Engagement("imageMessage") .AddParam("userLevel", 4) .AddParam("experience", 1000) .AddParam("missionName", "Disco Volante"); DDNA.Instance.RequestEngagement(engagement, (response) => { ImageMessage imageMessage = ImageMessage.Create(response); // Check we got an engagement with a valid image message. if (imageMessage != null) { Debug.Log("Engage returned a valid image message."); // This example will show the image as soon as the background // and button images have been downloaded. imageMessage.OnDidReceiveResources += () => { Debug.Log("Image Message loaded resources."); imageMessage.Show(); }; // Add a handler for the 'dismiss' action. imageMessage.OnDismiss += (ImageMessage.EventArgs obj) => { Debug.Log("Image Message dismissed by " + obj.ID); }; // Add a handler for the 'action' action. imageMessage.OnAction += (ImageMessage.EventArgs obj) => { Debug.Log("Image Message actioned by " + obj.ID + " with command " + obj.ActionValue); }; // Download the image message resources. imageMessage.FetchResources(); } else { Debug.Log("Engage didn't return an image message."); } }, (exception) => { Debug.Log("Engage reported an error: " + exception.Message); }); } if (GUI.Button(new Rect(x, y += space, width, height), "Notification Opened")) { var payload = new Dictionary <string, object>(); payload.Add("_ddId", 1); payload.Add("_ddName", "Example Notification"); payload.Add("_ddLaunch", true); DDNA.Instance.RecordPushNotification(payload); } if (GUI.Button(new Rect(x, y += space, width, height), "Upload Events")) { DDNA.Instance.Upload(); } if (GUI.Button(new Rect(x, y += space, width, height), "Start SDK")) { DDNA.Instance.StartSDK(ENVIRONMENT_KEY, COLLECT_URL, ENGAGE_URL); } if (GUI.Button(new Rect(x, y += space, width, height), "Stop SDK")) { DDNA.Instance.StopSDK(); } if (GUI.Button(new Rect(x, y += space, width, height), "New Session")) { DDNA.Instance.NewSession(); } if (popupContent != "") { GUI.ModalWindow(0, new Rect(Screen.width / 2 - 150, Screen.height / 2 - 100, 300, 200), RenderPopupContent, popupTitle); } }
public void CreateWithNullEngagementReturnsNull() { ImageMessage imageMessage = ImageMessage.Create(null); Assert.IsNull(imageMessage); }