File tree 3 files changed +35
-4
lines changed
3 files changed +35
-4
lines changed Original file line number Diff line number Diff line change 6
6
7
7
namespace devRantDotNet
8
8
{
9
- public static class Values
9
+ internal static class Values
10
10
{
11
11
internal const string API = "https://www.devrant.io/api" ;
12
12
internal const string AppId = "?app=3" ;
@@ -15,5 +15,6 @@ public static class Values
15
15
internal const string SingleRant = API + "/devrant/rants/" ;
16
16
internal const string User = API + "/users/" ;
17
17
internal const string Search = API + "/devrant/search" ;
18
+ internal const string Random = API + "/devrant/rants/surprise" ;
18
19
}
19
20
}
Original file line number Diff line number Diff line change @@ -96,6 +96,11 @@ private Comment JSONToCommentObject(dynamic c)
96
96
return comment ;
97
97
}
98
98
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>
99
104
public List < Rant > GetRants ( SortType type )
100
105
{
101
106
var req = MakeRequest ( Values . AllRants + "?sort=" + type + "&app=3" ) ;
@@ -244,5 +249,19 @@ public List<Rant> Search(string term)
244
249
}
245
250
}
246
251
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
+ }
247
266
}
248
267
}
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public static void getAllRants()
19
19
public static void getSingleRant ( int id )
20
20
{
21
21
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 + ")" )
23
23
) ;
24
24
}
25
25
@@ -41,12 +41,23 @@ public static void getSearchResults(string q)
41
41
results . ForEach ( r => Console . WriteLine ( r . text ) ) ;
42
42
}
43
43
44
+ public static void getRandomRant ( )
45
+ {
46
+ var dump = ObjectDumper . Dump ( dr . GetRandomRant ( ) ) ;
47
+ Console . WriteLine ( dump ) ;
48
+ }
49
+
44
50
static void Main ( string [ ] args )
45
51
{
46
52
//getAllRants();
47
- //getSingleRant(448338);
48
53
//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
+
50
61
Console . ReadLine ( ) ;
51
62
}
52
63
}
You can’t perform that action at this time.
0 commit comments