Skip to content

Commit 02a9b17

Browse files
Added Tests / Example projects to show the usage of the API in a WinForms application and Console Application.
1 parent 3de5118 commit 02a9b17

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3090
-538
lines changed

docs/Todo.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ OAuth
77
Code
88
- [ ] Flesh out the structure of the code to make it simpler to read
99
- [ ] Trap responses in a try catch etc.
10+
- [ ] Write comments documentation
11+
- [ ] Write xml documentation
1012

1113
.Net Wrapper
1214
- [ ] A simpler way of handling everything
1315
- [ ] Store token for usage later, less calls to api and less database storage requirement
14-
16+
- [ ] Asynchronous methods with callbacks for gui implementations
17+
1518
PHP Server
1619
- [ ] Flesh out authentication
1720
- [ ] Find and fix any exploits
File renamed without changes.

res/images/logo-white-alt.png

2.13 KB
Loading
52.5 KB
Binary file not shown.

src/LiveCoding.TV .NET API Wrapper.sln

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ VisualStudioVersion = 14.0.25420.1
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiveCoding.TV .NET API Wrapper", "LiveCodingTV\LiveCoding.TV .NET API Wrapper.csproj", "{36C8BF1D-9F44-4461-870E-6951DFA43DD8}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiveCoding.Net", "..\old\src\LiveCoding.Net\LiveCoding.Net.csproj", "{65186984-815A-4260-B55D-63BFE3E34608}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console -GetUserInformation", "Tests\Console_GetUserInformation\Console -GetUserInformation.csproj", "{3FBDD3A0-0020-4FEA-BB02-BD32CBEDB2AB}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication", "TestApplication\TestApplication.csproj", "{3FBDD3A0-0020-4FEA-BB02-BD32CBEDB2AB}"
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{2938F69F-DDF4-4A54-8055-E388FCAB8B28}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinForms - Implementing A GUI", "WinForms_GetUserInformation\WinForms - Implementing A GUI.csproj", "{5BC09953-B2B7-4200-A8B2-EDBD36BAD770}"
1113
EndProject
1214
Global
1315
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -19,16 +21,20 @@ Global
1921
{36C8BF1D-9F44-4461-870E-6951DFA43DD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
2022
{36C8BF1D-9F44-4461-870E-6951DFA43DD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
2123
{36C8BF1D-9F44-4461-870E-6951DFA43DD8}.Release|Any CPU.Build.0 = Release|Any CPU
22-
{65186984-815A-4260-B55D-63BFE3E34608}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23-
{65186984-815A-4260-B55D-63BFE3E34608}.Debug|Any CPU.Build.0 = Debug|Any CPU
24-
{65186984-815A-4260-B55D-63BFE3E34608}.Release|Any CPU.ActiveCfg = Release|Any CPU
25-
{65186984-815A-4260-B55D-63BFE3E34608}.Release|Any CPU.Build.0 = Release|Any CPU
2624
{3FBDD3A0-0020-4FEA-BB02-BD32CBEDB2AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2725
{3FBDD3A0-0020-4FEA-BB02-BD32CBEDB2AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
2826
{3FBDD3A0-0020-4FEA-BB02-BD32CBEDB2AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
2927
{3FBDD3A0-0020-4FEA-BB02-BD32CBEDB2AB}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{5BC09953-B2B7-4200-A8B2-EDBD36BAD770}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{5BC09953-B2B7-4200-A8B2-EDBD36BAD770}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{5BC09953-B2B7-4200-A8B2-EDBD36BAD770}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{5BC09953-B2B7-4200-A8B2-EDBD36BAD770}.Release|Any CPU.Build.0 = Release|Any CPU
3032
EndGlobalSection
3133
GlobalSection(SolutionProperties) = preSolution
3234
HideSolutionNode = FALSE
3335
EndGlobalSection
36+
GlobalSection(NestedProjects) = preSolution
37+
{3FBDD3A0-0020-4FEA-BB02-BD32CBEDB2AB} = {2938F69F-DDF4-4A54-8055-E388FCAB8B28}
38+
{5BC09953-B2B7-4200-A8B2-EDBD36BAD770} = {2938F69F-DDF4-4A54-8055-E388FCAB8B28}
39+
EndGlobalSection
3440
EndGlobal

src/LiveCodingTV/API/APIRequestHandler.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ private static string FormatJson(string json) {
1515
}
1616

1717
public string getAPIJson(string apiReqURL, oAuthAuth oaCreds, bool formatted = false) {
18-
HttpWebRequest timeLineRequest =
18+
HttpWebRequest apiRequest =
1919
(HttpWebRequest)WebRequest.Create(apiReqURL);
2020

2121
var apiReqHeaders = "{0} {1}";
22-
timeLineRequest.Headers.Add("Authorization",
22+
apiRequest.Headers.Add("Authorization",
2323
string.Format(apiReqHeaders, oaCreds.token_type, oaCreds.access_token));
2424

25-
timeLineRequest.Method = "Get";
25+
apiRequest.Method = "Get";
2626

27-
WebResponse response = timeLineRequest.GetResponse();
27+
28+
29+
WebResponse response = apiRequest.GetResponse();
2830
var responseJSON = string.Empty;
2931
using (response)
3032
using (var reader = new StreamReader(response.GetResponseStream()))

src/LiveCodingTV/API/APIResources.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public static string
2727
UserVideos = User + "livestreams/videos/",
2828
UserVideosLatest = User + "livestreams/videos/latest/",
2929

30+
Users = APIBasePath + "users/",
31+
3032
PublicUserInfo = APIBasePath + "users/",
3133
Videos = APIBasePath + "videos/";
3234

src/LiveCodingTV/API/Engine.cs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6+
using LiveCodingTV.API.Wrappers;
7+
using LiveCodingTV.API.Wrappers.Models;
68

79
namespace LiveCodingTV.API {
810

@@ -48,16 +50,53 @@ public enum APICall {
4850
}
4951

5052
public class Engine {
51-
private Server.Request req;
53+
APIRequestHandler aReq = new APIRequestHandler();
54+
oAuthAuth oaCreds;
55+
Serializer ser = new Serializer();
5256

57+
public Engine(oAuthAuth token) {
58+
this.oaCreds = token;
59+
}
60+
61+
62+
public IUser getCurrentUser() {
63+
var jsonString = aReq.getAPIJson(APIResources.User, oaCreds, true);
64+
65+
IUser obj;
66+
var state = ser.toUser(jsonString, out obj);
67+
if (state.Error)
68+
return null;
69+
else return obj;
70+
}
71+
72+
public IUser getUser(string user) {
73+
var jsonString = aReq.getAPIJson($"{APIResources.Users}{user}/", oaCreds, true);
5374

54-
public Engine(Server.Request request) {
55-
this.req = request;
75+
IUser obj;
76+
var state = ser.toUser(jsonString, out obj);
77+
if (state.Error)
78+
return null;
79+
else return obj;
5680
}
5781

82+
public ILivestreamList getLivestreamsFromURL(string url) {
83+
var jsonString = aReq.getAPIJson(url, oaCreds, true);
84+
85+
ILivestreamList obj;
86+
var state = ser.toLivestreams(jsonString, out obj);
87+
if (state.Error)
88+
return null;
89+
else return obj;
90+
}
5891

59-
public void CreateAPICall(APICall request) {
92+
public ILivestreamList getLivestreamsOnAIR() {
93+
var jsonString = aReq.getAPIJson(APIResources.LivestreamsOA, oaCreds, true);
6094

95+
ILivestreamList obj;
96+
var state = ser.toLivestreams(jsonString, out obj);
97+
if (state.Error)
98+
return null;
99+
else return obj;
61100
}
62101
}
63102
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Newtonsoft.Json.Linq;
7+
8+
namespace LiveCodingTV.API.Wrappers {
9+
public enum HTTPResponse {
10+
Success = 200,
11+
Unauthorised = 403,
12+
Error = 500,
13+
14+
NoResponse = 0 // Request recieved no response!
15+
}
16+
17+
public enum ResponseState {
18+
Success,
19+
Error
20+
}
21+
22+
public abstract class IAPIResponse {
23+
protected string detail;
24+
25+
public string ErrorDetails { get { return detail; } }
26+
27+
public bool Valid {
28+
get { return (detail == null); }
29+
}
30+
}
31+
32+
public abstract class IAPIResponseList {
33+
protected Serializer sz = new Serializer();
34+
35+
// API RESPONSES
36+
protected int count;
37+
protected string next, previous;
38+
protected JToken results; // This should be serialized into the required list of objects
39+
40+
41+
public int Count { get { return this.count; } }
42+
public string URLNext { get { return this.next; } }
43+
public string URLPrevious { get { return this.previous; } }
44+
}
45+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Newtonsoft.Json;
7+
using static LiveCodingTV.API.Wrappers.Serializer;
8+
9+
namespace LiveCodingTV.API.Wrappers.Models {
10+
/**
11+
12+
JSON Schema:
13+
ICodingCategory {
14+
url (string),
15+
name (string),
16+
sort (integer)
17+
}
18+
19+
JSON Result:
20+
{
21+
"url": "",
22+
"name": "",
23+
"sort": 0
24+
}
25+
26+
Description:
27+
URL - Url link to the coding category
28+
Name - Name of the coding category
29+
Sort - ????
30+
*/
31+
public class ICodingCategory {
32+
public string
33+
url,
34+
name;
35+
public int
36+
sort;
37+
}
38+
39+
/**
40+
JSON Schema:
41+
ICodingCategoryList {
42+
count (string),
43+
next (string),
44+
previous (string),
45+
results (array : ICodingCategory)
46+
}
47+
48+
JSON Results: {
49+
"count": 0,
50+
"next": "",
51+
"previous": "",
52+
"results": []
53+
}
54+
55+
Description:
56+
Count - This is the total count of coding categories
57+
Next - The link to query the next set of categories
58+
Previous - The link to query the previous set of categories
59+
Results - A array of the cateogies used on LiveCoding.tv
60+
*/
61+
public class ICodingCategoryList : IAPIResponseList {
62+
public ICodingCategory[] Categories {
63+
get {
64+
string json = results.ToString();
65+
var set = new JsonSerializerSettings() { ContractResolver = new MyContractResolver() };
66+
var objs = JsonConvert.DeserializeObject<ICodingCategory[]>(json, set);
67+
return objs;
68+
}
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)