private Uri GenerateUri <TParams>( ILacrmFunction <TParams> function) where TParams : Parameter { var param = JsonSerializer.Serialize(function.Parameters, _opt); return(_baseAddress.AddParameter(Function, function.Function) .AddParameter(Parameters, param)); }
private void ValidateParameters <TParams>( ILacrmFunction <TParams> function) where TParams : Parameter { var validate = function.Parameters.Validate(); if (!validate.Success) { throw new ValidationException(validate); } }
private async Task <IDictionary <string, object> > CallApi <TParams>( ILacrmFunction <TParams> function, CancellationToken cancellationToken = default, bool preprocess = true) where TParams : Parameter { ValidateParameters(function); var uri = GenerateUri(function); var cleaned = await GetCleanedResponse(uri, preprocess, cancellationToken); var init = JsonSerializer.Deserialize <ExpandoObject>( cleaned, _opt); return(init); }
private async Task <TResult> CallApi <TParams, TResult>( ILacrmFunction <TParams> function, CancellationToken cancellationToken = default, bool preprocess = true) where TParams : Parameter where TResult : LacrmResponse { ValidateParameters(function); var uri = GenerateUri(function); var cleaned = await GetCleanedResponse(uri, preprocess, cancellationToken); var init = JsonSerializer.Deserialize <ErrorResponse>(cleaned, _opt); if (!init?.Success == true) { throw new ApiException(init?.Error ?? ApiError); } return(JsonSerializer.Deserialize <TResult>(cleaned, _opt) ?? throw new Exception()); }