Skip to content

Commit ff86fa5

Browse files
committed
Merged PR 54616: Implement parallel update, token check, api class
Heavily refactored the figma update method Implemented per-update NodeMetadata Implement filtering shallow update Cleanup code with analyzers Implement token verification Implement base FigmaApi class
1 parent 9c14beb commit ff86fa5

File tree

16 files changed

+1336
-1621
lines changed

16 files changed

+1336
-1621
lines changed

Editor/Core/JsonUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static void Initialize()
3434
#endregion
3535
}
3636

37-
public abstract class ArrayConverter<T, U> : JsonConverter
37+
public abstract class ArrayConverter<T, TEnum> : JsonConverter
3838
{
3939
#region Methods
4040
public override bool CanConvert(Type objectType) => objectType == typeof(T[]);
@@ -52,7 +52,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
5252
foreach (T node in array) serializer.Serialize(writer, node);
5353
writer.WriteEndArray();
5454
}
55-
protected U GetValue(JObject obj, string name = "type") => (U)Enum.Parse(typeof(U), obj[name].Value<string>());
55+
protected TEnum GetValue(JObject obj, string name = "type") => (TEnum)Enum.Parse(typeof(TEnum), obj[name].Value<string>());
5656
protected abstract T ToObject(JObject obj, JsonSerializer serializer);
5757
#endregion
5858
}

Editor/Core/NodeMetadata.cs

Lines changed: 345 additions & 0 deletions
Large diffs are not rendered by default.

Editor/Core/NodeMetadata.cs.meta

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

Editor/Extensions/NodeExtensions.cs

Lines changed: 15 additions & 741 deletions
Large diffs are not rendered by default.

Editor/FigmaParser.cs

Lines changed: 329 additions & 355 deletions
Large diffs are not rendered by default.

Editor/Inspector/FigmaApi.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Collections.Generic;
2+
using System.Text;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using Trackman;
6+
7+
namespace Figma.Inspectors
8+
{
9+
using global;
10+
11+
abstract class FigmaApi
12+
{
13+
const string api = "https://api.figma.com/v1";
14+
15+
#region Fields
16+
protected readonly string title;
17+
protected readonly Dictionary<string, string> headers;
18+
#endregion
19+
20+
#region Constructors
21+
protected FigmaApi(string personalAccessToken = default, string title = default)
22+
{
23+
this.title = title;
24+
headers = new Dictionary<string, string> { { "X-FIGMA-TOKEN", personalAccessToken } };
25+
}
26+
#endregion
27+
28+
#region Support Methods
29+
protected async Task<string> GetJsonAsync(string get, CancellationToken token = default)
30+
{
31+
return GetString(await $"{api}/{get}".HttpGetAsync(headers, cancellationToken: token));
32+
}
33+
protected async Task<T> ConvertOnBackgroundAsync<T>(string json, CancellationToken token) where T : class
34+
{
35+
return await Task.Run(() => Task.FromResult(JsonUtility.FromJson<T>(json)), token);
36+
}
37+
protected async Task<T> GetAsync<T>(string get, CancellationToken token = default) where T : class
38+
{
39+
string json = await GetJsonAsync(get, token);
40+
return await ConvertOnBackgroundAsync<T>(json, token);
41+
}
42+
string GetString(byte[] bytes)
43+
{
44+
return Encoding.UTF8.GetString(bytes);
45+
}
46+
#endregion
47+
}
48+
}

Editor/Inspector/FigmaApi.cs.meta

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

Editor/Inspector/FigmaInspector.cs

Lines changed: 78 additions & 484 deletions
Large diffs are not rendered by default.

Editor/Inspector/FigmaTokenTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Figma.Inspectors
4+
{
5+
using global;
6+
7+
class FigmaTokenTest : FigmaApi
8+
{
9+
#region Constructors
10+
internal FigmaTokenTest(string personalAccessToken = default) : base(personalAccessToken) { }
11+
#endregion
12+
13+
#region Methods
14+
internal async Task<bool> TestAsync()
15+
{
16+
Me me = await GetAsync<Me>("me");
17+
return string.IsNullOrEmpty(me.err) && me.email.Contains("@");
18+
}
19+
#endregion
20+
}
21+
}

Editor/Inspector/FigmaTokenTest.cs.meta

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

0 commit comments

Comments
 (0)