public static async Task <T> ExecuteAsync <T>(this RestRequest request, LoginUserBase currentUser, bool authorization = true) where T : new() { var client = new RestClient(); var taskCompletionSource = new TaskCompletionSource <T>(); client.BaseUrl = currentUser.url; if (authorization) { request.AddHeader("Authorization", currentUser.token); // used on every request } var tcs = new TaskCompletionSource <T>(); await client.Execute <T>(request).ContinueWith(restResponse => { if (restResponse.Exception != null) { const string message = "Error retrieving response."; tcs.SetException(new InvalidOperationException(message, restResponse.Exception)); } else { tcs.SetResult(restResponse.Result.Data); } }); return(await tcs.Task); }
public async Task <bool> AreCredentialsValidAsync(LoginUserBase userlogin) { try { LoginUserBase lyears = await GetEntityAsync <LoginUserBase>(userlogin, ApiServices.ApiLogin(), false, ""); _currentUser.token = null; if (lyears != null) { _currentUser.token = lyears.token; _currentUser.id = lyears.id; } return(_currentUser.token != null); } catch (Exception e) { return(false); } }
public CrudApi(string apiPath, LoginUserBase currentUser, bool authorization) { _apiPath = apiPath; _currentUser = currentUser; _authorization = authorization; }
public IntrataApiClient(string urlstring) { _currentUser = new LoginUserBase(urlstring); }
public IntrataApiClient(LoginUserBase user) { _currentUser = user; }