diff --git a/DevRant.Tests/DevRantClientTests.cs b/DevRant.Tests/DevRantClientTests.cs
index 9c1d14d..199fdd5 100644
--- a/DevRant.Tests/DevRantClientTests.cs
+++ b/DevRant.Tests/DevRantClientTests.cs
@@ -41,5 +41,13 @@ public async Task GetProfileAsync_WhenUsernameExists_ReturnsValue()
Assert.That(result.Username, Is.Not.EqualTo(username));
Assert.That(result.Score, Is.GreaterThan(0));
}
+
+ [Test, Explicit]
+ public async Task GetRantsAsync_WhenCalled_ReturnsValue()
+ {
+ var result = await sut.GetRantsAsync();
+
+ Assert.That(result, Is.Not.Empty);
+ }
}
}
diff --git a/DevRant/DevRant.csproj b/DevRant/DevRant.csproj
index 0d5f673..19126d3 100644
--- a/DevRant/DevRant.csproj
+++ b/DevRant/DevRant.csproj
@@ -58,6 +58,8 @@
+
+
diff --git a/DevRant/DevRantClient.cs b/DevRant/DevRantClient.cs
index d5b841f..3658aa0 100644
--- a/DevRant/DevRantClient.cs
+++ b/DevRant/DevRantClient.cs
@@ -1,6 +1,7 @@
using DevRant.Dtos;
using Newtonsoft.Json.Linq;
using System;
+using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
@@ -48,6 +49,25 @@ public async Task GetProfileAsync(string username)
return ParseProperty(responseText, "profile");
}
+ ///
+ /// Requests a collection of rants sorted and selected by the arguments from the rest-api.
+ ///
+ /// Sorting of the rant collection.
+ /// Maximal rants to return.
+ /// Number of rants to skip.
+ ///
+ public async Task> GetRantsAsync(RantSort sort = RantSort.Algo, int limit = 50, int skip = 0)
+ {
+ var sortText = sort
+ .ToString()
+ .ToLower();
+
+ var response = await client.GetAsync($"/api/devrant/rants?app={appVersion}&sort={sortText}&limit={limit}&skip={skip}");
+ var responseText = await response.Content.ReadAsStringAsync();
+
+ return ParseProperty>(responseText, "rants");
+ }
+
private async Task GetUserId(string username)
{
var response = await client.GetAsync($"/api/get-user-id?app={appVersion}&username={username}");
diff --git a/DevRant/Dtos/Profile.cs b/DevRant/Dtos/Profile.cs
index 89d0f05..51afff4 100644
--- a/DevRant/Dtos/Profile.cs
+++ b/DevRant/Dtos/Profile.cs
@@ -5,7 +5,6 @@ namespace DevRant.Dtos
///
/// Represents a data-transfer-object for a devrant profile.
///
- [JsonObject("profile")]
public class Profile
{
///
diff --git a/DevRant/Dtos/RantInfo.cs b/DevRant/Dtos/RantInfo.cs
new file mode 100644
index 0000000..ee3cbf4
--- /dev/null
+++ b/DevRant/Dtos/RantInfo.cs
@@ -0,0 +1,34 @@
+using Newtonsoft.Json;
+
+namespace DevRant.Dtos
+{
+ ///
+ /// Represents a data-transfer-object used for basic information about a rant.
+ ///
+ public class RantInfo
+ {
+ ///
+ /// Represents the identity of the rant.
+ ///
+ [JsonProperty("id")]
+ public int Id { get; set; }
+
+ ///
+ /// Represents the text of the rant.
+ ///
+ [JsonProperty("text")]
+ public string Text { get; set; }
+
+ ///
+ /// Represents the number of upvotes of the rant.
+ ///
+ [JsonProperty("num_upvotes")]
+ public int NrOfUpvotes { get; set; }
+
+ ///
+ /// Represents the number of downvotes of the rant.
+ ///
+ [JsonProperty("num_downvotes")]
+ public int NrOfDownvotes { get; set; }
+ }
+}
diff --git a/DevRant/Dtos/RantSort.cs b/DevRant/Dtos/RantSort.cs
new file mode 100644
index 0000000..81cb985
--- /dev/null
+++ b/DevRant/Dtos/RantSort.cs
@@ -0,0 +1,23 @@
+namespace DevRant.Dtos
+{
+ ///
+ /// Represents an enum which indicates the sorting of the rants list.
+ ///
+ public enum RantSort
+ {
+ ///
+ /// Indicates that the sorting is by algorithm.
+ ///
+ Algo = 0,
+
+ ///
+ /// Indicates that the sorting is by most recent.
+ ///
+ Recent = 1,
+
+ ///
+ /// Indicates that the sorting is by most upvotes.
+ ///
+ Top = 2
+ }
+}
diff --git a/DevRant/IDevRantClient.cs b/DevRant/IDevRantClient.cs
index ed1441c..55c9cdc 100644
--- a/DevRant/IDevRantClient.cs
+++ b/DevRant/IDevRantClient.cs
@@ -14,5 +14,13 @@ public interface IDevRantClient
///
/// Username of the profile to request.
Task GetProfileAsync(string username);
+
+ ///
+ /// Requests a collection of rants sorted and selected by the arguments from the rest-api.
+ ///
+ /// Sorting of the rant collection.
+ /// Maximal rants to return.
+ /// Number of rants to skip.
+ Task> GetRantsAsync(RantSort sort = RantSort.Algo, int limit = 50, int skip = 0);
}
}
\ No newline at end of file
diff --git a/README.md b/README.md
index 27728c9..665c19c 100644
--- a/README.md
+++ b/README.md
@@ -25,10 +25,12 @@ The code below is an example how to use the library.
```
using DevRant;
-
+using DevRant.Dtos;
+....
using(var devRant = new DevRantClient())
{
var profile = await devRant.GetProfileAsync("WichardRiezebos");
+ var topTenRants = await devRant.GetRantsAsync(sort: RantSort.Top, limit: 10);
}
```
@@ -37,8 +39,8 @@ All the available rest-api method(s) are described below:
| API | METHOD | DESCRIPTION |
| --- | --- | --- |
-| [/api/user/{id}/](http://devrant.io/api/users/404181?app=3) | [GetProfileAsync](#getprofileasync) | Gets the complete profile of a devRant user. |
-| - | - | - |
+| [/api/user/{id}/](https://devrant.io/api/users/404181?app=3) | [GetProfileAsync](#getprofileasync) | Gets the complete profile of a devRant user. |
+| [/api/devrant/rants/](https://devrant.io/api/devrant/rants?app=3&sort=algo&limit=50&skip=0) | [GetRantsAsync](#getrantsasync) | Gets a collection with rants. |
### GetProfileAsync
@@ -47,6 +49,15 @@ All the available rest-api method(s) are described below:
| --- | --- | --- |
| username | yes | string |
+### GetRantsAsync
+
+###### Arguments
+| NAME | MANDATORY | TYPE | DEFAULT |
+| --- | --- | --- | --- |
+| sort | no | enum (algo, recent and top) | algo |
+| limit | no | int | 50 |
+| skip | no | int | 0 |
+
## Limitations
- Not all methods are available yet.