summary refs log tree commit diff
path: root/testFrontend/SafeNSound.Sdk/SafeNSoundClient.cs
blob: 4d81b521d41c4325e729de4fe807f3ff44f63380 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Net.Http.Json;

namespace SafeNSound.Sdk;

public class SafeNSoundClient(SafeNSoundConfiguration config, string accessToken)
{
    public WrappedHttpClient HttpClient { get; } = new()
    {
        BaseAddress = new Uri(config.BaseUri),
        DefaultRequestHeaders =
        {
            Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken)
        }
    };
    
    public async Task<WhoAmI> WhoAmI()
    {
        var res = await HttpClient.GetAsync("/auth/whoami");
        res.EnsureSuccessStatusCode();
        return (await res.Content.ReadFromJsonAsync<WhoAmI>())!;
    }
    
#region Alarm

    public async Task<AlarmDto> GetAlarm(string userId = "@me") {
        var res = await HttpClient.GetAsync($"/alarm/{userId}");
        res.EnsureSuccessStatusCode();
        return (await res.Content.ReadFromJsonAsync<AlarmDto>())!;
    }
        
    public async Task SetAlarm(AlarmDto alarm) {
        var res = await HttpClient.PutAsJsonAsync("/alarm/@me", alarm);
        res.EnsureSuccessStatusCode();
    }
    
    public async Task DeleteAlarm(string userId = "@me") {
        var res = await HttpClient.DeleteAsync($"/alarm/{userId}");
        res.EnsureSuccessStatusCode();
    }
    
    

#endregion

#region Budget

    

#endregion
}


public class AlarmDto {
    
}