Skip to content

Commit bea6318

Browse files
committed
Added surprise rant
1 parent a3fa9d8 commit bea6318

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

devRantDotNet/Source/Resources/Values.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace devRantDotNet
88
{
9-
public static class Values
9+
internal static class Values
1010
{
1111
internal const string API = "https://www.devrant.io/api";
1212
internal const string AppId = "?app=3";
@@ -15,5 +15,6 @@ public static class Values
1515
internal const string SingleRant = API + "/devrant/rants/";
1616
internal const string User = API + "/users/";
1717
internal const string Search = API + "/devrant/search";
18+
internal const string Random = API + "/devrant/rants/surprise";
1819
}
1920
}

devRantDotNet/Source/devRant.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ private Comment JSONToCommentObject(dynamic c)
9696
return comment;
9797
}
9898

99+
/// <summary>
100+
/// Returns all the rants from the feed at: https://www.devrant.io/feed
101+
/// </summary>
102+
/// <param name="type"> Type of sort e.g. Top, Algo or Recent</param>
103+
/// <returns>A List of Rants which are iterable</returns>
99104
public List<Rant> GetRants(SortType type)
100105
{
101106
var req = MakeRequest(Values.AllRants+"?sort="+type+"&app=3");
@@ -244,5 +249,19 @@ public List<Rant> Search(string term)
244249
}
245250
}
246251

252+
public Rant GetRandomRant()
253+
{
254+
try
255+
{
256+
var req = MakeRequest(Values.Random + Values.AppId);
257+
dynamic results = JsonConvert.DeserializeObject<dynamic>(req);
258+
259+
return results.success == "true" ? JSONToRantObject(results.rant) : null;
260+
}
261+
catch
262+
{
263+
return null;
264+
}
265+
}
247266
}
248267
}

devRantTests/Program.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static void getAllRants()
1919
public static void getSingleRant(int id)
2020
{
2121
dr.GetRant(id).rant_comments.ForEach(
22-
c => Console.WriteLine(c.user_username + ": " + c.body)
22+
c => Console.WriteLine(c.user_username + ": " + c.body +"("+c.id+")")
2323
);
2424
}
2525

@@ -41,12 +41,23 @@ public static void getSearchResults(string q)
4141
results.ForEach(r => Console.WriteLine(r.text));
4242
}
4343

44+
public static void getRandomRant()
45+
{
46+
var dump = ObjectDumper.Dump(dr.GetRandomRant());
47+
Console.WriteLine(dump);
48+
}
49+
4450
static void Main(string[] args)
4551
{
4652
//getAllRants();
47-
//getSingleRant(448338);
4853
//getUserProfile(dr.GetUserId("px06"));
49-
getSearchResults("px06");
54+
//getSearchResults("px06");
55+
//getSingleRant(448369);
56+
57+
getRandomRant();
58+
Console.WriteLine("-----------------------------------");
59+
getUserProfile(dr.GetUserId("px06"));
60+
5061
Console.ReadLine();
5162
}
5263
}

0 commit comments

Comments
 (0)