55 lines
1.2 KiB
C#
55 lines
1.2 KiB
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CLI
|
|
{
|
|
public partial class LinksClient
|
|
{
|
|
private string _token;
|
|
|
|
partial void PrepareRequest(HttpClient client, HttpRequestMessage request, StringBuilder urlBuilder)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(_token))
|
|
{
|
|
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _token);
|
|
}
|
|
}
|
|
|
|
public void UseToken(string token)
|
|
{
|
|
_token = token;
|
|
}
|
|
}
|
|
|
|
class Program
|
|
{
|
|
static async Task Main(string[] args)
|
|
{
|
|
var linksClient = new LinksClient("http://localhost:5000/");
|
|
var accountsClient = new AccountsClient("http://localhost:5000/");
|
|
|
|
var links = await linksClient.GetLinksAsync();
|
|
|
|
foreach (var link in links)
|
|
{
|
|
System.Console.WriteLine(link.Url);
|
|
}
|
|
|
|
var token = await accountsClient.LoginAsync(new LoginViewModel()
|
|
{
|
|
Username = "julien",
|
|
Password = "test"
|
|
});
|
|
|
|
linksClient.UseToken(token);
|
|
|
|
await linksClient.CreateLinkAsync(new AddLinkCommand()
|
|
{
|
|
Url = new Uri("http://somewhere-else.fr"),
|
|
});
|
|
}
|
|
}
|
|
}
|