-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from SP-SoftFuzz/Api
Api repository implemented
- Loading branch information
Showing
3 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
using ProfHeat.Core.Interfaces; | ||
using ProfHeat.Core.Models; | ||
|
||
using ProfHeat.Core.Interfaces; | ||
Check warning on line 10 in src/ProfHeat.Core/Repositories/ApiRepository.cs GitHub Actions / build
|
||
using System.Text.Json; | ||
Check warning on line 11 in src/ProfHeat.Core/Repositories/ApiRepository.cs GitHub Actions / build
|
||
|
||
namespace ProfHeat.Core.Repositories; | ||
|
||
public class ApiRepository : IRepository | ||
{ | ||
private readonly HttpClient _httpClient = new(); | ||
|
||
public T Load<T>(string url) | ||
{ | ||
var response = _httpClient.GetAsync(url).GetAwaiter().GetResult(); | ||
response.EnsureSuccessStatusCode(); | ||
var data = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); | ||
return JsonSerializer.Deserialize<T>(data)!; | ||
} | ||
|
||
public void Save<T>(T data, string filePath) => throw new NotImplementedException(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters