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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
18
FarmmapsApiSamples/FarmmapsApiSamples.csproj
Normal file
18
FarmmapsApiSamples/FarmmapsApiSamples.csproj
Normal file
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FarmmapsApi\FarmmapsApi.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
9
FarmmapsApiSamples/IApp.cs
Normal file
9
FarmmapsApiSamples/IApp.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FarmmapsApiSamples
|
||||
{
|
||||
public interface IApp
|
||||
{
|
||||
Task RunAsync();
|
||||
}
|
||||
}
|
31
FarmmapsApiSamples/Program.cs
Normal file
31
FarmmapsApiSamples/Program.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Threading.Tasks;
|
||||
using FarmmapsApi;
|
||||
using FarmmapsApi.Models;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FarmmapsApiSamples
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private static async Task Main(string[] args)
|
||||
{
|
||||
IConfiguration config = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json", false, true)
|
||||
.Build();
|
||||
|
||||
var configuration = config.Get<Configuration>();
|
||||
|
||||
var serviceProvider = new ServiceCollection()
|
||||
.AddLogging(opts => opts
|
||||
.AddConsole()
|
||||
.AddFilter("System.Net.Http", LogLevel.Warning))
|
||||
.AddFarmmapsServices(configuration)
|
||||
.AddSingleton<IApp, DefaultApp>()
|
||||
.BuildServiceProvider();
|
||||
|
||||
await serviceProvider.GetService<IApp>().RunAsync();
|
||||
}
|
||||
}
|
||||
}
|
9
FarmmapsApiSamples/appsettings.json
Normal file
9
FarmmapsApiSamples/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Authority": "https://accounts.farmmaps.awtest.nl/",
|
||||
"Endpoint": "https://farmmaps.awtest.nl/api/v1/",
|
||||
"DiscoveryEndpointUrl": "https://accounts.farmmaps.awtest.nl/.well-known/openid-configuration",
|
||||
"RedirectUri": "http://example.nl/api",
|
||||
"ClientId": "",
|
||||
"ClientSecret": "",
|
||||
"Scopes": ["api"]
|
||||
}
|
Reference in New Issue
Block a user