コード例 #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);
            }
        }
コード例 #2
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);
            }
        }