Exemple #1
0
        /* NEEDS WORK - BulkCreateParticipants
         * public IEnumerable<ChallongeParticipant> BulkCreateParticipants(string tournamentUrl, IEnumerable<CreateChallongeParticipant> participantList)
         * {
         *    //Creates a JsonCreateChallongeParticipant list for sending it!
         *    IEnumerable<JsonCreateChallongeParticipant> jsonList = participantList.Select(x => new JsonCreateChallongeParticipant() { json = x });
         *
         *    //Deserializes the
         *    var deserialize = JsonConvert.DeserializeObject<IEnumerable<CreateChallongeParticipant>>(Send(participantList, "POST", "/" + tournamentUrl + "/participants/bulk_add"));
         *
         *    return new List<ChallongeParticipant>(); //return deserialize.Select(x => ProcessJson<ChallongeParticipant, JsonChallongeParticipant>(x)).AsEnumerable();
         * }
         */

        public ChallongeParticipant UpdateParticipant(string tournamentUrl, int participantID, ChallongeParticipant participant)
        {
            var jsonParticipant = new JsonChallongeParticipant()
            {
                json = participant
            };

            return(ProcessJson <ChallongeParticipant, JsonChallongeParticipant>(JsonConvert.DeserializeObject <JsonChallongeParticipant>(Send(jsonParticipant, "PUT",
                                                                                                                                              "/" + tournamentUrl + "/participants/" + participantID.ToString()))));
        }
        /// <summary>Retrieve a tournament's participant list.</summary>
        /// <param name="tournamentKey">The ID or URL string that identifies the tournament. In the form "SUBDOMAIN-URLKEY"</param>
        /// <param name="username">The Challonge username to retrieve the data.</param>
        /// <param name="apikey">The Challonge API key, generated from https://challonge.com/settings/developer. </param>
        /// <param name="participants">List of participants to add (name & email).</param>
        public static void AddParticipant(string tournamentKey, string username, string apikey, ChallongeParticipant participant)
        {
            if (participant == null || string.IsNullOrEmpty(participant.Name))
            {
                return;
            }

            var requestUrl = string.Format("tournaments/{0}/participants", tournamentKey);

            var client = new RestClient(CHALLONGE_API_URL);

            client.Authenticator = new HttpBasicAuthenticator(username, apikey);

            var request = new RestRequest(requestUrl, Method.POST);

            request.AddParameter("participant[name]", participant.Name);

            if (!string.IsNullOrEmpty(participant.Email))
            {
                request.AddParameter("participant[misc]", participant.Email);
            }

            var response = client.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine(string.Format("- Added: {0}", participant.Name));
            }
            else
            {
                Console.WriteLine(string.Format("- Failed to add participant: {0}", participant.Name));
            }
        }