Esempio n. 1
0
        /// <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));
        }
Esempio n. 2
0
        /// <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));
        }
Esempio n. 3
0
        /// <summary>
        /// Create or update a  Multi for the authenticated user
        /// </summary>
        /// <param name="description">Multi Description</param>
        /// <param name="displayname">Multi Display Name</param>
        /// <param name="iconname">Icon Name (must be one of the default values)</param>
        /// <param name="keycolor">Hex Code for the desired color</param>
        /// <param name="subreddits">Array of Subreddit names to add</param>
        /// <param name="visibility">Visibility state for the Multi</param>
        /// <param name="weightingscheme">Weighting Scheme for the Multi</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 string PutMulti(MData m, string path)
        {
            if (Reddit.User == null)
            {
                throw new AuthenticationException("No user logged in");
            }
            var     request   = WebAgent.CreatePut(string.Format(GetMultiPathUrl, path));
            var     stream    = request.GetRequestStream();
            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(stream, new
            {
                model     = modelData,
                multipath = path,
                uh        = Reddit.User.Modhash
            });
            stream.Close();
            var response = request.GetResponse();
            var data     = WebAgent.GetResponseString(response.GetResponseStream());

            return(data);
        }
Esempio n. 4
0
 /// <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);
 }
Esempio n. 5
0
 /// <summary>
 /// Creates an implementation of MultiData
 /// </summary>
 /// <param name="reddit">Reddit Object to use</param>
 /// <param name="json">Json Token containing the information for the Multi</param>
 /// <param name="webAgent">Web Agent to use</param>
 /// <param name="subs">Whether there are subs</param>
 protected internal MultiData(Reddit reddit, JToken json, IWebAgent webAgent, bool subs = true)
 {
     Data = new MData(reddit, json["data"], webAgent, subs);
     JsonConvert.PopulateObject(json.ToString(), this, reddit.JsonSerializerSettings);
 }