Skip to content

Commit a1c09f2

Browse files
committed
Add contact details
1 parent 37ffe68 commit a1c09f2

3 files changed

Lines changed: 138 additions & 0 deletions

File tree

API.Test/ProfileTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,18 @@ public void GetGenerallyInformation()
6868
else
6969
Assert.Fail();
7070
}
71+
72+
[Test]
73+
public void GetContactDetails()
74+
{
75+
Client.LoginAsync(s_Server, s_LoginName, s_UserName, s_Password).Wait();
76+
77+
Task<(ContactDetails? contact, bool read, bool write)> contact = Client.GetContactDetailsAsync();
78+
contact.Wait();
79+
80+
if (contact.Result.read)
81+
Assert.Pass();
82+
else
83+
Assert.Fail();
84+
}
7185
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace WebUntisAPI.Client.Models
9+
{
10+
/// <summary>
11+
/// Contact information about a user
12+
/// </summary>
13+
public class ContactDetails
14+
{
15+
/// <summary>
16+
/// The person id
17+
/// </summary>
18+
[JsonProperty("personId")]
19+
public int PersonId { get; set; }
20+
21+
/// <summary>
22+
/// The person type id
23+
/// </summary>
24+
[JsonProperty("personType")]
25+
public int PersonType { get; set; }
26+
27+
/// <summary>
28+
/// The user id
29+
/// </summary>
30+
[JsonProperty("id")]
31+
public int Id { get; set; }
32+
33+
/// <summary>
34+
/// The user name
35+
/// </summary>
36+
[JsonProperty("name")]
37+
public string Name { get; set; }
38+
39+
/// <summary>
40+
/// For which person are this information
41+
/// </summary>
42+
[JsonProperty("addressType")]
43+
public string AddressType { get; set; }
44+
45+
/// <summary>
46+
/// The id for <see cref="AddressType"/>
47+
/// </summary>
48+
[JsonProperty("addressTypeValue")]
49+
public int AddressTypeValue { get; set; }
50+
51+
/// <summary>
52+
/// The street
53+
/// </summary>
54+
[JsonProperty("street")]
55+
public string Street { get; set; }
56+
57+
/// <summary>
58+
/// The city
59+
/// </summary>
60+
[JsonProperty("city")]
61+
public string City { get; set; }
62+
63+
/// <summary>
64+
/// The post code
65+
/// </summary>
66+
[JsonProperty("postCode")]
67+
public string PostCode { get; set; }
68+
69+
/// <summary>
70+
/// The country
71+
/// </summary>
72+
[JsonProperty("country")]
73+
public string Country { get; set; }
74+
75+
/// <summary>
76+
/// The email
77+
/// </summary>
78+
[JsonProperty("email")]
79+
public string Email { get; set; }
80+
81+
/// <summary>
82+
/// The phone number
83+
/// </summary>
84+
[JsonProperty("phone")]
85+
public string PhoneNumber { get; set; }
86+
87+
/// <summary>
88+
/// The mobile number
89+
/// </summary>
90+
[JsonProperty("mobile")]
91+
public string MobileNumber { get; set; }
92+
93+
/// <summary>
94+
/// The fax number
95+
/// </summary>
96+
[JsonProperty("fax")]
97+
public string FaxNumber { get; set; }
98+
}
99+
}

WebUntisAPI.Client/WebUntisclient.Profile.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,35 @@ public async Task<AccountConfig> GetAccountConfigAsync(CancellationToken ct = de
215215
/// </summary>
216216
/// <param name="ct">Cancellation token</param>
217217
/// <returns>The information</returns>
218+
/// <exception cref="ObjectDisposedException">Thrown when the instance was disposed</exception>
219+
/// <exception cref="UnauthorizedAccessException">Thrown when you're logged in</exception>
220+
/// <exception cref="HttpRequestException">Thrown when an error happened while the http request</exception>
218221
public async Task<GeneralAccount> GetGenerallyAccountInformationAsync(CancellationToken ct = default)
219222
{
220223
string responseString = await MakeAPIGetRequestAsync("/WebUntis/api/profile/general", ct);
221224
return GeneralAccount.ReadFromJson(JObject.Parse(responseString)["data"].CreateReader());
222225
}
226+
227+
/// <summary>
228+
/// Get the contact details for this account
229+
/// </summary>
230+
/// <param name="ct">Cancellation token</param>
231+
/// <returns>When read is false the contact <see langword="null"/></returns>
232+
/// <exception cref="ObjectDisposedException">Thrown when the instance was disposed</exception>
233+
/// <exception cref="UnauthorizedAccessException">Thrown when you're logged in</exception>
234+
/// <exception cref="HttpRequestException">Thrown when an error happened while the http request</exception>
235+
public async Task<(ContactDetails contact, bool read, bool write)> GetContactDetailsAsync(CancellationToken ct = default)
236+
{
237+
string responseString = await MakeAPIGetRequestAsync("/WebUntis/api/profile/contactdetails?personId=3299&isRequestForStudent=false", ct);
238+
JObject data = JObject.Parse(responseString)["data"].Value<JObject>();
239+
240+
if (data["read"].Value<bool>())
241+
{
242+
ContactDetails contact = data["address"].ToObject<ContactDetails>();
243+
return (contact, true, data["write"].Value<bool>());
244+
}
245+
246+
return (null, false, data["write"].Value<bool>());
247+
}
223248
}
224249
}

0 commit comments

Comments
 (0)