Skip to content

Commit 0b243c0

Browse files
angelotodaroCrustyJew
authored andcommitted
Added support for Multis (#35)
* Added support for Multis with Documentation on the functions. Added helper methods in WebAgent.cs for Put and Delete methods. * Added Documentation to the MultiData class * Update Naming Conventions to match the rest of the project. * Pull Request Changes 1 Altered the Class mData to instead be MData. Added curly braces to if statements that did not have them. Altered Constructor for Multi class to reflect the rest of the project. Converted doubles for Created properties to DateTime. * Pull Request Changes 2 Updated Target Framework to 4.5.2 for UnitTesting * Moved MData and MultiSubs to their own File. Fixed for loops to be foreach loops. Altered postMulti and putMulti to accept datatype MData.
1 parent 14892b3 commit 0b243c0

File tree

8 files changed

+619
-0
lines changed

8 files changed

+619
-0
lines changed

RedditSharp/Interfaces/IWebAgent.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public interface IWebAgent
1212
HttpWebRequest CreateRequest(string url, string method);
1313
HttpWebRequest CreateGet(string url);
1414
HttpWebRequest CreatePost(string url);
15+
HttpWebRequest CreatePut(string url);
16+
HttpWebRequest CreateDelete(string url);
1517
string GetResponseString(Stream stream);
1618
void WritePostBody(Stream stream, object data, params string[] additionalFields);
1719
JToken CreateAndExecuteRequest(string url);

RedditSharp/Multi/MData.cs

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Linq;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace RedditSharp.Multi
10+
{
11+
/// <summary>
12+
/// Contains the innner information of the Multi
13+
/// </summary>
14+
public class MData
15+
{
16+
/// <summary>
17+
/// Can the Multi be edited
18+
/// </summary>
19+
[JsonProperty("can_edit")]
20+
public bool CanEdit { get; set; }
21+
22+
/// <summary>
23+
/// Display name for the Multi
24+
/// </summary>
25+
[JsonProperty("display_name")]
26+
public string DisplayName { get; set; }
27+
28+
/// <summary>
29+
/// Actual name of the Multi
30+
/// </summary>
31+
[JsonProperty("name")]
32+
public string Name { get; set; }
33+
34+
/// <summary>
35+
/// Description of the Multi in HTML format
36+
/// </summary>
37+
[JsonProperty("description_html")]
38+
public string DescriptionHTML { get; set; }
39+
40+
/// <summary>
41+
/// When the multi was created
42+
/// </summary>
43+
[JsonProperty("created")]
44+
[JsonConverter(typeof(UnixTimestampConverter))]
45+
public DateTime? Created { get; set; }
46+
47+
/// <summary>
48+
/// Where the multi was copied from if it was copied
49+
/// </summary>
50+
[JsonProperty("copied_from")]
51+
public string CopiedFrom { get; set; }
52+
53+
/// <summary>
54+
/// URL of the icon to use.
55+
/// </summary>
56+
[JsonProperty("icon_url")]
57+
public string IconUrl { get; set; }
58+
59+
/// <summary>
60+
/// List of the Subreddits in the multi
61+
/// </summary>
62+
[JsonIgnore]
63+
public List<MultiSubs> Subreddits { get; set; }
64+
65+
/// <summary>
66+
/// When the multi was created in UTC
67+
/// </summary>
68+
[JsonProperty("created_utc")]
69+
[JsonConverter(typeof(UnixTimestampConverter))]
70+
public DateTime? CreatedUTC { get; set; }
71+
72+
/// <summary>
73+
/// Hex Code of the color for the multi
74+
/// </summary>
75+
[JsonProperty("key_color")]
76+
public string KeyColor { get; set; }
77+
78+
/// <summary>
79+
/// Visiblity property for the Multi
80+
/// </summary>
81+
[JsonProperty("visibility")]
82+
public string Visibility { get; set; }
83+
84+
/// <summary>
85+
/// Name of the icon corresponding to the URL
86+
/// </summary>
87+
[JsonProperty("icon_name")]
88+
public string IconName { get; set; }
89+
90+
/// <summary>
91+
/// Weighting scheme of the Multi
92+
/// </summary>
93+
[JsonProperty("weighting_scheme")]
94+
public string WeightingScheme { get; set; }
95+
96+
/// <summary>
97+
/// Path to navigate to the multi
98+
/// </summary>
99+
[JsonProperty("path")]
100+
public string Path { get; set; }
101+
102+
/// <summary>
103+
/// Description of the multi in text format.
104+
/// </summary>
105+
[JsonProperty("description_md")]
106+
public string DescriptionMD { get; set; }
107+
108+
/// <summary>
109+
/// Creates a new mData implementation
110+
/// </summary>
111+
/// <param name="reddit">Reddit object to use</param>
112+
/// <param name="json">Token to use with parameters for the different members</param>
113+
/// <param name="webAgent">Web Agent to use</param>
114+
/// <param name="subs">Whether or not subs exist</param>
115+
protected internal MData(Reddit reddit, JToken json, IWebAgent webAgent, bool subs)
116+
{
117+
Subreddits = new List<MultiSubs>();
118+
if (subs)
119+
{
120+
//Get Subreddit List
121+
for (int i = 0; i < json["subreddits"].Count(); i++)
122+
{
123+
Subreddits.Add(new MultiSubs(reddit, json["subreddits"][i], webAgent));
124+
}
125+
}
126+
JsonConvert.PopulateObject(json.ToString(), this, reddit.JsonSerializerSettings);
127+
}
128+
129+
/// <summary>
130+
/// Generic Constructor
131+
/// </summary>
132+
public MData()
133+
{
134+
135+
}
136+
}
137+
}

0 commit comments

Comments
 (0)