Refactor to api connections. Update Checker.
This commit is contained in:
50
PWAPPv2/Source/API/PWApiConnection.cs
Normal file
50
PWAPPv2/Source/API/PWApiConnection.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user