Skip to content

Commit 1e57429

Browse files
authored
Merge pull request #29 from uramakilab/dev
Update JSON
2 parents b0f2f6a + 4660654 commit 1e57429

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1055
-2
lines changed

Editor.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.

Editor/API.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.

Editor/API/APIService.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using UnityEngine;
2+
using UnityEngine.Networking;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text.RegularExpressions;
6+
using System.Net;
7+
using System.IO;
8+
9+
abstract class APIService {
10+
11+
public static File GetDocument() {
12+
HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"https://api.figma.com/v1/files{Global.documentID}");
13+
request.Headers.Add("Authorization", $"Bearer {Global.token}");
14+
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) {
15+
StreamReader reader = new StreamReader(response.GetResponseStream());
16+
string json = reader.ReadToEnd();
17+
Regex regex = new Regex("(|(PositionX)|(PositionY)|(PositionZ)|(RotationX)|(RotationY))#[0-9]+:[0-9]+");
18+
json = regex.Replace(json, "$1");
19+
return JsonUtility.FromJson<File>(json);
20+
}
21+
}
22+
23+
public static string GetImage() {
24+
HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"https://api.figma.com/v1/files{Global.documentID}/images");
25+
request.Headers.Add("Authorization", $"Bearer {Global.token}");
26+
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) {
27+
StreamReader reader = new StreamReader(response.GetResponseStream());
28+
return reader.ReadToEnd();
29+
}
30+
}
31+
32+
public static string ContentType(string url) {
33+
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
34+
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
35+
string type = response.ContentType;
36+
return type.Remove(0, type.IndexOf("/")+1);
37+
}
38+
39+
public static bool DownloadImage(string url, string path) {
40+
UnityWebRequest uwr = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET);
41+
uwr.downloadHandler = new DownloadHandlerFile(path);
42+
uwr.SendWebRequest();
43+
while(!uwr.isDone){}
44+
return uwr.responseCode == 200 ? true : false;
45+
}
46+
47+
public static string GetImageID(string id) {
48+
HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"https://api.figma.com/v1/images{Global.documentID}?ids={id}");
49+
request.Headers.Add("Authorization", "Bearer "+ Global.token);
50+
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) {
51+
StreamReader reader = new StreamReader(response.GetResponseStream());
52+
return reader.ReadToEnd();
53+
}
54+
}
55+
}

Editor/API/APIService.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.

Editor/API/JSON.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.

Editor/API/JSON/File.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.

Editor/API/JSON/File/Document.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[System.Serializable]
2+
public class Document {
3+
public string id;
4+
public string name;
5+
public string type;
6+
public string scrollBehavior;
7+
public Page[] children;
8+
}

Editor/API/JSON/File/Document.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.

Editor/API/JSON/File/File.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[System.Serializable]
2+
public class File {
3+
public Document document;
4+
public string[] components;
5+
public string[] componentSets;
6+
public string[] schemaVersion;
7+
public string[] styles;
8+
public string name;
9+
public string lastModified;
10+
public string thumbnailUrl;
11+
public string version;
12+
public string role;
13+
public string editorType;
14+
public string linkAccess;
15+
}

Editor/API/JSON/File/File.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.

0 commit comments

Comments
 (0)