aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn/UniteClient.cs
blob: 1136b5c74e0a7e3597338945a734f8a7c543a265 (plain) (blame)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace ShiftOS.Unite
{
    public class UniteClient
    {
        public string Token { get; private set; }
        public string BaseURL { get; private set; }

        public string GetDisplayNameId(string id)
        {
            return MakeCall("/API/GetDisplayName/" + id);
        }

        public PongHighscoreModel GetPongHighscores()
        {
            return JsonConvert.DeserializeObject<PongHighscoreModel>(MakeCall("/API/GetPongHighscores"));
        }

        public UniteClient(string baseurl, string usertoken)
        {
            BaseURL = baseurl;
            Token = usertoken;
        }

        internal string MakeCall(string url)
        {
            var webrequest = WebRequest.Create(BaseURL + url);
            webrequest.Headers.Add("Authentication: Token " + Token);
            using (var response = webrequest.GetResponse())
            {
                using (var stream = response.GetResponseStream())
                {
                    using (var reader = new System.IO.StreamReader(stream))
                    {
                        return reader.ReadToEnd();
                    }
                }
            }
        }

        public int GetPongCP()
        {
            return Convert.ToInt32(MakeCall("/API/GetPongCP"));
        }

        public int GetPongLevel()
        {
            return Convert.ToInt32(MakeCall("/API/GetPongLevel"));
        }

        public void SetPongLevel(int value)
        {
            MakeCall("/API/SetPongLevel/" + value.ToString());
        }

        public void SetPongCP(int value)
        {
            MakeCall("/API/SetPongCP/" + value.ToString());
        }

        public string GetEmail()
        {
            return MakeCall("/API/GetEmail");
        }

        public string GetSysName()
        {
            return MakeCall("/API/GetSysName");
        }

        public void SetSysName(string value)
        {
            MakeCall("/API/SetSysName/" + value);
        }

        public string GetDisplayName()
        {
            return MakeCall("/API/GetDisplayName");
        }

        public void SetDisplayName(string value)
        {
            MakeCall("/API/SetDisplayName/" + value.ToString());
        }

        public string GetFullName()
        {
            return MakeCall("/API/GetFullName");
        }

        public void SetFullName(string value)
        {
            MakeCall("/API/SetFullName/" + value.ToString());
        }


        public long GetCodepoints()
        {
            return Convert.ToInt64(MakeCall("/API/GetCodepoints"));
        }

        public void SetCodepoints(long value)
        {
            MakeCall("/API/SetCodepoints/" + value.ToString());
        }
    }

    public class PongHighscoreModel
    {
        public int Pages { get; set; }
        public PongHighscore[] Highscores { get; set; }
    }

    public class PongHighscore
    {
        public string UserId { get; set; }
        public int Level { get; set; }
        public long CodepointsCashout { get; set; }
    }
}