Esempio n. 1
0
        /// <summary>
        /// Makes get call to fetch contest.
        /// </summary>
        /// <param name="contestId">The id of the contest to fetch</param>
        /// <returns>The contest response if value. Throw exception otherwise</returns>
        public async Task <ContestResponse> GetContestStatus(string contestId)
        {
            string uri = END_POINT + $"/api/contests/{contestId}";

            var response = await httpClient.GetAsync(uri);

            string jsonResponse = await response.Content.ReadAsStringAsync();

            ContestResponse result = JsonConvert.DeserializeObject <ContestResponse>(jsonResponse);

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a Cloud Skills Challenge based on the parameter.
        /// </summary>
        /// <param name="contest">The argurments to pass to the server.</param>
        /// <returns>The ContestResponse from the server.</returns>
        public async Task <ContestResponse> CreateChallengeAsync(ContestRequest contest)
        {
            string uri = END_POINT + $"/api/contests";

            string json = JsonConvert.SerializeObject(contest);

            HttpResponseMessage response = await httpClient.PostAsync(uri,
                                                                      new StringContent(json, Encoding.UTF8, "application/json"));

            string jsonResponse = await response.Content.ReadAsStringAsync();

            ContestResponse result = JsonConvert.DeserializeObject <ContestResponse>(jsonResponse);

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a challenge for each collection based on template
        /// </summary>
        /// <param name="collections">The list of collections to be used in the template.</param>
        /// <param name="contestTemplate">The template to be used to created the contest.</param>
        /// <returns>The ContestResponse.</returns>
        public async Task <List <ContestResponse> > CreateCollectionChallengesAsync(List <string> collections, ContestRequest contestTemplate)
        {
            contestTemplate.Type = "Collection";
            var results = new List <ContestResponse>();

            foreach (string s in collections)
            {
                contestTemplate.CollectionUrl = s;
                contestTemplate.CollectionID  = s.Substring(s.LastIndexOf('/') + 1);
                ContestResponse result = await CreateChallengeAsync(contestTemplate);

                results.Add(result);
            }

            return(results);
        }