tuitio/src/Tuitio.Wrapper/Services/TuitioService.cs

49 lines
1.7 KiB
C#
Raw Normal View History

2023-02-14 01:23:13 +02:00
// Copyright (c) 2020 Tudor Stanciu
using Netmash.Extensions.Http;
2020-12-21 00:45:10 +02:00
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
2023-03-07 19:36:12 +02:00
using Tuitio.PublishedLanguage.Dto;
using Tuitio.Wrapper.Constants;
using Tuitio.Wrapper.Models;
2020-12-21 00:45:10 +02:00
namespace Tuitio.Wrapper.Services
2020-12-21 00:45:10 +02:00
{
internal class TuitioService : ITuitioService
2020-12-21 00:45:10 +02:00
{
private const string _contentType = "application/json";
private readonly HttpClient _httpClient;
public TuitioService(HttpClient httpClient, ServiceConfiguration configuration)
2020-12-21 00:45:10 +02:00
{
httpClient.BaseAddress = new Uri(configuration.BaseAddress);
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(_contentType));
_httpClient = httpClient;
}
2023-03-07 20:36:12 +02:00
public async Task<Envelope<AccountLoginResult>> Login(string userName, string password)
2023-03-07 19:36:12 +02:00
{
var route = string.Format(ApiRoutes.AccountLogin, userName, password);
2023-03-07 20:36:12 +02:00
var result = await _httpClient.ExecutePostRequest<Envelope<AccountLoginResult>>(route);
2023-03-07 19:36:12 +02:00
return result;
}
2023-03-07 20:36:12 +02:00
public async Task<Envelope<AccountLogoutResult>> Logout(string token)
2020-12-21 00:45:10 +02:00
{
2023-03-07 19:36:12 +02:00
var route = string.Format(ApiRoutes.AccountLogout, token);
2023-03-07 20:36:12 +02:00
var result = await _httpClient.ExecutePostRequest<Envelope<AccountLogoutResult>>(route);
2020-12-21 00:45:10 +02:00
return result;
}
2023-03-07 20:36:12 +02:00
public async Task<Envelope<AuthorizationResult>> Authorize(string token)
2020-12-21 00:45:10 +02:00
{
var route = string.Format(ApiRoutes.Authorization, token);
2023-03-07 20:36:12 +02:00
var result = await _httpClient.ExecutePostRequest<Envelope<AuthorizationResult>>(route);
2020-12-21 00:45:10 +02:00
return result;
}
}
}