Skip to content

Commit fe1026a

Browse files
committed
Use jsonProperty for all models
1 parent cf08040 commit fe1026a

11 files changed

Lines changed: 101 additions & 56 deletions

WebUntisAPI.Client/Exceptions/WebUntisException.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Runtime.Serialization;
@@ -31,12 +32,14 @@ public enum Codes
3132
/// <summary>
3233
/// Code of the error
3334
/// </summary>
34-
public int code { get; set; }
35+
[JsonProperty("code")]
36+
public int Code { get; set; }
3537

3638
/// <summary>
3739
/// A message that describes the error
3840
/// </summary>
39-
public string message { get; set; }
41+
[JsonProperty("message")]
42+
public override string Message { get; }
4043

4144
/// <summary>
4245
/// A new <see cref="WebUntisException"/>
@@ -45,8 +48,8 @@ public enum Codes
4548
/// <param name="message">Message</param>
4649
public WebUntisException(int code, string message) : base(message)
4750
{
48-
this.code = code;
49-
this.message = message;
51+
this.Code = code;
52+
this.Message = message;
5053
}
5154
}
5255
}

WebUntisAPI.Client/Models/IUser.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace WebUntisAPI.Client.Models
8+
{
9+
public interface IUser
10+
{
11+
int id { get; set; }
12+
}
13+
}

WebUntisAPI.Client/Models/JSONRPCRequestModel.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Runtime.Serialization;
@@ -16,21 +17,25 @@ internal class JSONRPCRequestModel<TParam>
1617
/// <summary>
1718
/// Identifies the request (repeated in response)
1819
/// </summary>
19-
public string id;
20+
[JsonProperty("id")]
21+
public string Id { get; set; }
2022

2123
/// <summary>
2224
/// Name of the method to call
2325
/// </summary>
24-
public string method;
26+
[JsonProperty("method")]
27+
public string Method { get; set; }
2528

2629
/// <summary>
2730
/// Parameters for the method
2831
/// </summary>
29-
public TParam @params;
32+
[JsonProperty("params")]
33+
public TParam Params { get; set; }
3034

3135
/// <summary>
3236
/// Version of json rpc to use
3337
/// </summary>
34-
public string jsonrpc = "2.0";
38+
[JsonProperty("jsonrpc")]
39+
public string JSONRPC = "2.0";
3540
}
3641
}

WebUntisAPI.Client/Models/JSONRPCResponeModel.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Runtime.Serialization;
@@ -17,21 +18,25 @@ internal class JSONRPCResponeModel<TResult>
1718
/// <summary>
1819
/// Version of json rpc to use
1920
/// </summary>
20-
public string jsonrpc;
21+
[JsonProperty("jsonrpc")]
22+
public string JSONRPC { get; set; }
2123

2224
/// <summary>
2325
/// Identifies the request
2426
/// </summary>
25-
public string id;
27+
[JsonProperty("id")]
28+
public string Id { get; set; }
2629

2730
/// <summary>
2831
/// Result of the method
2932
/// </summary>
30-
public TResult result;
33+
[JsonProperty("result")]
34+
public TResult Result { get; set; }
3135

3236
/// <summary>
3337
/// A error while on the request
3438
/// </summary>
35-
public WebUntisException error = null;
39+
[JsonProperty("error")]
40+
public WebUntisException Error { get; set; } = null;
3641
}
3742
}

WebUntisAPI.Client/Models/LoginModel.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -14,16 +15,19 @@ internal struct LoginModel
1415
/// <summary>
1516
/// Username to login
1617
/// </summary>
17-
public string user;
18+
[JsonProperty("user")]
19+
public string User { get; set; }
1820

1921
/// <summary>
2022
/// Password for login
2123
/// </summary>
22-
public string password;
24+
[JsonProperty("password")]
25+
public string Password { get; set; }
2326

2427
/// <summary>
2528
/// Unique identifier for the client app
2629
/// </summary>
27-
public string client;
30+
[JsonProperty("client")]
31+
public string Client { get; set; }
2832
}
2933
}

WebUntisAPI.Client/Models/LoginResultModel.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -14,16 +15,19 @@ internal struct LoginResultModel
1415
/// <summary>
1516
/// Sesson of the login
1617
/// </summary>
17-
public string sessionId;
18+
[JsonProperty("sessionId")]
19+
public string SessionId { get; set; }
1820

1921
/// <summary>
2022
/// Type of the person
2123
/// </summary>
22-
public int personType;
24+
[JsonProperty("personType")]
25+
public int PersonType { get; set; }
2326

2427
/// <summary>
2528
/// Is of the person
2629
/// </summary>
27-
public int personId;
30+
[JsonProperty("personId")]
31+
public int PersonId { get; set; }
2832
}
2933
}

WebUntisAPI.Client/Models/School.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Runtime.Serialization;
@@ -15,31 +16,37 @@ public struct School
1516
/// <summary>
1617
/// Real name of the school
1718
/// </summary>
18-
public string displayName { get; set; }
19+
[JsonProperty("displayName")]
20+
public string DisplayName { get; set; }
1921

2022
/// <summary>
2123
/// Id of the school
2224
/// </summary>
23-
public long schoolId { get; set; }
25+
[JsonProperty("schoolId")]
26+
public long SchoolId { get; set; }
2427

2528
/// <summary>
2629
/// Login name of the school
2730
/// </summary>
28-
public string loginName { get; set; }
31+
[JsonProperty("loginName")]
32+
public string LoginName { get; set; }
2933

3034
/// <summary>
3135
/// Real address of the school
3236
/// </summary>
33-
public string address { get; set; }
37+
[JsonProperty("address")]
38+
public string Address { get; set; }
3439

3540
/// <summary>
3641
/// Server of the school
3742
/// </summary>
38-
public string server { get; set; }
43+
[JsonProperty("server")]
44+
public string Server { get; set; }
3945

4046
/// <summary>
4147
/// Server url of the school
4248
/// </summary>
43-
public string serverUrl { get; set; }
49+
[JsonProperty("serverUrl")]
50+
public string ServerUrl { get; set; }
4451
}
4552
}

WebUntisAPI.Client/Models/SchoolSearchModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -14,6 +15,7 @@ internal struct SchoolSearchModel
1415
/// <summary>
1516
/// Name to search
1617
/// </summary>
17-
public string search;
18+
[JsonProperty("search")]
19+
public string Search { get; set; }
1820
}
1921
}

WebUntisAPI.Client/Models/SchoolSearchResultModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Newtonsoft.Json;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -14,6 +15,7 @@ internal struct SchoolSearchResultModel
1415
/// <summary>
1516
/// All schools found
1617
/// </summary>
17-
public School[] schools;
18+
[JsonProperty("schools")]
19+
public School[] Schools { get; set; }
1820
}
1921
}

WebUntisAPI.Client/SchoolSearch.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ public static async Task<School[]> SearchAsync(string name, CancellationToken ct
3838
// Write request content
3939
JSONRPCRequestModel<SchoolSearchModel[]> requestModel = new JSONRPCRequestModel<SchoolSearchModel[]>()
4040
{
41-
id = id,
42-
method = "searchSchool",
43-
@params = new SchoolSearchModel[]
41+
Id = id,
42+
Method = "searchSchool",
43+
Params = new SchoolSearchModel[]
4444
{
4545
new SchoolSearchModel()
4646
{
47-
search = name.ToLower()
47+
Search = name.ToLower()
4848
}
4949
}
5050
};
@@ -63,16 +63,16 @@ public static async Task<School[]> SearchAsync(string name, CancellationToken ct
6363
throw new HttpRequestException($"The request had an error (Code: {response.StatusCode}).");
6464

6565
// Check for WebUntis error
66-
if (responeModel.error != null)
66+
if (responeModel.Error != null)
6767
{
68-
if (responeModel.error.code == (int)WebUntisException.Codes.TooManyResults)
68+
if (responeModel.Error.Code == (int)WebUntisException.Codes.TooManyResults)
6969
return null;
7070

71-
throw responeModel.error;
71+
throw responeModel.Error;
7272
}
7373

7474
// Evaluate response
75-
return responeModel.result.schools;
75+
return responeModel.Result.Schools;
7676
}
7777
}
7878
}

0 commit comments

Comments
 (0)