Skip to content

Commit a936d35

Browse files
committed
- Use supabase-core and implement IGettableHeaders on Client
1 parent bf9405f commit a936d35

File tree

6 files changed

+42
-74
lines changed

6 files changed

+42
-74
lines changed

Functions/Client.cs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Newtonsoft.Json;
2-
using Supabase.Functions.Extensions;
2+
using Supabase.Core;
3+
using Supabase.Core.Extensions;
34
using Supabase.Functions.Interfaces;
45
using Supabase.Functions.Responses;
56
using System;
@@ -14,11 +15,16 @@
1415
namespace Supabase.Functions
1516
{
1617

17-
public class Client : IFunctionsClient
18+
public partial class Client : IFunctionsClient
1819
{
1920
private static readonly HttpClient client = new HttpClient();
2021
private string baseUrl;
2122

23+
/// <summary>
24+
/// Function that can be set to return dynamic headers.
25+
///
26+
/// Headers specified in the method parameters will ALWAYS take precendece over headers returned by this function.
27+
/// </summary>
2228
public Func<Dictionary<string, string>>? GetHeaders { get; set; }
2329

2430
public Client(string baseUrl)
@@ -98,7 +104,7 @@ internal async Task<HttpResponseMessage> HandleRequest(string url, string? token
98104
options.Headers["Authorization"] = $"Bearer {token}";
99105
}
100106

101-
options.Headers["X-Client-Info"] = Util.GetAssemblyVersion();
107+
options.Headers["X-Client-Info"] = Util.GetAssemblyVersion(typeof(Client));
102108

103109
var builder = new UriBuilder(url);
104110
var query = HttpUtility.ParseQueryString(builder.Query);
@@ -146,25 +152,5 @@ public RequestException(HttpResponseMessage response, ErrorResponse error) : bas
146152
Error = error;
147153
}
148154
}
149-
150-
/// <summary>
151-
/// Options that can be supplied to a function invocation.
152-
///
153-
/// Note: If Headers.Authorization is set, it can be later overriden if a token is supplied in the method call.
154-
/// </summary>
155-
public class InvokeFunctionOptions
156-
{
157-
/// <summary>
158-
/// Headers to be included on the request.
159-
/// </summary>
160-
public Dictionary<string, string> Headers { get; set; } = new Dictionary<string, string>();
161-
162-
163-
/// <summary>
164-
/// Body of the Request
165-
/// </summary>
166-
[JsonProperty("body")]
167-
public Dictionary<string, object> Body { get; set; } = new Dictionary<string, object>();
168-
}
169155
}
170156
}

Functions/Extensions/DictionaryExtensions.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.

Functions/Functions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@
3939
</PropertyGroup>
4040
<ItemGroup>
4141
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
42+
<PackageReference Include="supabase-core" Version="0.0.2" />
4243
</ItemGroup>
4344
</Project>

Functions/Interfaces/IFunctionsClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
using System;
1+
using Supabase.Core.Interfaces;
2+
using System;
23
using System.Collections.Generic;
34
using System.Net.Http;
45
using System.Threading.Tasks;
56

67
namespace Supabase.Functions.Interfaces
78
{
8-
public interface IFunctionsClient
9+
public interface IFunctionsClient : IGettableHeaders
910
{
10-
Func<Dictionary<string, string>>? GetHeaders { get; set; }
1111
Task<string> Invoke(string url, string? token = null, Client.InvokeFunctionOptions? options = null);
1212
Task<T?> Invoke<T>(string url, string? token = null, Client.InvokeFunctionOptions? options = null) where T : class;
1313
Task<HttpContent> RawInvoke(string url, string? token = null, Client.InvokeFunctionOptions? options = null);

Functions/InvokeFunctionOptions.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Newtonsoft.Json;
2+
using System.Collections.Generic;
3+
4+
namespace Supabase.Functions
5+
{
6+
7+
public partial class Client
8+
{
9+
/// <summary>
10+
/// Options that can be supplied to a function invocation.
11+
///
12+
/// Note: If Headers.Authorization is set, it can be later overriden if a token is supplied in the method call.
13+
/// </summary>
14+
public class InvokeFunctionOptions
15+
{
16+
/// <summary>
17+
/// Headers to be included on the request.
18+
/// </summary>
19+
public Dictionary<string, string> Headers { get; set; } = new Dictionary<string, string>();
20+
21+
22+
/// <summary>
23+
/// Body of the Request
24+
/// </summary>
25+
[JsonProperty("body")]
26+
public Dictionary<string, object> Body { get; set; } = new Dictionary<string, object>();
27+
}
28+
}
29+
}

Functions/Util.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)