/// <summary> /// Retrieves a list of achievements and the completion a subject has towards the achievements. The returned list will also contain earned achievement records when present. /// </summary> /// <param name="subjectId">Unique subject the progress is associated with</param> /// <param name="includeAchievements">Include related achievements</param> /// <param name="includeCriteria">Include related criteria</param> /// <param name="includeAwards">Include related awards</param> /// <returns></returns> public Task <List <Progress> > GetProgress(string subjectId, bool includeAchievements = false, bool includeCriteria = false, bool includeAwards = false) { var query = new HttpQuery(); query.Add("subject", subjectId); //Including criteria or awards requires also including achievements if (includeAwards || includeCriteria) { includeAchievements = true; } if (includeAchievements) { query.Add("include", "achievement"); } if (includeCriteria) { query.Add("include", "criterion"); } if (includeAwards) { query.Add("include", "award"); } return(this.m_httpClient.GetAll <Progress>(ENDPOINT, query: query.ToString())); }
public void ToString_UrlEncodesSpecialSymbolsInKeysAndValues() { var query = new HttpQuery(); query.Add("key=", "value="); Assert.Equal("key%3D=value%3D", query.ToString()); }
public void ToString_UrlEncodesParameterKeysAndValues() { var query = new HttpQuery(); query.Add("key 1", "value 1"); Assert.Equal("key%201=value%201", query.ToString()); }
public void MultipleParameterPairs_ToString_ConcatenatesPairs() { var query = new HttpQuery(); query.Add("key1", "value1"); query.Add("key2", "value2"); Assert.Equal("key1=value1&key2=value2", query.ToString()); }
public void MultipleParameterPairs_ToString_DoesntProduceTrailingAmpersand() { var query = new HttpQuery(); query.Add("key1", "value1"); query.Add("key2", "value2"); Assert.False(query.ToString().EndsWith("&")); }
/// <summary> /// Uploads an HttpQuery object and returns a JsonObject /// </summary> /// <typeparam name="TReturn">The return type of the post</typeparam> /// <param name="url">The url to post to</param> /// <param name="query">The query object to upload</param> /// <returns>A JsonObject representation of the return</returns> public TReturn UploadHttpQuery <TReturn>(string url, HttpQuery query) { this.Headers[HttpRequestHeader.ContentType] = this.FormContentType; if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentException($"'{nameof(url)}' cannot be null or whitespace.", nameof(url)); } if (query is null) { throw new ArgumentNullException(nameof(query)); } return(this.UploadJson <TReturn>(new Uri(url), query.ToString())); }
public void ToString_UrlEncodesEmojiAndUnicodeKeysAndValues() { var query = new HttpQuery(); query.Add("🔥key🔥", "тест 🔥value🔥 тест"); Assert.Equal("%F0%9F%94%A5key%F0%9F%94%A5=%D1%82%D0%B5%D1%81%D1%82%20%F0%9F%94%A5value%F0%9F%94%A5%20%D1%82%D0%B5%D1%81%D1%82", query.ToString()); }
/// <summary> /// Send an event to BadgeUp to be processed, returning achievement progress status /// </summary> /// <param name="event">Event object to send to BadgeUp</param> /// <param name="showIncomplete">Show progress towards an achievement, even if it is incomplete</param> /// <param name="onlyNew">Include only new progress objects </param> /// <returns>Returns a <see cref="EventResponse"/> object with the <see cref="Event"/> and <see cref="Progress"/> towards any relevant achievements</returns> public async Task <EventResponse> Send(Event @event, bool?showIncomplete = null, bool onlyNew = false) { HttpQuery query = new HttpQuery(); if (showIncomplete.GetValueOrDefault(false)) { query.Add("showIncomplete", showIncomplete.Value.ToString().ToLower()); } var result = await this.m_httpClient.Post <EventResponse>(new EventRequest(@event), "events", query : query.ToString()); if (onlyNew) { result.Results.ForEach(res => res.Progress = res.Progress.Where(x => x.IsNew).ToArray()); } return(result); }