From 21c42ba8ed7bb5725a8de8eb2b45d31b265bf76d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Pa=C5=A1ko?= <patrik.pasko@twinzo.eu> Date: Wed, 3 Jul 2024 14:15:00 +0000 Subject: [PATCH] - added generic requests --- Main/Program.cs | 2 +- README.md | 5 ++++ SDK/Connection/DevkitConnector.cs | 2 ++ SDK/Connection/V3/Utils.cs | 46 +++++++++++++++++++++++++++++++ SDK/SDK.csproj | 2 +- tDevkit.sln | 5 ++++ 6 files changed, 60 insertions(+), 2 deletions(-) diff --git a/Main/Program.cs b/Main/Program.cs index e90d304..0cb61f6 100644 --- a/Main/Program.cs +++ b/Main/Program.cs @@ -80,7 +80,7 @@ namespace Main Login = "buffer", SensorData = dataList.ToArray(), }; - + // Send sensor with specified data to Twinzo server PostResponseContract[] response = await devkitConnector.AddSensorData(new[] { sensor }); Console.WriteLine(response); diff --git a/README.md b/README.md index 4f64a2a..d2f830f 100644 --- a/README.md +++ b/README.md @@ -242,6 +242,11 @@ await devkitConnector.AddSensorData(sensorContracts); * `GetDemoFile(fileName)` - Get byte representation of the specified demo file * `GetUnityLastVersion(platform)` - Get the last version of the Unity app * `GetUnityBundleInfo(bundleName)` - Get information (version, size, name) about the Unity Bundle + * **Generic methods** + * `Get(string subUrl)` + * `Post(string subUrl, object body)` + * `Patch(string subUrl, object body)` + * `Delete(string subUrl)` ## Future features - **protobuffers** serialization diff --git a/SDK/Connection/DevkitConnector.cs b/SDK/Connection/DevkitConnector.cs index 540498a..0444598 100644 --- a/SDK/Connection/DevkitConnector.cs +++ b/SDK/Connection/DevkitConnector.cs @@ -1,5 +1,6 @@ using SDK.Exceptions; using System; +using System.Net; using System.Net.Http; using System.Text; using System.Text.Json; @@ -32,6 +33,7 @@ namespace SDK { this.connectionOptions = connectionOptions; this.httpClient = httpClient; + this.httpClient.DefaultRequestVersion = HttpVersion.Version30; httpClient.BaseAddress = new Uri(connectionOptions.Url + "/" + connectionOptions.Version + "/"); ResetHttpClientHeaders(); diff --git a/SDK/Connection/V3/Utils.cs b/SDK/Connection/V3/Utils.cs index 8905ca4..50ec82f 100644 --- a/SDK/Connection/V3/Utils.cs +++ b/SDK/Connection/V3/Utils.cs @@ -1,6 +1,7 @@  using SDK.Contracts.Data; using SDK.Models; +using System; using System.Threading.Tasks; namespace SDK @@ -51,5 +52,50 @@ namespace SDK return response; } + + /// <summary> + /// Generic GET request + /// </summary> + /// <typeparam name="T">Returns type of T</typeparam> + /// <param name="subUrl"></param> + /// <returns></returns> + public async Task<T> Get<T>(string subUrl) + { + return await GetRequest<T>(subUrl); + } + + /// <summary> + /// Generic POST request + /// </summary> + /// <typeparam name="T">Returns type of T</typeparam> + /// <param name="subUrl"></param> + /// <param name="body"></param> + /// <returns></returns> + public async Task<T> Post<T>(string subUrl, object body) + { + return await PostRequest<T>(subUrl, body); + } + + /// <summary> + /// Generic PATCH request + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="subUrl"></param> + /// <param name="body"></param> + /// <returns></returns> + public async Task Patch(string subUrl, object body) + { + await PatchRequest(subUrl, body); + } + + /// <summary> + /// Generic DELETE request + /// </summary> + /// <param name="subUrl"></param> + /// <returns></returns> + public async Task Delete(string subUrl) + { + await DeleteRequest(subUrl); + } } } diff --git a/SDK/SDK.csproj b/SDK/SDK.csproj index 8571b4c..e89d2af 100644 --- a/SDK/SDK.csproj +++ b/SDK/SDK.csproj @@ -5,7 +5,7 @@ <TargetFramework>net8.0</TargetFramework> <AssemblyVersion>2021.6.28.25</AssemblyVersion> <FileVersion>2021.6.28.25</FileVersion> - <Version>4.11.0</Version> + <Version>4.12.0</Version> <GeneratePackageOnBuild>true</GeneratePackageOnBuild> </PropertyGroup> diff --git a/tDevkit.sln b/tDevkit.sln index a1f2e0b..c473bc2 100644 --- a/tDevkit.sln +++ b/tDevkit.sln @@ -9,6 +9,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "Test\Test\Test.cspr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Main", "Main\Main.csproj", "{E30C5B8F-0CA9-4947-8D83-95DC4612F4E1}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5BFAF4E7-6401-497C-B5F3-EF757BD49BDB}" + ProjectSection(SolutionItems) = preProject + README.md = README.md + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU -- GitLab