Skip to content

Commit d1e118d

Browse files
committed
LiveUpdateEvent access and editing
The Reddit's GetLiveEvent method threw an exception due to one forgotten parameter in a Helper method. LiveUpdateEvent's EditAsync method had multiple errors.
1 parent a062f58 commit d1e118d

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

RedditSharp/Reddit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public async Task<LiveUpdateEvent> GetLiveEvent(Uri uri)
247247
if (!uri.AbsoluteUri.EndsWith("about"))
248248
uri = new Uri(uri.AbsoluteUri + "/about");
249249

250-
var token = await Helpers.GetTokenAsync(WebAgent, uri).ConfigureAwait(false);
250+
var token = await Helpers.GetTokenAsync(WebAgent, uri,true).ConfigureAwait(false);
251251
return new LiveUpdateEvent(WebAgent, token);
252252
}
253253

RedditSharp/Things/LiveUpdateEvent.cs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -166,29 +166,24 @@ public async Task<bool> DeleteUpdateAsync(LiveUpdate update)
166166
/// <summary>
167167
/// Edit a live thread. Set parameters to empty string to clear those fields. Or null to ignore them on update.
168168
/// </summary>
169-
/// <param name="title">New Title.</param>
169+
/// <param name="title">New Title. Cannot be empty string.</param>
170170
/// <param name="description">New Description</param>
171171
/// <param name="resources">new Resources</param>
172172
/// <param name="nsfw">NSFW flag</param>
173173
public async Task<bool> EditAsync(string title, string description, string resources, bool? nsfw)
174174
{
175-
var expando = (IDictionary<string, object>)new ExpandoObject();
176-
177-
if (title != null)
178-
expando.Add(new KeyValuePair<string, object>("title", title));
179-
180-
if (description != null)
181-
expando.Add(new KeyValuePair<string, object>("description", description));
182-
183-
if (resources != null)
184-
expando.Add(new KeyValuePair<string, object>("resources", resources));
185-
186-
if (nsfw.HasValue)
187-
expando.Add(new KeyValuePair<string, object>("nsfw", nsfw.Value));
188-
175+
if (title == null)
176+
title = Title;
177+
if (description == null)
178+
description = Description;
179+
if (resources == null)
180+
resources = Resources;
181+
if (!nsfw.HasValue)
182+
nsfw = NSFW;
183+
184+
dynamic properties = new { title=title,description =description, resources = resources, nsfw = nsfw};
189185
var request = WebAgent.CreateRequest(EditUrl, "POST");
190-
WebAgent.WritePostBody(request, expando);
191-
186+
WebAgent.WritePostBody(request, properties);
192187
var response = await WebAgent.GetResponseAsync(request).ConfigureAwait(false);
193188

194189
if (!response.IsSuccessStatusCode)
@@ -198,9 +193,9 @@ public async Task<bool> EditAsync(string title, string description, string resou
198193
JToken json = JToken.Parse(data);
199194
if (json["success"].Value<Boolean>())
200195
{
201-
Title = title ?? "";
202-
Description = description ?? "";
203-
Resources = resources ?? "";
196+
Title = title ?? Title;
197+
Description = description ?? Description;
198+
Resources = resources ?? Resources;
204199

205200
if (nsfw.HasValue)
206201
NSFW = nsfw.Value;

0 commit comments

Comments
 (0)