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

42 lines
1.4 KiB
C#
Raw Normal View History

2023-02-14 01:23:13 +02:00
// Copyright (c) 2020 Tudor Stanciu
using Tuitio.PublishedLanguage.Dto;
using Tuitio.Wrapper.Constants;
using Tuitio.Wrapper.Models;
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;
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;
}
public async Task<Token> Authenticate(string userName, string password)
{
var route = string.Format(ApiRoutes.Authentication, userName, password);
var result = await _httpClient.ExecutePostRequest<Token>(route);
2020-12-21 00:45:10 +02:00
return result;
}
public async Task<TokenAuthorizationResult> Authorize(string token)
2020-12-21 00:45:10 +02:00
{
var route = string.Format(ApiRoutes.Authorization, token);
var result = await _httpClient.ExecutePostRequest<TokenAuthorizationResult>(route);
2020-12-21 00:45:10 +02:00
return result;
}
}
}