Beispiel #1
0
        /// <summary>
        /// Send a player action with the given type and parameters.
        /// Then executes the given callback when the response is received.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="callback">The callback.</param>
        /// <returns></returns>
        public static IEnumerator SendAction(string type, object parameters, Action <MatchableResponse> callback)
        {
            if (MatchableSettings.IsPluginEnabled())
            {
                if (type == null)
                {
                    Debug.LogError("SendAction(): parameter 'type' is required");
                    yield return(null);
                }

                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Content-Type", "application/json");
                headers.Add("Authorization", "api_key " + MatchableSettings.GetAppKey());

                Hashtable action = MatchableAction.Create(type, parameters);

                // Simple hack to wrap the action inside a JSON array
                string data = "[" + MJSON.Serialize(action) + "]";
                if (MatchableSettings.IsLoggingEnabled())
                {
                    Debug.Log("Sent action:" + data);
                }
                byte[] postData = AsciiEncoding.StringToAscii(data);

                WWW request = new WWW(MatchableSettings.GetActionsEndpoint(), postData, headers);
                yield return(request);

                MatchableResponse response = new MatchableResponse(request);
                yield return(response);

                callback(response);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Add a new action with the given type and parameters for the default player
        /// This action is saved locally and can be sent via the SendPlayerActions() method
        /// </summary>
        /// <param name="type">Action type (ex: game_start)</param>
        /// <param name="parameters">Action parameters (JSON string)</param>
        public static Hashtable Create(string type, object parameters)
        {
            Hashtable action = new Hashtable();

            //adding device info
            action.Add("device_model", SystemInfo.deviceModel);
            action.Add("device_type", SystemInfo.deviceType);
            action.Add("operating_system", SystemInfo.operatingSystem);

            action.Add("version", MatchableSettings.GetGameVersion());
            action.Add("type", type);
            action.Add("parameters", parameters);
            action.Add("date", TimeStamp.UnixTimeStampUTC());
            return(action);
        }
Beispiel #3
0
        /// <summary>
        /// Retrieve recommendations for a given player.
        /// The recommendations are obtained using a strategy based on the different scores computed by Matchable.
        /// The strategies can be specifically developped for each customer in collaboration with Matchable's data scientists.
        /// </summary>
        /// /// <code>
        /// StartCoroutine(Matchable.GetAdvisor((response) =>
        /// {
        ///     Debug.Log(response.ToJsonString());
        /// }));
        /// </code>
        public static IEnumerator GetRecommendations(Action <MatchableResponse> callback)
        {
            if (MatchableSettings.IsPluginEnabled())
            {
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "api_key " + MatchableSettings.GetAppKey());

                WWW request = new WWW(MatchableSettings.GetRecommendationsEndpoint(), null, headers);
                yield return(request);

                MatchableResponse response = new MatchableResponse(request);
                yield return(response);

                callback(response);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Initializes the SDK plugin. (optional)
 /// Enabled by default in Matchable > EditSettings
 /// </summary>
 public static void Init()
 {
     MatchableSettings.SetPluginEnabled(true);
 }
Beispiel #5
0
 /// <summary>
 /// Disable the SDK plugin.
 /// Prevents all the method calls (useful for debuging other plugins)
 /// </summary>
 public static void Disable()
 {
     MatchableSettings.SetPluginEnabled(false);
 }
Beispiel #6
0
 /// <summary>
 /// Build matchable.io API url for the given endpoint using the provided customer_key and player_id
 /// </summary>
 /// <param name="endpoint">API endpoint name</param>
 /// <returns>
 /// The complete URL string for the given endpoint
 /// </returns>
 private static string GetUserEndpoint(string endpoint)
 {
     return(String.Format("{0}/{1}/users/{2}/{3}", apiUrl, apiVersion, MatchableSettings.GetPlayerId(), endpoint));
 }