forum

C# Library for osu!api

posted
Total Posts
6
Topic Starter
Xferno2



Hello everyone!

Recently I was developing a Discord bot for my server and I wanted to add osu!api to my bot, unfortunately most of the api adaptation for C# were outdated and won't work so I decided to create my own. It uses the Newtonsoft Json library to parse the information into classes.
If you find any parsing errors, feel free to create an issue on github or reply here.

The following parts from osu!api are supported:

Beatmap []

User []

Scores []

Best Performance []

Recently Played []

Multiplayer []

Replay []




Details
Available for all .NET Framework languages: CLS Compilant []

Build Version:

Downloads:



Thanks for checking out my post.
Xferno2
-Makishima S-
1. Unify GetBeatmapset and GetBeatmap:

public OsuBeatmap GetBeatmapSet(int id, bool isSet = true)
{
string html = (isSet) ? GetUrl(BeatmapSet(id)) : GetUrl(Beatmap(id));
.
.
.
}

2. Deserialize directly to object, it requires way less code and makes it easier to read and maintain.
(from my private API lib) - https://puu.sh/vxUbh.png - left side example, right is random usage

3. Avoid using dynamic when it comes to objects. 'dynamic' is not a type, nor an object. It was primarily introduced as a way to allow C# to interop with languages such as Python, which is not statically typed. If you are using it out of this context you are probably forgoing functionality.

4. If you are building library, imo good habit is making XML documentation comments. Helps end-dev who use it to not look into documentation for "what is what".
/// - shortcut to shippet in visual studio

Good luck!
This can be solid, if i find time I may commit something myself to this.
Topic Starter
Xferno2

[Taiga] wrote:

1. Unify GetBeatmapset and GetBeatmap:

public OsuBeatmap GetBeatmapSet(int id, bool isSet = true)
{
string html = (isSet) ? GetUrl(BeatmapSet(id)) : GetUrl(Beatmap(id));
.
.
.
}

2. Deserialize directly to object, it requires way less code and makes it easier to read and maintain.
(from my private API lib) - https://puu.sh/vxUbh.png - left side example, right is random usage

3. Avoid using dynamic when it comes to objects. 'dynamic' is not a type, nor an object. It was primarily introduced as a way to allow C# to interop with languages such as Python, which is not statically typed. If you are using it out of this context you are probably forgoing functionality.

4. If you are building library, imo good habit is making XML documentation comments. Helps end-dev who use it to not look into documentation for "what is what".
/// - shortcut to shippet in visual studio

Good luck!
This can be solid, if i find time I may commit something myself to this.
Done with all of them, just commit to Github a minute ago. Thanks for help!
Topic Starter
Xferno2
I've added a way to export replay data as .osr
Everything is done except from adding some error handlers and cleaning up the code a bit.
octagonal
>open repo

>see this

using (WebClient webclient = new WebClient())
{
using (WebClient client = new WebClient())
{
html = client.DownloadString(url);
}
}

>close repo
Topic Starter
Xferno2

octagonal wrote:

>open repo

>see this

using (WebClient webclient = new WebClient())
{
using (WebClient client = new WebClient())
{
html = client.DownloadString(url);
}
}

>close repo
¯\_(ツ)_/¯ , still have to change some things. Is a part from my discord bot code, I forgot to change it
Please sign in to reply.

New reply