示例#1
0
        public static StringRequest CreateAddRequest(string gameId, string privateKey, string score, int sort, string username, string userToken, string guest, string extraData, string tableId)
        {
            var output = new StringRequest(gameId, privateKey, Constants.ScoreUrls.AddUrl, RequestParameter.CreateScore(score), RequestParameter.CreateSort(sort));

            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(userToken))
            {
                if (!string.IsNullOrWhiteSpace(username))
                {
                    Logging.LogError("If you do not want user specific scores you cannot supply a username or a user token.");
                    throw new Exception("User token is null, but username is not.");
                }

                if (!string.IsNullOrWhiteSpace(userToken))
                {
                    Logging.LogError("If you do not want user specific scores you cannot supply a username or a user token.");
                    throw new Exception("Username is null, but user token is not.");
                }

                output.Parameters.Add(RequestParameter.CreateGuest(guest));
            }
            else
            {
                output.Parameters.Add(RequestParameter.CreateUsername(username));
                output.Parameters.Add(RequestParameter.CreateUserToken(userToken));
            }

            if (!string.IsNullOrWhiteSpace(extraData))
            {
                output.Parameters.Add(RequestParameter.CreateExtraData(extraData));
            }

            if (!string.IsNullOrWhiteSpace(tableId))
            {
                output.Parameters.Add(RequestParameter.CreateTableId(tableId));
            }

            return(output);
        }