/// <summary> /// Create a new Multi for the authenticated user /// </summary> /// <param name="m">Multi Data</param> /// <param name="path">Desired URL path for the Multi</param> /// <returns>A string containing the information for the newly created Multi or a status of (409) if the Multi already exists</returns> public async Task <JToken> PostMultiAsync(MData m, string path) { JObject modelData = new JObject { { "description_md", m.DescriptionMD }, { "display_name", m.DisplayName }, { "icon_name", m.IconName }, { "key_color", m.KeyColor } }; JArray subData = new JArray(); foreach (var s in m.Subreddits) { JObject sub = new JObject { { "name", s.Name } }; subData.Add(sub); } modelData.Add("subreddits", subData); modelData.Add("visibility", m.Visibility); modelData.Add("weighting_scheme", m.WeightingScheme); return(await WebAgent.Post(GetMultiPathUrl(path), new { model = modelData, multipath = path }).ConfigureAwait(false)); }
/// <summary> /// Create or update a Multi for the authenticated user /// </summary> /// <param name="m">Multi Data</param> /// <param name="path">Desired URL path for the Multi</param> /// <returns>A string containing the information for the newly created or updated Multi or a status of (409) if the Multi already exists</returns> public async Task <string> PutMultiAsync(MData m, string path) { var request = WebAgent.CreateRequest(GetMultiPathUrl(path), "PUT"); JObject modelData = new JObject { { "description_md", m.DescriptionMD }, { "display_name", m.DisplayName }, { "icon_name", m.IconName }, { "key_color", m.KeyColor } }; JArray subData = new JArray(); foreach (var s in m.Subreddits) { JObject sub = new JObject { { "name", s.Name } }; subData.Add(sub); } modelData.Add("subreddits", subData); modelData.Add("visibility", m.Visibility); modelData.Add("weighting_scheme", m.WeightingScheme); WebAgent.WritePostBody(request, new { model = modelData, multipath = path }); var response = await WebAgent.GetResponseAsync(request).ConfigureAwait(false); return(await response.Content.ReadAsStringAsync().ConfigureAwait(false)); }
/// <summary> /// Creates an implementation of MultiData /// </summary> /// <param name="agent">IWebAgent Object to use</param> /// <param name="json">Json Token containing the information for the Multi</param> /// <param name="subs">Whether there are subs</param> protected internal MultiData(IWebAgent agent, JToken json, bool subs = true) { Data = new MData(agent, json["data"], subs); Helpers.PopulateObject(json, this); }