Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload files using the files.falu.io host #253

Merged
merged 5 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Falu/FaluClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class FaluClientOptions
/// </summary>
public int Retries { get; set; } = 2;

/// <summary>
/// Host to use when uploading files
/// </summary>
public string FilesHost { get; set; } = "files.falu.io";

/// <summary>
/// Information about the application.
/// It is recommended for use only with third party services for identification purposes.
Expand Down
2 changes: 1 addition & 1 deletion src/Falu/Files/FilesServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public virtual Task<ResourceResponse<File>> CreateAsync(FileCreateOptions option
content.Add(new StringContent(options.Expires!.Value.ToString("O")), "expires");
}

var uri = MakePath();
var uri = new UriBuilder(BackChannel.BaseAddress!) { Host = Options.FilesHost, Path = MakePath() }.ToString();
return RequestResourceAsync(uri, HttpMethod.Post, content, requestOptions, cancellationToken);
}
}
8 changes: 7 additions & 1 deletion tests/Falu.Tests/Clients/BaseServiceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected DynamicHttpMessageHandler GetAsync_Handler(RequestOptions? requestOpti
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Get, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/{Data.Id!}", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand All @@ -49,6 +50,7 @@ protected DynamicHttpMessageHandler ListAsync_Handler(bool? hasContinuationToken
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Get, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand All @@ -74,11 +76,12 @@ protected DynamicHttpMessageHandler ListAsync_Handler(bool? hasContinuationToken
return handler;
}

protected DynamicHttpMessageHandler CreateAsync_Handler(RequestOptions? requestOptions = null)
protected DynamicHttpMessageHandler CreateAsync_Handler(RequestOptions? requestOptions = null, string? host = ApiHost)
{
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Post, req.Method);
Assert.Equal(host, req.RequestUri!.Host);
Assert.Equal($"{BasePath}", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand All @@ -102,6 +105,7 @@ protected DynamicHttpMessageHandler UpdateAsync_Handler(RequestOptions? requestO
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Patch, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/{Data.Id!}", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand All @@ -123,6 +127,7 @@ protected DynamicHttpMessageHandler DeleteAsync_Handler(RequestOptions? requestO
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Delete, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/{Data.Id!}", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand All @@ -138,6 +143,7 @@ public class BaseServiceClientTests
{
private const string TestKey = "test";

protected const string ApiHost = "api.falu.io";
protected const string WorkspaceId = "wksp_602a8dd0a54847479a874de4";
protected const string IdempotencyKey = "05bc69eb-218d-46f2-8812-5bede8592abf";

Expand Down
2 changes: 1 addition & 1 deletion tests/Falu.Tests/Clients/FilesServiceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ await TestAsync(handler, async (client) =>
[ClassData(typeof(RequestOptionsData))]
public async Task CreateAsync_Works(RequestOptions requestOptions)
{
var handler = CreateAsync_Handler(requestOptions);
var handler = CreateAsync_Handler(requestOptions, "files.falu.io");

await TestAsync(handler, async (client) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public async Task CancelAsync_Works(RequestOptions requestOptions)
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Post, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/{Data!.Id}/cancel", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand Down Expand Up @@ -156,6 +157,7 @@ public async Task RedactAsync_Works(RequestOptions requestOptions)
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Post, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/{Data!.Id}/redact", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand Down
3 changes: 3 additions & 0 deletions tests/Falu.Tests/Clients/MessageBatchesServiceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public async Task StatusAsync_Works(RequestOptions requestOptions)
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Get, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/{Data!.Id}/status", req.RequestUri!.AbsolutePath);

var response = new HttpResponseMessage(HttpStatusCode.OK)
Expand All @@ -163,6 +164,7 @@ public async Task CancelAsync_Works(RequestOptions requestOptions)
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Post, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/{Data!.Id}/cancel", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand Down Expand Up @@ -191,6 +193,7 @@ public async Task RedactAsync_Works(RequestOptions requestOptions)
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Post, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/{Data!.Id}/redact", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand Down
2 changes: 2 additions & 0 deletions tests/Falu.Tests/Clients/MessageStreamsServiceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public async Task ArchiveAsync_Works(RequestOptions requestOptions)
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Post, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/{Data!.Id}/archive", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand Down Expand Up @@ -145,6 +146,7 @@ public async Task UnarchiveAsync_Works(RequestOptions requestOptions)
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Post, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/{Data!.Id!}/unarchive", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public async Task ValidateAsync_Works(RequestOptions requestOptions)
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Post, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/validate", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand Down
2 changes: 2 additions & 0 deletions tests/Falu.Tests/Clients/MessagesServiceClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public async Task CancelAsync_Works(RequestOptions requestOptions)
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Post, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/{Data!.Id}/cancel", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand Down Expand Up @@ -189,6 +190,7 @@ public async Task RedactAsync_Works(RequestOptions requestOptions)
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Post, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/{Data!.Id}/redact", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public async Task RefreshAsync_Works(RequestOptions requestOptions)
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Post, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/refresh", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public async Task ApproveAsync_Works(RequestOptions requestOptions)
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Post, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/{Data!.Id}/approve", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand Down Expand Up @@ -135,6 +136,7 @@ public async Task DeclineAsync_Works(RequestOptions requestOptions)
var handler = new DynamicHttpMessageHandler((req, ct) =>
{
Assert.Equal(HttpMethod.Post, req.Method);
Assert.Equal(ApiHost, req.RequestUri!.Host);
Assert.Equal($"{BasePath}/{Data!.Id}/decline", req.RequestUri!.AbsolutePath);

AssertRequestHeaders(req, requestOptions);
Expand Down