Skip to content

Commit

Permalink
com.utilities.rest 3.1.2 (#81)
Browse files Browse the repository at this point in the history
- added IServerSentEvent interface to implement on custom event callbacks.
  • Loading branch information
StephenHodgson authored Jun 9, 2024
1 parent 91de28f commit 12293d1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

namespace Utilities.WebRequestRest.Interfaces
{
/// <summary>
/// Common interface for streaming server sent events
/// </summary>
public interface IServerSentEvent
{
string Object { get; }

string ToJsonString();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ServerSentEventKind> EventMap = new()
Expand All @@ -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)}");
Expand Down
2 changes: 1 addition & 1 deletion Utilities.Rest/Packages/com.utilities.rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 12293d1

Please sign in to comment.