public static ISetup <IHttpClient, byte[]> SetupOtherDataApiCall(this Mock <IHttpClient> httpClientMock, ComponentBase component, string method, IDictionary <string, object> parameters = null, string apiKey = null) { if (apiKey != null) { parameters = parameters ?? new Parameters(); parameters.Add("apikey", apiKey); } var url = ZapApi.BuildRequestUrl(DataType.Other, component.ComponentName, CallType.Other, method, parameters); return(httpClientMock.Setup(m => m.DownloadData(url))); }
public static ISetup <IHttpClient, string> SetupApiCall(this Mock <IHttpClient> httpClientMock, ComponentBase component, CallType callType, string method, IDictionary <string, object> parameters = null, DataType?dataType = null, string apiKey = null) { dataType = dataType ?? DataType.Json; if (apiKey != null) { parameters = parameters ?? new Parameters(); parameters.Add("apikey", apiKey); } var url = ZapApi.BuildRequestUrl(dataType.Value, component.ComponentName, callType, method, parameters); return(httpClientMock.Setup(m => m.DownloadString(url))); }
private string CallApi(DataType dataType, CallType callType, string method, IDictionary <string, object> parameters) { parameters = AddApiKey(parameters); var url = ZapApi.BuildRequestUrl(dataType, ComponentName, callType, method, parameters); var result = _httpClient.DownloadString(url); if (string.IsNullOrEmpty(result)) { throw new ZapException(Resources.EmptyServerResult); } return(result); }
/// <summary> /// Calls an "other" API method in ZAP and return it's result as binary data. /// </summary> /// <param name="method">The name of the API method.</param> /// <param name="parameters">Optional parameters to send to the API method.</param> /// <returns>The result of the API call as binary data.</returns> protected byte[] CallOtherData(string method, IDictionary <string, object> parameters = null) { parameters = AddApiKey(parameters); var url = ZapApi.BuildRequestUrl(DataType.Other, ComponentName, CallType.Other, method, parameters); var result = _httpClient.DownloadData(url); if (!result.Any()) { throw new ZapException(Resources.EmptyServerResult); } return(result); }