Skip to content

Commit 5b07311

Browse files
committed
Initial Commit
0 parents  commit 5b07311

14 files changed

+687
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
bin
3+
obj

ATLauncherAPI.csproj

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<Company>HypherionMC</Company>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
10+
</ItemGroup>
11+
12+
</Project>

ATLauncherAPI.sln

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ATLauncherAPI", "ATLauncherAPI.csproj", "{CF3E4D1D-61D7-40E1-8BD6-FC51D66DC36D}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Any CPU = Debug|Any CPU
8+
Release|Any CPU = Release|Any CPU
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{CF3E4D1D-61D7-40E1-8BD6-FC51D66DC36D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{CF3E4D1D-61D7-40E1-8BD6-FC51D66DC36D}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{CF3E4D1D-61D7-40E1-8BD6-FC51D66DC36D}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{CF3E4D1D-61D7-40E1-8BD6-FC51D66DC36D}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal

ATLauncherAPIClient.cs

+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
using System;
2+
using System.Net;
3+
using System.Text;
4+
using ATLauncherAPI.apiobjects;
5+
using Newtonsoft.Json;
6+
7+
namespace ATLauncherAPI
8+
{
9+
10+
public class ATLauncherAPIClient
11+
{
12+
/* Private API Variables */
13+
private WebClient client = new WebClient() { Encoding = Encoding.UTF8 };
14+
private String apiurl = "https://api.atlauncher.com/v1/";
15+
private Logger logger = Logger.getLogger("AT-API");
16+
17+
/***
18+
* Get info about a modpack
19+
* @param safename - The name of the modpack to search for (Case Sensitive and NO SPACES ALLOWED)
20+
* @return
21+
*/
22+
public Optional<PackResult> getPackInfo(string safename)
23+
{
24+
try
25+
{
26+
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
27+
String response = client.DownloadString(apiurl + "pack/" + safename + "/");
28+
29+
if (!string.IsNullOrEmpty(response))
30+
{
31+
PackResult packResult = JsonConvert.DeserializeObject<PackResult>(response);
32+
return new Optional<PackResult>(packResult);
33+
}
34+
}
35+
catch (Exception ex)
36+
{
37+
logger.error(ex.Message);
38+
}
39+
40+
return new Optional<PackResult>();
41+
}
42+
43+
/***
44+
* Get basic information about a single version of the modpack
45+
* @param safename - The name of the modpack to search for (Case Sensitive and NO SPACES ALLOWED)
46+
* @param version - Version to lookup (Use latest to get the newest version)
47+
* @return
48+
*/
49+
public Optional<PackVersionResult> getPackVersion(String safename, String version) {
50+
try {
51+
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
52+
String response = client.DownloadString(apiurl + "pack/" + safename + "/" + version + "/");
53+
54+
if (!string.IsNullOrEmpty(response))
55+
{
56+
PackVersionResult packVersionResult = JsonConvert.DeserializeObject<PackVersionResult>(response);
57+
return new Optional<PackVersionResult>(packVersionResult);
58+
} else {
59+
throw new Exception("Could not retrieve result from API");
60+
}
61+
} catch (Exception ex) {
62+
logger.error(ex.Message);
63+
}
64+
65+
return new Optional<PackVersionResult>();
66+
}
67+
68+
/***
69+
* Get a collection of basic information of all published modpacks
70+
* @return
71+
*/
72+
public Optional<SimplePackResult> getSimplePackInfo() {
73+
74+
try {
75+
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
76+
String response = client.DownloadString(apiurl + "packs/simple/");
77+
78+
if (!string.IsNullOrEmpty(response))
79+
{
80+
SimplePackResult simplePackResult = JsonConvert.DeserializeObject<SimplePackResult>(response);
81+
return new Optional<SimplePackResult>(simplePackResult);
82+
} else {
83+
throw new Exception("Could not retrieve result from API");
84+
}
85+
} catch (Exception ex) {
86+
logger.error(ex.Message);
87+
}
88+
89+
return new Optional<SimplePackResult>();
90+
}
91+
92+
/***
93+
* Gets the full info about ALL published modpacks
94+
* @return
95+
*/
96+
public Optional<PackArrayResult> getAllPacks() {
97+
98+
try {
99+
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
100+
String response = client.DownloadString(apiurl + "packs/full/all/");
101+
102+
if (!string.IsNullOrEmpty(response))
103+
{
104+
PackArrayResult packArrayResult = JsonConvert.DeserializeObject<PackArrayResult>(response);
105+
return new Optional<PackArrayResult>(packArrayResult);
106+
} else {
107+
throw new Exception("Could not retrieve result from API");
108+
}
109+
} catch (Exception ex) {
110+
logger.error(ex.Message);
111+
}
112+
113+
return new Optional<PackArrayResult>();
114+
}
115+
116+
/***
117+
* Gets the full info about ALL published modpacks marked as public
118+
* @return
119+
*/
120+
public Optional<PackArrayResult> getPublicPacks() {
121+
122+
try {
123+
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
124+
String response = client.DownloadString(apiurl + "packs/full/public/");
125+
126+
if (!string.IsNullOrEmpty(response))
127+
{
128+
PackArrayResult packArrayResult = JsonConvert.DeserializeObject<PackArrayResult>(response);
129+
return new Optional<PackArrayResult>(packArrayResult);
130+
} else {
131+
throw new Exception("Could not retrieve result from API");
132+
}
133+
} catch (Exception ex) {
134+
logger.error(ex.Message);
135+
}
136+
137+
return new Optional<PackArrayResult>();
138+
}
139+
140+
/***
141+
* Gets the full info about ALL published modpacks marked as semi-public
142+
* @return
143+
*/
144+
public Optional<PackArrayResult> getSemiPublicPacks() {
145+
try {
146+
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
147+
String response = client.DownloadString(apiurl + "packs/full/semipublic/");
148+
149+
if (!string.IsNullOrEmpty(response))
150+
{
151+
PackArrayResult packArrayResult = JsonConvert.DeserializeObject<PackArrayResult>(response);
152+
return new Optional<PackArrayResult>(packArrayResult);
153+
} else {
154+
throw new Exception("Could not retrieve result from API");
155+
}
156+
} catch (Exception ex) {
157+
logger.error(ex.Message);
158+
}
159+
160+
return new Optional<PackArrayResult>();
161+
}
162+
163+
/***
164+
* Gets the full info about ALL published modpacks marked as private
165+
* @return
166+
*/
167+
public Optional<PackArrayResult> getPrivatePacks() {
168+
try {
169+
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
170+
String response = client.DownloadString(apiurl + "packs/full/private/");
171+
172+
if (!string.IsNullOrEmpty(response))
173+
{
174+
PackArrayResult packArrayResult = JsonConvert.DeserializeObject<PackArrayResult>(response);
175+
return new Optional<PackArrayResult>(packArrayResult);
176+
} else {
177+
throw new Exception("Could not retrieve result from API");
178+
}
179+
} catch (Exception ex) {
180+
logger.error(ex.Message);
181+
}
182+
183+
return new Optional<PackArrayResult>();
184+
}
185+
}
186+
}

apiobjects/PackArrayResult.cs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using ATLauncherAPI.apiobjects.helpers;
4+
5+
namespace ATLauncherAPI.apiobjects
6+
{
7+
public class PackArrayResult
8+
{
9+
private bool error;
10+
private int code;
11+
private String message;
12+
private List<PackObject> data;
13+
14+
public PackArrayResult(bool error, int code, String message, List<PackObject> data) {
15+
this.error = error;
16+
this.code = code;
17+
this.message = message;
18+
this.data = data;
19+
}
20+
21+
/***
22+
* Get the error code returned by the API in the case of failure
23+
* @return
24+
*/
25+
public int getCode() {
26+
return code;
27+
}
28+
29+
/***
30+
* Check if the API call encountered an error
31+
* @return
32+
*/
33+
public bool isError() {
34+
return error;
35+
}
36+
37+
/***
38+
* Returns a PackObject containing the modpack info
39+
* @return
40+
*/
41+
public List<PackObject> getData() {
42+
return data;
43+
}
44+
45+
/***
46+
* Get the error message returned by the api. (NULL when no error)
47+
* @return
48+
*/
49+
public String getMessage() {
50+
return message;
51+
}
52+
}
53+
}

apiobjects/PackResult.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using ATLauncherAPI.apiobjects.helpers;
3+
4+
namespace ATLauncherAPI.apiobjects
5+
{
6+
public class PackResult
7+
{
8+
private bool error;
9+
private int code;
10+
private String message;
11+
private PackObject data;
12+
13+
public PackResult(bool error, int code, String message, PackObject data) {
14+
this.error = error;
15+
this.code = code;
16+
this.message = message;
17+
this.data = data;
18+
}
19+
20+
public int getCode() {
21+
return code;
22+
}
23+
24+
public bool isError() {
25+
return error;
26+
}
27+
28+
public PackObject getData() {
29+
return data;
30+
}
31+
32+
public String getMessage() {
33+
return message;
34+
}
35+
}
36+
}

apiobjects/PackVersionResult.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using ATLauncherAPI.apiobjects.helpers;
3+
4+
namespace ATLauncherAPI.apiobjects
5+
{
6+
public class PackVersionResult
7+
{
8+
private bool error;
9+
private int code;
10+
private String message;
11+
private PackVersionObject data;
12+
13+
public PackVersionResult(bool error, int code, String message, PackVersionObject data) {
14+
this.error = error;
15+
this.code = code;
16+
this.message = message;
17+
this.data = data;
18+
}
19+
20+
public int getCode() {
21+
return code;
22+
}
23+
24+
public bool isError() {
25+
return error;
26+
}
27+
28+
public PackVersionObject getData() {
29+
return data;
30+
}
31+
32+
public String getMessage() {
33+
return message;
34+
}
35+
}
36+
}

apiobjects/SimplePackResult.cs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using ATLauncherAPI.apiobjects.helpers;
4+
5+
namespace ATLauncherAPI.apiobjects
6+
{
7+
public class SimplePackResult
8+
{
9+
private bool error;
10+
private int code;
11+
private String message;
12+
private List<SimplePackObject> data;
13+
14+
public SimplePackResult(bool error, int code, String message, List<SimplePackObject> data) {
15+
this.error = error;
16+
this.code = code;
17+
this.message = message;
18+
this.data = data;
19+
}
20+
21+
public int getCode() {
22+
return code;
23+
}
24+
25+
public bool isError() {
26+
return error;
27+
}
28+
29+
public List<SimplePackObject> getData() {
30+
return data;
31+
}
32+
33+
public String getMessage() {
34+
return message;
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)