Skip to content

Commit 84e04ce

Browse files
committed
Merge pull request #189 from andrewtackett/master
Add get overview method with parameters and comment del
2 parents a3712a7 + 4e25f11 commit 84e04ce

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

RedditSharp/Things/Comment.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ namespace RedditSharp.Things
1313
public class Comment : VotableThing
1414
{
1515
private const string CommentUrl = "/api/comment";
16-
private const string EditUserTextUrl = "/api/editusertext";
17-
private const string RemoveUrl = "/api/remove";
16+
private const string EditUserTextUrl = "/api/editusertext";
17+
private const string RemoveUrl = "/api/remove";
18+
private const string DelUrl = "/api/del";
1819
private const string SetAsReadUrl = "/api/read_message";
1920

2021
[JsonIgnore]
@@ -187,6 +188,28 @@ public void EditText(string newText)
187188
Body = newText;
188189
else
189190
throw new Exception("Error editing text.");
191+
}
192+
193+
private string SimpleAction(string endpoint)
194+
{
195+
if (Reddit.User == null)
196+
throw new AuthenticationException("No user logged in.");
197+
var request = WebAgent.CreatePost(endpoint);
198+
var stream = request.GetRequestStream();
199+
WebAgent.WritePostBody(stream, new
200+
{
201+
id = FullName,
202+
uh = Reddit.User.Modhash
203+
});
204+
stream.Close();
205+
var response = request.GetResponse();
206+
var data = WebAgent.GetResponseString(response.GetResponseStream());
207+
return data;
208+
}
209+
210+
public void Del()
211+
{
212+
var data = SimpleAction(DelUrl);
190213
}
191214

192215
public void Remove()

RedditSharp/Things/RedditUser.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,24 @@ public Listing<Subreddit> SubscribedSubreddits
111111
}
112112
}
113113

114+
/// <summary>
115+
/// Get a listing of comments and posts from the user sorted by <paramref name="sorting"/>, from time <paramref name="fromTime"/>
116+
/// and limited to <paramref name="limit"/>.
117+
/// </summary>
118+
/// <param name="sorting">How to sort the comments (hot, new, top, controversial).</param>
119+
/// <param name="limit">How many comments to fetch per request. Max is 100.</param>
120+
/// <param name="fromTime">What time frame of comments to show (hour, day, week, month, year, all).</param>
121+
/// <returns>The listing of comments requested.</returns>
122+
public Listing<VotableThing> GetOverview(Sort sorting = Sort.New, int limit = 25, FromTime fromTime = FromTime.All)
123+
{
124+
if ((limit < 1) || (limit > MAX_LIMIT))
125+
throw new ArgumentOutOfRangeException("limit", "Valid range: [1," + MAX_LIMIT + "]");
126+
string overviewUrl = string.Format(OverviewUrl, Name);
127+
overviewUrl += string.Format("?sort={0}&limit={1}&t={2}", Enum.GetName(typeof(Sort), sorting), limit, Enum.GetName(typeof(FromTime), fromTime));
128+
129+
return new Listing<VotableThing>(Reddit, overviewUrl, WebAgent);
130+
}
131+
114132
/// <summary>
115133
/// Get a listing of comments from the user sorted by <paramref name="sorting"/>, from time <paramref name="fromTime"/>
116134
/// and limited to <paramref name="limit"/>.

0 commit comments

Comments
 (0)