-
Notifications
You must be signed in to change notification settings - Fork 2
Documentation
Ihtasham edited this page Dec 12, 2017
·
14 revisions
devRantDotNet is a C# wrapper library providing easy access to the devRant API. Please visit devRant for more information about what it is.
using dr = new devRant(){}
| Method | Parameters | TYPE | EXAMPLE |
|---|---|---|---|
| GetRantsAsync() | SortType = SortType.algo (algo, top, recent) - Optional limit=30 - Optional skip=10 - Optional |
List | dr.GetRantAsync(SortType.recent, 20, 15) |
| GetRantAsync() | id - Required | Rant | dr.GetRantAsync(455045) |
| GetUserIdAsync() | username - Required | int | dr.GetUserIdAsync("px06") |
| GetProfileAsync() | id - Required | User | dr.GetProfileAsync(428514) |
| SearchAsync() | term - Required | List | dr.SearchAsync("hello world") |
| GetRandomRantAsync() | Rant | dr.GetRandomRantAsync() |
| Property | Description |
|---|---|
| id | long - The Id of the rant |
| text | string - The content of the rant |
| num_upvotes | int - The number of up votes on the rant |
| num_downvotes | int - The number of down votes on the rant |
| score | int - Total score of the rant |
| created_time | long - Time rant was created (milliseconds) |
| attachedImageUrl | string - The url of the attached image to the rant if there is any |
| num_comments | string - Number of comments on the rant |
| tags | string list - The tags on the rant |
| vote_state | int - The current user's vote state (0 = no vote, 1 = ++, -1 = --). Always 0 if the parameters user_id, token_id and token_key are missing (aka. not logged user) |
| user_id | long - The id of the user who submitted the rant |
| user_username | string - The username of the user who submitted the rant |
| user_score | long - The score of the user who submitted the rant |
| user_avatar_url | string - The URL of the avatar of the user who submitted the rant |
| rant_comments | Comment list - The list of comments on the rant |
| Property | Description |
|---|---|
| id | long - The Id of the comment |
| rant_id | long - The Id of the rant that the comment belongs to |
| body | string - The content of the comment |
| num_upvotes | int - The number of up votes on the comment |
| num_downvotes | int - The number of down votes on the comment |
| score | int - The total score of the comment |
| created_time | long - Time comment was created (milliseconds) |
| vote_state | int - The current user's vote state (0 = no vote, 1 = ++, -1 = --). Always 0 if the parameters user_id, token_id and token_key are missing (aka. not logged user) |
| user_username | string - The username of the user who submitted the comment |
| user_score | long - The score of the user who submitted the comment |
| user_avatar | string - The URL of the avatar of the user who submitted the comment |
You can see the devRantTests project for some play around sample code, however for convenience the below can be done.
This is a Console Application with Newtonsoft.Json and devRantDotNet installed via nuget.
class Program
{
static void Main(string[] args)
{
using (devRant d = new devRant())
{
// Getting all recent rants:
var allRants = d.GetRantsAsync(devRant.SortType.recent).Result;
// Find a rant by its id:
var rantById = d.GetRantAsync(455045).Result;
// Finding a user's id by their name (useful to find a profile):
var userByName = d.GetUserIdAsync("px06").Result;
// Getting a profile by Id, you can use the actual id if you know it or just use ther result from before:
var userProfile = d.GetProfileAsync(userByName);
// Finding result from a search:
var searchResults = d.SearchAsync("hello world").Result;
// You can iterate these results because it's a list:
Console.WriteLine(searchResults.Count);
searchResults.ForEach(s => Console.WriteLine(s.text));
// Finding a random rant with a score of 20 or more:
var randomRant = d.GetRandomRantAsync().Result;
if(randomRant.num_upvotes < 20)
{
throw new Exception(); // Could just be the API playing up here too
}
}
}
}| Method | CALL |
|---|---|
| GetRantsAsync() | /api/devrant/rants?sort=recent&limit=20&skip=15&app=3 |
| GetRantAsync() | /api/devrant/rants/455045?app=3 |
| GetUserIdAsync() | /api/get-user-id?username=px06&app=3 |
| GetProfileAsync() | /api/users/428514?app=3 |
| SearchAsync() | /api/devrant/search?term=hello world&app=3 |
| GetRandomRantAsync() | /api/devrant/rants/surprise?app=3 |