forked from FarmMaps/FarmMapsApiClient
Initial commit
This commit is contained in:
42
FarmmapsApiSamples/DefaultApp.cs
Normal file
42
FarmmapsApiSamples/DefaultApp.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using FarmmapsApi.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FarmmapsApiSamples
|
||||
{
|
||||
public class DefaultApp : IApp
|
||||
{
|
||||
private readonly ILogger<DefaultApp> _logger;
|
||||
private readonly FarmmapsApiService _farmmapsApiService;
|
||||
|
||||
public DefaultApp(ILogger<DefaultApp> logger, FarmmapsApiService farmmapsApiService)
|
||||
{
|
||||
_logger = logger;
|
||||
_farmmapsApiService = farmmapsApiService;
|
||||
}
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await _farmmapsApiService.AuthenticateAsync();
|
||||
|
||||
_logger.LogInformation("Authenticated client credentials");
|
||||
|
||||
var user = await _farmmapsApiService.GetCurrentUserCodeAsync();
|
||||
_logger.LogInformation($"Usercode: {user}");
|
||||
|
||||
var roots = await _farmmapsApiService.GetCurrentUserRootsAsync();
|
||||
foreach (var userRoot in roots)
|
||||
{
|
||||
_logger.LogInformation($"{userRoot.Name} - {userRoot.Code}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user