mirror of
https://github.com/Tribufu/TribufuDotNet
synced 2026-08-09 04:41:07 +00:00
Add example project
This commit is contained in:
parent
f65b2a5912
commit
42f42637b2
7 changed files with 86 additions and 0 deletions
44
src/Tribufu.Example/Program.cs
Normal file
44
src/Tribufu.Example/Program.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
|
||||
using dotenv.net;
|
||||
using Tribufu.Api;
|
||||
using Tribufu.Client;
|
||||
|
||||
namespace Tribufu.Test
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
DotEnv.Load(new DotEnvOptions(ignoreExceptions: true, envFilePaths: [".env", "../../.env"]));
|
||||
|
||||
var config = new Configuration
|
||||
{
|
||||
BasePath = "https://api.tribufu.com"
|
||||
};
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable("TRIBUFU_API_KEY");
|
||||
if (!string.IsNullOrEmpty(apiKey))
|
||||
{
|
||||
config.AddApiKey("Authorization", "DvyTVeT6EBsvqsPE1mRuW7ewwiP1f9playWE9wLTmdXnCuBQqBrluhU0p1KXYaRi");
|
||||
config.AddApiKeyPrefix("Authorization", "ApiKey");
|
||||
}
|
||||
|
||||
var tribufu = new TribufuApi(config);
|
||||
|
||||
try
|
||||
{
|
||||
var result = await tribufu.GetUserInfoAsync();
|
||||
Console.WriteLine("Result:");
|
||||
Console.WriteLine(result);
|
||||
}
|
||||
catch (ApiException e)
|
||||
{
|
||||
Console.WriteLine("---- API Error ----");
|
||||
Console.WriteLine($"Status: {e.ErrorCode}");
|
||||
Console.WriteLine($"Details: {e.Data}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
src/Tribufu.Example/Tribufu.Example.csproj
Normal file
11
src/Tribufu.Example/Tribufu.Example.csproj
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Tribufu\Tribufu.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="dotenv.net" />
|
||||
<PackageReference Include="JsonSubTypes" />
|
||||
<PackageReference Include="Newtonsoft.Json" />
|
||||
<PackageReference Include="Polly" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue