/// <summary>
/// Calls the function asynchronous.
/// </summary>
/// <param name="functionName">Name of the function.</param>
/// <param name="arg">The argument.</param>
/// <returns></returns>
public async Task <Result <int> > CallFunctionAsync(String functionName, String arg)
{
if (String.IsNullOrWhiteSpace(functionName))
{
throw new ArgumentNullException(nameof(functionName));
}
try
{
var response = await cloud.MakePostRequestWithAuthTestAsync($"devices/{Id}/{Uri.EscapeUriString(functionName)}", new KeyValuePair <string, string>("arg", arg));
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var returnValue = response.Response.SelectToken("return_value");
return(new Result <int>(true, (int)returnValue.Value <long>()));
}
else
{
return(response.AsResult <int>());
}
}
catch (HttpRequestException re)
{
return(new Result <int>
{
Success = false,
Error = re.Message,
Exception = re
});
}
}