-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayentry.cs
More file actions
70 lines (54 loc) · 2.04 KB
/
Playentry.cs
File metadata and controls
70 lines (54 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
namespace Playentry
{
class Http
{
public static string RequestGet(string url)
{
string responseText = string.Empty;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
{
HttpStatusCode status = resp.StatusCode;
Stream respStream = resp.GetResponseStream();
responseText = new StreamReader(respStream).ReadToEnd();
}
return responseText;
}
}
public class PlayentryClient
{
const string Domain = "https://playentry.org";
public static List<ProjectThumbnail> GetStaffPicks(int limit = 3)
{
string response = Http.RequestGet(Domain + $"/api/rankProject?type=staff&limit={limit}");
List<ProjectThumbnail> staffPicks = new List<ProjectThumbnail>();
JObject json = JObject.Parse($"{{\"value\":{response}}}");
for (int i = 0; i < limit; i++)
staffPicks.Add(new ProjectThumbnail(json["value"][i]));
return staffPicks;
}
public static List<ProjectThumbnail> GetBestProjects(int limit = 9)
{
string response = Http.RequestGet(Domain + $"/api/rankProject?type=best&limit={limit}");
List<ProjectThumbnail> bestProjects = new List<ProjectThumbnail>();
JObject json = JObject.Parse($"{{\"value\":{response}}}");
for (int i = 0; i < limit; i++)
bestProjects.Add(new ProjectThumbnail(json["value"][i]));
return bestProjects;
}
public static Project GetProjectByID(string ProjectID)
{
return new Project(ProjectID);
}
public static User GetUserByUsername(string Username)
{
return new User(Username);
}
}
}