using RestSharp.Serialization.Json;
using RestSharp.Serializers.SystemTextJson;
public static void Main()
BaseClient.SetBaseUrl("https://whateverkronosurlis");
TokenRequest tokenRequest = new TokenRequest("someuser", "somepassword", "mycompany", "apikey");
BaseClient.SetToken(tokenRequest.Post());
EmployeeRequest request = new EmployeeRequest("23050823");
Employee myEmployee = request.Get();
public abstract class BaseClient {
protected static string BaseUrl = null;
protected static string Token = null;
public static void SetBaseUrl(string url) {
public static void SetToken(string token) {
public class TokenRequest : BaseClient<string> {
public override string URL {
public override bool RequiresToken {
private readonly string _apiKey;
private readonly TokenAuth _tokenInfo;
public TokenRequest(string username, string password, string company, string apiKey) {
_tokenInfo = new TokenAuth {
protected override void AddHeaders(IRestRequest request) {
request.AddHeader("Accept", "text/json");
request.AddHeader("Api-Key", _apiKey);
protected override void AddContent(IRestRequest request) {
request.AddJsonBody(_tokenInfo)
public string UserName {get; set;}
public string Password {get;set;}
public string Company {get;set;}
public abstract class BaseClient<T> : BaseClient where T: class {
private readonly RestClient _restClient;
public abstract string URL { get; }
public virtual bool RequiresToken { get { return true; } }
_restClient = new RestClient(BaseUrl);
_restClient.UseSystemTextJson();
public IRestResponse Execute(Method method) {
RestRequest request = new RestRequest(URL, DataFormat.Json);
request.AddHeader("BEARER", Token);
return _restClient.Execute(request, method);
IRestResponse response = Execute(Method.GET);
return _restClient.Deserialize<T>(response).Data;
IRestResponse response = Execute(Method.POST);
return _restClient.Deserialize<T>(response).Data;
protected virtual void AddHeaders(IRestRequest request) {
protected virtual void AddContent(IRestRequest request) {
public class EmployeeRequest : BaseClient<Employee> {
private readonly string _employeeId;
public override string URL {
return $"/employee/{_employeeId}";
public EmployeeRequest(string employeeId) {
_employeeId = employeeId;
public string Name { get; set;}