Skip to content

Commit 02c7d8f

Browse files
author
Francisco Liberal
committed
updating examples and docs
1 parent 5208b71 commit 02c7d8f

File tree

5 files changed

+299
-16
lines changed

5 files changed

+299
-16
lines changed

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
# Changelog
22

3+
## 0.2.0 (2025-01-XX)
4+
5+
### Breaking Changes
6+
7+
* **Client Configuration**: Constructor now requires `ArcadeClientOptions` instead of object initializer syntax
8+
* **HttpClient**: Removed from public API. Inject via `ArcadeClientOptions.HttpClient` for dependency injection support
9+
* **Type Names**: Renamed `HttpRequest`/`HttpResponse``ArcadeRequest`/`ArcadeResponse` to avoid ASP.NET naming conflicts
10+
11+
### Features
12+
13+
* **ArcadeClientOptions**: New strongly-typed configuration class with environment variable support
14+
* **ArcadeClientFactory**: Convenient factory methods with shared HttpClient instance
15+
* **Parameterless Constructor**: Creates client using `ARCADE_API_KEY` and `ARCADE_BASE_URL` environment variables
16+
* **XML Documentation**: Comprehensive documentation added to all public APIs
17+
18+
### Improvements
19+
20+
* Applied modern C# 12 patterns (primary constructors, expression-bodied members, string interpolation)
21+
* Added 69 behavior-focused unit tests covering edge cases and architectural validation
22+
* Proper dependency injection support for `HttpClient`
23+
* All exception types now sealed with XML documentation
24+
* Improved separation of concerns and architectural patterns
25+
326
## 0.1.0 (2025-10-29)
427

528
Full Changelog: [v0.0.1...v0.1.0](https://github.com/ArcadeAI/arcade-dotnet/compare/v0.0.1...v0.1.0)

README.md

Lines changed: 81 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,79 @@ This library requires .NET 8 or later.
3030

3131
See the [`examples`](examples) directory for complete and runnable examples.
3232

33+
### Execute a Tool
34+
35+
**Simple tool (no OAuth):**
3336
```csharp
34-
using System;
3537
using ArcadeDotnet;
3638
using ArcadeDotnet.Models.Tools;
3739

38-
// Configured using the ARCADE_API_KEY and ARCADE_BASE_URL environment variables
39-
ArcadeClient client = new();
40+
var client = new ArcadeClient();
41+
42+
var executeParams = new ToolExecuteParams
43+
{
44+
ToolName = "CheckArcadeEngineHealth" // Example: simple tool
45+
};
46+
47+
var result = await client.Tools.Execute(executeParams);
48+
result.Validate();
49+
Console.WriteLine($"Execution ID: {result.ExecutionID}");
50+
Console.WriteLine($"Status: {result.Status}");
51+
```
52+
53+
**Tool requiring OAuth (e.g., GitHub):**
54+
```csharp
55+
// Step 1: Authorize the tool
56+
var authResponse = await client.Tools.Authorize(new ToolAuthorizeParams
57+
{
58+
ToolName = "GitHub.ListRepositories"
59+
});
60+
61+
// Step 2: After OAuth completes, execute with UserID
62+
var executeParams = new ToolExecuteParams
63+
{
64+
ToolName = "GitHub.ListRepositories",
65+
UserID = authResponse.UserID // From authorization response
66+
};
67+
68+
var result = await client.Tools.Execute(executeParams);
69+
```
70+
71+
### List Available Tools
72+
73+
```csharp
74+
using ArcadeDotnet;
4075

41-
ToolExecuteParams parameters = new() { ToolName = "Google.ListEmails" };
76+
var client = new ArcadeClient();
77+
var tools = await client.Tools.List();
78+
tools.Validate();
79+
Console.WriteLine($"Found {tools.Items?.Count ?? 0} tools");
80+
```
81+
82+
### With Options
83+
84+
```csharp
85+
using ArcadeDotnet;
86+
using System.Net.Http;
87+
88+
var client = new ArcadeClient(new ArcadeClientOptions
89+
{
90+
ApiKey = "your-api-key",
91+
BaseUrl = new Uri("https://api.arcade.dev"),
92+
HttpClient = new HttpClient() // Optional: inject your own HttpClient
93+
});
94+
```
4295

43-
var executeToolResponse = await client.Tools.Execute(parameters);
96+
### Using Factory
4497

45-
Console.WriteLine(executeToolResponse);
98+
```csharp
99+
using ArcadeDotnet;
100+
101+
// Factory method with shared HttpClient
102+
var client = ArcadeClientFactory.Create("your-api-key");
103+
104+
// Or using environment variables
105+
var clientFromEnv = ArcadeClientFactory.Create();
46106
```
47107

48108
## Client Configuration
@@ -53,25 +113,30 @@ Configure the client using environment variables:
53113
using ArcadeDotnet;
54114

55115
// Configured using the ARCADE_API_KEY and ARCADE_BASE_URL environment variables
56-
ArcadeClient client = new();
116+
var client = new ArcadeClient();
57117
```
58118

59-
Or manually:
119+
Or with explicit options:
60120

61121
```csharp
62122
using ArcadeDotnet;
63-
64-
ArcadeClient client = new() { APIKey = "My API Key" };
123+
using System.Net.Http;
124+
125+
var client = new ArcadeClient(new ArcadeClientOptions
126+
{
127+
ApiKey = "your-api-key",
128+
BaseUrl = new Uri("https://api.arcade.dev"),
129+
HttpClient = new HttpClient() // Optional
130+
});
65131
```
66132

67-
Or using a combination of the two approaches.
68-
69133
See this table for the available options:
70134

71-
| Property | Environment variable | Required | Default value |
72-
| --------- | -------------------- | -------- | -------------------------- |
73-
| `APIKey` | `ARCADE_API_KEY` | true | - |
74-
| `BaseUrl` | `ARCADE_BASE_URL` | true | `"https://api.arcade.dev"` |
135+
| Property | Environment variable | Required | Default value |
136+
| ------------ | ------------------- | -------- | ------------------------- |
137+
| `ApiKey` | `ARCADE_API_KEY` | true | - |
138+
| `BaseUrl` | `ARCADE_BASE_URL` | false | `"https://api.arcade.dev"` |
139+
| `HttpClient` | - | false | New instance created |
75140

76141
## Requests and responses
77142

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<ItemGroup>
4+
<ProjectReference Include="..\..\src\ArcadeDotnet\ArcadeDotnet.csproj" />
5+
</ItemGroup>
6+
7+
<PropertyGroup>
8+
<OutputType>Exe</OutputType>
9+
<TargetFramework>net8.0</TargetFramework>
10+
<ImplicitUsings>enable</ImplicitUsings>
11+
<Nullable>enable</Nullable>
12+
</PropertyGroup>
13+
14+
</Project>

examples/BasicExample/Program.cs

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Threading.Tasks;
4+
using ArcadeDotnet;
5+
using ArcadeDotnet.Models.Tools;
6+
using ArcadeDotnet.Exceptions;
7+
using ArcadeDotnet.Models;
8+
9+
namespace Examples;
10+
11+
/// <summary>
12+
/// Basic example demonstrating how to use the Arcade SDK.
13+
/// </summary>
14+
class Program
15+
{
16+
static async Task Main(string[] args)
17+
{
18+
// Create client using environment variables
19+
var client = new ArcadeClient();
20+
Console.WriteLine($"Connected to: {client.BaseUrl}\n");
21+
22+
// Example 1: Execute a Simple Tool (No OAuth Required)
23+
Console.WriteLine("=== Example 1: Execute Simple Tool (No OAuth) ===");
24+
Console.WriteLine(" Note: Most tools require OAuth. This example shows the pattern.");
25+
Console.WriteLine(" For a working example, use a tool that doesn't require authentication.");
26+
try
27+
{
28+
// Example: Execute a tool (this will likely require UserID for most tools)
29+
// In practice, you'd use a tool that doesn't need OAuth like math operations
30+
var executeParams = new ToolExecuteParams
31+
{
32+
ToolName = "CheckArcadeEngineHealth", // Example tool name
33+
// UserID = "user-id" // Required for most tools
34+
};
35+
36+
var result = await client.Tools.Execute(executeParams);
37+
result.Validate();
38+
39+
Console.WriteLine($"✅ Tool executed successfully!");
40+
Console.WriteLine($" Execution ID: {result.ExecutionID}");
41+
Console.WriteLine($" Status: {result.Status}");
42+
Console.WriteLine($" Success: {result.Success}");
43+
}
44+
catch (ArcadeBadRequestException ex)
45+
{
46+
Console.WriteLine($" ⚠️ Expected: Most tools require UserID or specific parameters");
47+
Console.WriteLine($" Error: {ex.Message}");
48+
Console.WriteLine($" Tip: Use Tools.Authorize() first for OAuth tools");
49+
}
50+
catch (ArcadeNotFoundException ex)
51+
{
52+
Console.WriteLine($"❌ Tool not found: {ex.Message}");
53+
}
54+
catch (Exception ex)
55+
{
56+
Console.WriteLine($"❌ Error: {ex.GetType().Name}: {ex.Message}");
57+
}
58+
59+
// Example 2: Execute Tool Requiring OAuth (GitHub Example)
60+
Console.WriteLine("\n=== Example 2: Tool Requiring OAuth (GitHub) ===");
61+
try
62+
{
63+
// For tools requiring OAuth, you need to authorize first
64+
// This example shows the pattern (GitHub tools require OAuth)
65+
var authorizeParams = new ToolAuthorizeParams
66+
{
67+
ToolName = "GitHub.ListRepositories" // Example GitHub tool
68+
};
69+
70+
Console.WriteLine(" Authorizing tool access...");
71+
var authResponse = await client.Tools.Authorize(authorizeParams);
72+
authResponse.Validate();
73+
74+
Console.WriteLine($" ✅ Authorization initiated!");
75+
if (authResponse.Status != null)
76+
{
77+
Console.WriteLine($" Status: {authResponse.Status.Value}");
78+
}
79+
if (!string.IsNullOrEmpty(authResponse.URL))
80+
{
81+
Console.WriteLine($" OAuth URL: {authResponse.URL}");
82+
}
83+
Console.WriteLine($" Note: Complete OAuth flow, then use UserID in Execute()");
84+
85+
// After OAuth completes, execute with UserID:
86+
// var executeParams = new ToolExecuteParams
87+
// {
88+
// ToolName = "GitHub.ListRepositories",
89+
// UserID = "user-id-from-oauth-flow"
90+
// };
91+
}
92+
catch (ArcadeNotFoundException ex)
93+
{
94+
Console.WriteLine($" ⚠️ Tool not found (this is expected if GitHub tools aren't available)");
95+
Console.WriteLine($" Error: {ex.Message}");
96+
}
97+
catch (Exception ex)
98+
{
99+
Console.WriteLine($" ⚠️ Error: {ex.GetType().Name}: {ex.Message}");
100+
Console.WriteLine(" Note: This demonstrates the OAuth authorization pattern");
101+
}
102+
103+
// Example 3: List Available Tools
104+
Console.WriteLine("\n=== Example 3: List Available Tools ===");
105+
try
106+
{
107+
var tools = await client.Tools.List();
108+
tools.Validate();
109+
var count = tools.Items?.Count ?? 0;
110+
Console.WriteLine($"✅ Found {count} available tools");
111+
112+
if (tools.Items != null && tools.Items.Count > 0)
113+
{
114+
Console.WriteLine($" First tool: {tools.Items[0].Name}");
115+
}
116+
}
117+
catch (Exception ex)
118+
{
119+
Console.WriteLine($"❌ Error: {ex.GetType().Name}: {ex.Message}");
120+
}
121+
122+
// Example 4: Get Tool Details
123+
Console.WriteLine("\n=== Example 4: Get Tool Details ===");
124+
try
125+
{
126+
var toolParams = new ToolGetParams { Name = "Google.ListEmails" };
127+
var tool = await client.Tools.Get(toolParams);
128+
tool.Validate();
129+
Console.WriteLine($"✅ Tool retrieved: {tool.Name}");
130+
Console.WriteLine($" Description: {tool.Description ?? "N/A"}");
131+
}
132+
catch (ArcadeNotFoundException ex)
133+
{
134+
Console.WriteLine($"❌ Tool not found: {ex.Message}");
135+
}
136+
catch (Exception ex)
137+
{
138+
Console.WriteLine($"❌ Error: {ex.GetType().Name}: {ex.Message}");
139+
}
140+
141+
// Example 5: Health Check
142+
Console.WriteLine("\n=== Example 5: Health Check ===");
143+
try
144+
{
145+
var health = await client.Health.Check();
146+
health.Validate();
147+
Console.WriteLine($"✅ Health check passed: {health.Healthy}");
148+
}
149+
catch (Exception ex)
150+
{
151+
Console.WriteLine($"❌ Error: {ex.GetType().Name}: {ex.Message}");
152+
}
153+
}
154+
}

examples/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Examples
2+
3+
This directory contains runnable examples demonstrating how to use the Arcade C# SDK.
4+
5+
## BasicExample
6+
7+
Demonstrates basic SDK usage including:
8+
- Creating clients with different configuration methods
9+
- Using environment variables
10+
- Using `ArcadeClientOptions`
11+
- Using `ArcadeClientFactory`
12+
- Listing tools
13+
- Health checks
14+
15+
### Running
16+
17+
```bash
18+
cd BasicExample
19+
export ARCADE_API_KEY="your-api-key"
20+
dotnet run
21+
```
22+
23+
## Requirements
24+
25+
- .NET 8 SDK
26+
- Valid Arcade API key (set via `ARCADE_API_KEY` environment variable)
27+

0 commit comments

Comments
 (0)