diff options
Diffstat (limited to 'MatrixRoomUtils.Core/Responses')
-rw-r--r-- | MatrixRoomUtils.Core/Responses/LoginResponse.cs | 31 | ||||
-rw-r--r-- | MatrixRoomUtils.Core/Responses/ProfileResponse.cs | 11 |
2 files changed, 42 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Core/Responses/LoginResponse.cs b/MatrixRoomUtils.Core/Responses/LoginResponse.cs new file mode 100644 index 0000000..eedc970 --- /dev/null +++ b/MatrixRoomUtils.Core/Responses/LoginResponse.cs @@ -0,0 +1,31 @@ +using System.Net.Http.Json; +using System.Text.Json; +using System.Text.Json.Serialization; +using MatrixRoomUtils.Authentication; + +namespace MatrixRoomUtils.Responses; + +public class LoginResponse +{ + [JsonPropertyName("access_token")] + public string AccessToken { get; set; } + [JsonPropertyName("device_id")] + public string DeviceId { get; set; } + [JsonPropertyName("home_server")] + public string HomeServer { get; set; } + [JsonPropertyName("user_id")] + public string UserId { get; set; } + + public async Task<ProfileResponse> GetProfile() + { + var hc = new HttpClient(); + var resp = await hc.GetAsync($"{HomeServer}/_matrix/client/r0/profile/{UserId}"); + var data = await resp.Content.ReadFromJsonAsync<JsonElement>(); + if(!resp.IsSuccessStatusCode) Console.WriteLine("Profile: " + data.ToString()); + return data.Deserialize<ProfileResponse>(); + } + public async Task<string> GetCanonicalHomeserverUrl() + { + return await MatrixAccount.ResolveHomeserverFromWellKnown(HomeServer); + } +} \ No newline at end of file diff --git a/MatrixRoomUtils.Core/Responses/ProfileResponse.cs b/MatrixRoomUtils.Core/Responses/ProfileResponse.cs new file mode 100644 index 0000000..ab6cc92 --- /dev/null +++ b/MatrixRoomUtils.Core/Responses/ProfileResponse.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace MatrixRoomUtils.Authentication; + +public class ProfileResponse +{ + [JsonPropertyName("avatar_url")] + public string? AvatarUrl { get; set; } = ""; + [JsonPropertyName("displayname")] + public string DisplayName { get; set; } = ""; +} \ No newline at end of file |