Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #57 from lolPants/master
Browse files Browse the repository at this point in the history
Use paginated ModSaber endpoint
  • Loading branch information
Umbranoxio authored Sep 18, 2018
2 parents 927cf4b + 899a11d commit 5eacb6d
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions BeatSaberModManager/Core/RemoteLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ namespace BeatSaberModManager.Core
{
public class RemoteLogic
{
private const string EndPoint = "https://www.modsaber.ml/";
private const Int16 CurrentVersion = 11;
private const string ModSaberURL = "https://www.modsaber.ml";
private const string ApiVersion = "1.0";
private readonly string ApiURL = $"{ModSaberURL}/api/v{ApiVersion}";

private const Int16 CurrentVersion = 12;
private string currentGameVersion = string.Empty;
public List<ReleaseInfo> releases;
public RemoteLogic()
{
releases = new List<ReleaseInfo>();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
}

public void GetCurrentGameVersion()
{
string raw = CallApiFunction("api/public/gameversions");
string raw = Fetch($"{ApiURL}/site/gameversions");
var decoded = JSON.Parse(raw);
var current = decoded[0];
var value = current["value"];
Expand All @@ -29,11 +33,10 @@ public void GetCurrentGameVersion()

public void PopulateReleases()
{
string raw = CallApiFunction("api/public/temp/approved");
string raw = GetModSaberReleases();
if (raw != null)
{
var decoded = JSON.Parse(raw);
var mods = decoded["mods"];
var mods = JSON.Parse(raw);
for (int i = 0; i < mods.Count; i++)
{
var current = mods[i];
Expand All @@ -55,17 +58,37 @@ public void PopulateReleases()
}
}
}
private string CallApiFunction(string function)

private string Fetch(string URL) => Helper.Get(URL);

private string GetModSaberReleases()
{
return Helper.Get(string.Format("{0}{1}", EndPoint, function));
string raw = Fetch($"{ApiURL}/mods/approved");
var decoded = JSON.Parse(raw);
int lastPage = decoded["lastPage"];

JSONArray final = new JSONArray();

for (int i = 0; i <= lastPage; i++)
{
string page = Fetch($"{ApiURL}/mods/approved/{i}");
var pageDecoded = JSON.Parse(page);
var mods = pageDecoded["mods"];

foreach (var x in mods)
final.Add(x.Value);
}
return final.ToString();
}

private void CreateRelease(ReleaseInfo release)
{
if (release.gameVersion == currentGameVersion)
{
releases.Add(release);
}
}

public void CheckVersion()
{
//TODO: Don't be lazy and actually make an auto updater
Expand Down

0 comments on commit 5eacb6d

Please sign in to comment.