blob: 3259e443071128a59ff2a72f45150ac0d417e5e9 (
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
|
using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MatrixRoomUtils.Core.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);
return data.Deserialize<ProfileResponse>();
}
public async Task<string> GetCanonicalHomeserverUrl() => (await new RemoteHomeServer(HomeServer).Configure()).FullHomeServerDomain;
}
|