Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

com.utilities.rest 3.1.2 #81

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
com.utilities.rest 3.1.2
- added IServerSentEvent interface to implement on custom event callbacks.
  • Loading branch information
StephenHodgson committed Jun 9, 2024
commit 8da54783e80b8ca649f9f78dae99e3c9ad19b3cc
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