diff --git a/Utilities.Rest/Packages/com.utilities.rest/Runtime/Interfaces/IServerSentEvent.cs b/Utilities.Rest/Packages/com.utilities.rest/Runtime/Interfaces/IServerSentEvent.cs new file mode 100644 index 0000000..852df2f --- /dev/null +++ b/Utilities.Rest/Packages/com.utilities.rest/Runtime/Interfaces/IServerSentEvent.cs @@ -0,0 +1,14 @@ +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace Utilities.WebRequestRest.Interfaces +{ + /// + /// Common interface for streaming server sent events + /// + public interface IServerSentEvent + { + string Object { get; } + + string ToJsonString(); + } +} diff --git a/Utilities.Rest/Packages/com.utilities.rest/Runtime/Interfaces/IServerSentEvent.cs.meta b/Utilities.Rest/Packages/com.utilities.rest/Runtime/Interfaces/IServerSentEvent.cs.meta new file mode 100644 index 0000000..0f70b58 --- /dev/null +++ b/Utilities.Rest/Packages/com.utilities.rest/Runtime/Interfaces/IServerSentEvent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: aadfe9ffc3f8fd84793afffa89b8828a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Utilities.Rest/Packages/com.utilities.rest/Runtime/ServerSentEvent.cs b/Utilities.Rest/Packages/com.utilities.rest/Runtime/ServerSentEvent.cs index be4955e..b181c9e 100644 --- a/Utilities.Rest/Packages/com.utilities.rest/Runtime/ServerSentEvent.cs +++ b/Utilities.Rest/Packages/com.utilities.rest/Runtime/ServerSentEvent.cs @@ -5,11 +5,12 @@ using System.Collections.Generic; using System.Text; using UnityEngine.Scripting; +using Utilities.WebRequestRest.Interfaces; namespace Utilities.WebRequestRest { [Preserve] - public sealed class ServerSentEvent + public sealed class ServerSentEvent : IServerSentEvent { [Preserve] internal static readonly Dictionary EventMap = new() @@ -33,8 +34,16 @@ public sealed class ServerSentEvent [Preserve] public JToken Data { get; internal set; } + [Preserve] + [JsonIgnore] + public string Object => "stream.event"; + [Preserve] public override string ToString() + => ToJsonString(); + + [Preserve] + public string ToJsonString() { var stringBuilder = new StringBuilder(); stringBuilder.Append($"{{\"{Event.ToString().ToLower()}\": {Value.ToString(Formatting.None)}"); diff --git a/Utilities.Rest/Packages/com.utilities.rest/package.json b/Utilities.Rest/Packages/com.utilities.rest/package.json index 1236654..f7d1041 100644 --- a/Utilities.Rest/Packages/com.utilities.rest/package.json +++ b/Utilities.Rest/Packages/com.utilities.rest/package.json @@ -3,7 +3,7 @@ "displayName": "Utilities.Rest", "description": "This package contains useful RESTful utilities for the Unity Game Engine.", "keywords": [], - "version": "3.1.1", + "version": "3.1.2", "unity": "2021.3", "documentationUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest#documentation", "changelogUrl": "https://github.com/RageAgainstThePixel/com.utilities.rest/releases",