new public static SwrveConversationCampaign LoadFromJSON(SwrveSDK sdk, Dictionary <string, object> campaignData, int campaignId, DateTime initialisedTime) { SwrveConversationCampaign campaign = new SwrveConversationCampaign(initialisedTime); campaign.Conversation = SwrveConversation.LoadFromJSON(sdk, campaign, (Dictionary <string, object>)campaignData ["conversation"]); return(campaign); }
/// <summary> /// Initialize the SDK. /// </summary> /// <param name="appId"> /// ID for your app, as supplied by Swrve. /// </param> /// <param name="apiKey"> /// Scret API key for your app, as supplied by Swrve. /// </param> /// <param name="config"> /// Extra configuration for the SDK. /// </param> public void Init(int appId, string apiKey, SwrveConfig config = null) { if (SDK == null || SDK is SwrveEmpty) { bool supportedOSAndVersion = true; #if !UNITY_EDITOR #if UNITY_IPHONE supportedOSAndVersion = SwrveSDK.IsSupportediOSVersion(); #elif UNITY_ANDROID supportedOSAndVersion = SwrveSDK.IsSupportedAndroidVersion(); #else #warning "We do not officially support this plaform. tracking is disabled." supportedOSAndVersion = false; #endif #elif !UNITY_IPHONE && !UNITY_ANDROID #warning "We do not officially support this plaform. tracking is disabled." supportedOSAndVersion = false; #endif if (supportedOSAndVersion) { SDK = new SwrveSDK(); } else { SDK = new SwrveEmpty(); } } if (config == null) { config = new SwrveConfig(); } SDK.Init(this, appId, apiKey, config); }
/// <summary> /// Load a conversation from a JSON response. /// </summary> /// <param name="campaign"> /// Parent in-app campaign. /// </param> /// <param name="conversationData"> /// JSON object with the conversation data. /// </param> /// <returns> /// Parsed conversation wrapper for native layer. /// </returns> public static SwrveConversation LoadFromJSON(SwrveSDK sdk, SwrveConversationCampaign campaign, Dictionary <string, object> conversationData) { SwrveConversation conversation = new SwrveConversation(sdk, campaign); conversation.Id = MiniJsonHelper.GetInt(conversationData, "id"); List <object> pages = (List <object>)conversationData ["pages"]; for (int i = 0; i < pages.Count; i++) { Dictionary <string, object> page = (Dictionary <string, object>)pages [i]; List <object> contents = (List <object>)page ["content"]; for (int j = 0; j < contents.Count; j++) { Dictionary <string, object> content = (Dictionary <string, object>)contents[j]; if ("image" == (string)content ["type"]) { conversation.ConversationAssets.Add((string)content ["value"]); } } } conversation.Conversation = Json.Serialize(conversationData); if (conversationData.ContainsKey("priority")) { conversation.Priority = MiniJsonHelper.GetInt(conversationData, "priority"); } return(conversation); }
public void Init(int appId, string apiKey) { if (this.SDK == null || this.SDK is SwrveEmpty) { bool flag = SwrveSDK.IsSupportedAndroidVersion(); if (flag) { this.SDK = new SwrveSDK(); } else { this.SDK = new SwrveEmpty(); } } this.SDK.Init(this, appId, apiKey, this.Config); }
public SwrveQAUser(SwrveSDK swrve, Dictionary <string, object> jsonQa) { this.swrve = swrve; this.ResetDevice = MiniJsonHelper.GetBool(jsonQa, "reset_device_state", false); this.Logging = MiniJsonHelper.GetBool(jsonQa, "logging", false); if (this.Logging) { this.restClient = new RESTClient(); this.loggingUrl = MiniJsonHelper.GetString(jsonQa, "logging_url", null); this.loggingUrl = this.loggingUrl.Replace("http://", "https://"); if (!this.loggingUrl.EndsWith("/")) { this.loggingUrl += "/"; } } this.campaignReasons = new Dictionary <int, string>(); this.campaignMessages = new Dictionary <int, SwrveBaseMessage>(); }
public void Init(int appId, string apiKey, SwrveConfig config = null) { if (SDK == null || SDK is SwrveEmpty) { if (true) { SDK = new SwrveSDK(); } else { SDK = new SwrveEmpty(); } } if (config == null) { config = new SwrveConfig(); } SDK.Init(this, appId, apiKey, config); }
/// <summary> /// Load an in-app campaign from a JSON response. /// </summary> /// <param name="campaignData"> /// JSON object with the individual campaign data. /// </param> /// <param name="initialisedTime"> /// Time that the SDK was initialised. Used for rules checking. /// </param> /// <param name="assetPath"> /// Path to the folder that will store all the assets. /// </param> /// <returns> /// Parsed in-app campaign. /// </returns> public static SwrveBaseCampaign LoadFromJSON(SwrveSDK sdk, Dictionary <string, object> campaignData, DateTime initialisedTime, SwrveQAUser qaUser) { int id = MiniJsonHelper.GetInt(campaignData, ID_KEY); SwrveBaseCampaign campaign = null; if (campaignData.ContainsKey(CONVERSATION_KEY)) { campaign = SwrveConversationCampaign.LoadFromJSON(sdk, campaignData, id, initialisedTime); } else if (campaignData.ContainsKey(MESSAGES_KEY)) { campaign = SwrveMessagesCampaign.LoadFromJSON(sdk, campaignData, id, initialisedTime, qaUser); } if (campaign == null) { return(null); } campaign.Id = id; AssignCampaignTriggers(campaign, campaignData); campaign.MessageCenter = campaignData.ContainsKey(MESSAGE_CENTER_KEY) && (bool)campaignData[MESSAGE_CENTER_KEY]; if ((!campaign.MessageCenter) && (campaign.GetTriggers().Count == 0)) { campaign.LogAndAddReason("Campaign [" + campaign.Id + "], has no triggers. Skipping this campaign.", qaUser); return(null); } AssignCampaignRules(campaign, campaignData); AssignCampaignDates(campaign, campaignData); campaign.Subject = campaignData.ContainsKey(SUBJECT_KEY) ? (string)campaignData[SUBJECT_KEY] : ""; if (campaign.MessageCenter) { SwrveLog.Log(string.Format("message center campaign: {0}, {1}", campaign.GetType(), campaign.subject)); } return(campaign); }
new public static SwrveMessagesCampaign LoadFromJSON(SwrveSDK sdk, Dictionary <string, object> campaignData, int id, DateTime initialisedTime, SwrveQAUser qaUser) { SwrveMessagesCampaign campaign = new SwrveMessagesCampaign(initialisedTime); object _messages = null; campaignData.TryGetValue("messages", out _messages); IList <object> messages = null; try { messages = (IList <object>)_messages; } catch (Exception e) { campaign.LogAndAddReason("Campaign [" + id + "] invalid messages found, skipping. Error: " + e, qaUser); } if (messages == null) { campaign.LogAndAddReason("Campaign [" + id + "] JSON messages are null, skipping.", qaUser); return(null); } for (int k = 0, t = messages.Count; k < t; k++) { Dictionary <string, object> messageData = (Dictionary <string, object>)messages [k]; SwrveMessage message = SwrveMessage.LoadFromJSON(sdk, campaign, messageData); if (message.Formats.Count > 0) { campaign.AddMessage(message); } } if (campaign.Messages.Count == 0) { campaign.LogAndAddReason("Campaign [" + id + "] no messages found, skipping.", qaUser); } return(campaign); }
/// <summary> /// Load an in-app message from a JSON response. /// </summary> /// <param name="campaign"> /// Parent in-app campaign. /// </param> /// <param name="messageData"> /// JSON object with the individual message data. /// </param> /// <returns> /// Parsed in-app message. /// </returns> public static SwrveMessage LoadFromJSON(SwrveSDK sdk, SwrveMessagesCampaign campaign, Dictionary <string, object> messageData) { SwrveMessage message = new SwrveMessage(sdk, campaign); message.Id = MiniJsonHelper.GetInt(messageData, "id"); message.Name = (string)messageData ["name"]; if (messageData.ContainsKey("priority")) { message.Priority = MiniJsonHelper.GetInt(messageData, "priority"); } Dictionary <string, object> template = (Dictionary <string, object>)messageData ["template"]; IList <object> jsonFormats = (List <object>)template ["formats"]; for (int i = 0, j = jsonFormats.Count; i < j; i++) { Dictionary <string, object> messageFormatData = (Dictionary <string, object>)jsonFormats [i]; SwrveMessageFormat messageFormat = SwrveMessageFormat.LoadFromJSON(sdk, message, messageFormatData); message.Formats.Add(messageFormat); } return(message); }
/// <summary> /// Load an in-app message format from a JSON response. /// </summary> /// <param name="message"> /// Parent in-app message. /// </param> /// <param name="messageFormatData"> /// JSON object with the individual message format data. /// </param> /// <returns> /// Parsed in-app message format. /// </returns> public static SwrveMessageFormat LoadFromJSON(SwrveSDK sdk, SwrveMessage message, Dictionary <string, object> messageFormatData) { SwrveMessageFormat messageFormat = new SwrveMessageFormat(message); messageFormat.Name = (string)messageFormatData ["name"]; messageFormat.Language = (string)messageFormatData ["language"]; if (messageFormatData.ContainsKey("scale")) { messageFormat.Scale = MiniJsonHelper.GetFloat(messageFormatData, "scale", 1); } if (messageFormatData.ContainsKey("orientation")) { messageFormat.Orientation = SwrveOrientationHelper.Parse((string)messageFormatData ["orientation"]); } messageFormat.BackgroundColor = sdk.DefaultBackgroundColor; if (messageFormatData.ContainsKey("color")) { string strColor = (string)messageFormatData ["color"]; Color? c = messageFormat.BackgroundColor; if (strColor.Length == 8) { // RRGGBB byte a = byte.Parse(strColor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); byte r = byte.Parse(strColor.Substring(2, 2), System.Globalization.NumberStyles.HexNumber); byte g = byte.Parse(strColor.Substring(4, 2), System.Globalization.NumberStyles.HexNumber); byte b = byte.Parse(strColor.Substring(6, 2), System.Globalization.NumberStyles.HexNumber); c = new Color32(r, g, b, a); } else if (strColor.Length == 6) { // AARRGGBB byte r = byte.Parse(strColor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); byte g = byte.Parse(strColor.Substring(2, 2), System.Globalization.NumberStyles.HexNumber); byte b = byte.Parse(strColor.Substring(4, 2), System.Globalization.NumberStyles.HexNumber); c = new Color32(r, g, b, 255); } messageFormat.BackgroundColor = c; } Dictionary <string, object> sizeJson = (Dictionary <string, object>)messageFormatData ["size"]; messageFormat.Size.X = MiniJsonHelper.GetInt(((Dictionary <string, object>)sizeJson ["w"]), "value"); messageFormat.Size.Y = MiniJsonHelper.GetInt(((Dictionary <string, object>)sizeJson ["h"]), "value"); IList <object> jsonButtons = (List <object>)messageFormatData ["buttons"]; for (int i = 0, j = jsonButtons.Count; i < j; i++) { SwrveButton button = LoadButtonFromJSON(message, (Dictionary <string, object>)jsonButtons [i]); messageFormat.Buttons.Add(button); } IList <object> jsonImages = (List <object>)messageFormatData ["images"]; for (int ii = 0, ji = jsonImages.Count; ii < ji; ii++) { SwrveImage image = LoadImageFromJSON(message, (Dictionary <string, object>)jsonImages [ii]); messageFormat.Images.Add(image); } return(messageFormat); }
public SwrveComponent() { this.Config = new SwrveConfig(); this.SDK = new SwrveEmpty(); }
/// <summary> /// Reset is invoked when the component is added to the Game Object /// and is always called on the main thread. /// </summary> public void Reset() { Config = new SwrveConfig(); SDK = new SwrveSDK(); }
public CPSwrveService(SwrveComponent swrveComponent) { resourceManager = swrveComponent.SDK.ResourceManager; sdk = swrveComponent.SDK; }
/** constructor for initialising the SDK */ public SwrveDeeplinkManager(MonoBehaviour container, SwrveSDK sdkinstance) { this.sdk = sdkinstance; this.container = container; }
/// <summary> /// Default constructor. Will be called by Unity when /// placing this script in your scene. /// </summary> public SwrveComponent() { Config = new SwrveConfig(); SDK = new SwrveSDK(); }
public SwrveComponent() { SDK = new SwrveEmpty(); }
public SwrveCommon(SwrveSDK sdk) { _unitySDK = sdk; }