-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShippingService.cs
71 lines (61 loc) · 1.98 KB
/
ShippingService.cs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using BitBuggy.Shipping.Maui.Shipping.Api;
using BitBuggy.Shipping.Maui.Shipping.Client;
using Microsoft.Identity.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BitBuggy.Shipping.Maui;
/// <summary>
/// Info for authorization on Shipping API.
/// </summary>
public sealed class ShippingService(AccountAuthorizationService accountAuthorizationService)
{
private readonly AccountAuthorizationService _authorization = accountAuthorizationService;
public static readonly string[] Scopes = ["https://bitbuggy.dev/shipping/Shipment.Write"];
public async Task<Configuration?> GetConfigurationAsync()
{
AuthenticationResult? authenticationResult = await _authorization.GetAuthenticationAsync(Scopes);
if (authenticationResult is null)
{
return null;
}
return new Configuration
{
AccessToken = authenticationResult.AccessToken,
DefaultHeaders = new Dictionary<string, string>
{
["Authorization"] = $"Bearer {authenticationResult.AccessToken}"
},
BasePath = "https://shipping.bitbuggy.dev"
};
}
public async Task<MeApi?> GetMeAsync()
{
Configuration? configuration = await GetConfigurationAsync();
if (configuration is null)
{
return null;
}
return new MeApi(configuration);
}
public async Task<OrdersApi?> GetOrdersAsync()
{
Configuration? configuration = await GetConfigurationAsync();
if (configuration is null)
{
return null;
}
return new OrdersApi(configuration);
}
public async Task<ShipmentsApi?> GetShipmentsAsync()
{
Configuration? configuration = await GetConfigurationAsync();
if (configuration is null)
{
return null;
}
return new ShipmentsApi(configuration);
}
}