Adding trash api values when scanning a specific marker

This commit is contained in:
Nicolas SANS
2023-04-11 13:47:42 +02:00
parent af5acdae96
commit c092e3d426
32 changed files with 252 additions and 264 deletions

58
AR/Assets/utils/Api.cs Normal file
View File

@ -0,0 +1,58 @@
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using models;
using UnityEngine;
namespace utils
{
public class Api<T>
{
public static String API_URL = "https://iot.epi.cb85.software";
public static int API_TIMEOUT = 10000;
public static HttpWebRequest createClient(String suffix) {
return (HttpWebRequest)WebRequest.Create(API_URL + suffix);
}
public static T get(String suffix, String token)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(API_URL + suffix);
request.Accept = "application/json";
request.Method = "GET";
request.Headers.Add("Authorization", token);
request.Timeout=API_TIMEOUT;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response == null)
{
throw new Exception("Response is null");
}
StreamReader reader = new StreamReader(response.GetResponseStream());
string jsonResponse = reader.ReadToEnd();
T responseData = JsonUtility.FromJson<T>(jsonResponse);
response.Close();
return responseData;
}
public static T post(String suffix, String body)
{
HttpWebRequest request = createClient(suffix);
request.ContentType = "application/json";
request.Method = "POST";
request.Timeout=API_TIMEOUT;
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(body);
streamWriter.Flush();
streamWriter.Close();
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string jsonResponse = reader.ReadToEnd();
T responseData = JsonUtility.FromJson<T>(jsonResponse);
response.Close();
return responseData;
}
}
}

3
AR/Assets/utils/Api.cs.meta generated Normal file
View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1294827371cd4417aaab68f1c6736e6d
timeCreated: 1679386098