Refactor to api connections. Update Checker.

This commit is contained in:
Matthew Burke
2023-08-24 12:45:56 -04:00
parent 4a4bcc81e0
commit 87a73ff24b
14 changed files with 355 additions and 45 deletions

View File

@@ -0,0 +1,50 @@
using PWAPPv2.Source.DataObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PWAPPv2.Source.API
{
public class PWApiConnection
{
private APIConnection BaseConnection;
private APIConnection UpdateConnection;
private APICredentials Credentials;
private string AppVersion;
public PWApiConnection(Source.Config.Configuration practiceConfig, Source.Config.Configuration universalConfig)
{
Credentials = new APICredentials(practiceConfig);
BaseConnection = new APIConnection(universalConfig.Get("PWBaseURI"), Credentials);
UpdateConnection = new APIConnection(universalConfig.Get("PWUpdateURI"), Credentials);
AppVersion = universalConfig.Get("PWAppVersion");
}
public string PostToApi(string uri, string data)
{
return BaseConnection.SendPostRequestAsync(uri, data);
}
public string GetFromApi(string uri)
{
return BaseConnection.SendPostRequestAsync(uri);
}
public bool CheckForUpdate()
{
string currentVersion = UpdateConnection.SendPostWithCredsInHeader("", "");
currentVersion = currentVersion.Replace("\"", "");
if(currentVersion != AppVersion)
{
return true;
}
return false;
}
}
}