blob: 34b42d130192c22bd3d18ed642835556c4306c25 (
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
30
|
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.ToString());
return data.Deserialize<ProfileResponse>();
}
public async Task<string> GetCanonicalHomeserverUrl()
{
return (await new RemoteHomeServer(HomeServer).Configure()).FullHomeServerDomain;
}
}
|