Skip to content

Commit 4f53d12

Browse files
committed
Cleanup http client, better redirect page
1 parent dcc5c18 commit 4f53d12

9 files changed

+95
-11
lines changed
0 Bytes
Binary file not shown.

Assets/Thirdweb/Runtime/Unity/Http.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System.Collections.Generic;
2+
using System.Net.Http;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using UnityEngine;
6+
7+
namespace Thirdweb.Unity
8+
{
9+
public class CrossPlatformUnityHttpClient : IThirdwebHttpClient
10+
{
11+
IThirdwebHttpClient _httpClient;
12+
13+
public CrossPlatformUnityHttpClient()
14+
{
15+
#if UNITY_EDITOR
16+
_httpClient = new ThirdwebHttpClient();
17+
#elif UNITY_WEBGL
18+
_httpClient = new Helpers.UnityThirdwebHttpClient();
19+
#else
20+
_httpClient = new ThirdwebHttpClient();
21+
#endif
22+
}
23+
24+
public Dictionary<string, string> Headers => _httpClient.Headers;
25+
26+
public void AddHeader(string key, string value)
27+
{
28+
_httpClient.AddHeader(key, value);
29+
}
30+
31+
public void ClearHeaders()
32+
{
33+
_httpClient.ClearHeaders();
34+
}
35+
36+
public Task<ThirdwebHttpResponseMessage> DeleteAsync(string requestUri, CancellationToken cancellationToken = default)
37+
{
38+
return _httpClient.DeleteAsync(requestUri, cancellationToken);
39+
}
40+
41+
public void Dispose()
42+
{
43+
_httpClient.Dispose();
44+
}
45+
46+
public Task<ThirdwebHttpResponseMessage> GetAsync(string requestUri, CancellationToken cancellationToken = default)
47+
{
48+
return _httpClient.GetAsync(requestUri, cancellationToken);
49+
}
50+
51+
public Task<ThirdwebHttpResponseMessage> PostAsync(string requestUri, HttpContent content, CancellationToken cancellationToken = default)
52+
{
53+
return _httpClient.PostAsync(requestUri, content, cancellationToken);
54+
}
55+
56+
public Task<ThirdwebHttpResponseMessage> PutAsync(string requestUri, HttpContent content, CancellationToken cancellationToken = default)
57+
{
58+
return _httpClient.PutAsync(requestUri, content, cancellationToken);
59+
}
60+
61+
public void RemoveHeader(string key)
62+
{
63+
_httpClient.RemoveHeader(key);
64+
}
65+
66+
public void SetHeaders(Dictionary<string, string> headers)
67+
{
68+
_httpClient.SetHeaders(headers);
69+
}
70+
}
71+
}

Assets/Thirdweb/Runtime/Unity/Http/CrossPlatformUnityHttpClient.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Thirdweb/Runtime/Unity/ThirdwebUnityHttpClient.cs renamed to Assets/Thirdweb/Runtime/Unity/Http/ThirdwebUnityHttpClient.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Net.Http;
44
using System.Threading;
55
using System.Threading.Tasks;
6-
using UnityEngine;
76
using UnityEngine.Networking;
87

98
namespace Thirdweb.Unity.Helpers

Assets/Thirdweb/Runtime/Unity/ThirdwebManager.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,11 @@ public void Initialize()
200200
Client = ThirdwebClient.Create(
201201
clientId: ClientId,
202202
bundleId: BundleId,
203-
httpClient: Application.platform == RuntimePlatform.WebGLPlayer ? new Helpers.UnityThirdwebHttpClient() : new ThirdwebHttpClient(),
204-
headers: new Dictionary<string, string>
205-
{
206-
{ "x-sdk-name", Application.platform == RuntimePlatform.WebGLPlayer ? "UnitySDK_WebGL" : "UnitySDK" },
207-
{ "x-sdk-os", Application.platform.ToString() },
208-
{ "x-sdk-platform", "unity" },
209-
{ "x-sdk-version", THIRDWEB_UNITY_SDK_VERSION },
210-
{ "x-client-id", ClientId },
211-
{ "x-bundle-id", BundleId }
212-
}
203+
httpClient: new CrossPlatformUnityHttpClient(),
204+
sdkName: Application.platform == RuntimePlatform.WebGLPlayer ? "UnitySDK_WebGL" : "UnitySDK",
205+
sdkOs: Application.platform.ToString(),
206+
sdkPlatform: "unity",
207+
sdkVersion: THIRDWEB_UNITY_SDK_VERSION
213208
);
214209

215210
ThirdwebDebug.Log("ThirdwebManager initialized.");

0 commit comments

Comments
 (0)