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.rest.blockadelabs 1.0.0-preview.1 #1

Merged
merged 18 commits into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixed some issues with auth setup
  • Loading branch information
StephenHodgson committed May 28, 2023
commit 35e48f15795deb15ff451375d561330ec6057ec0
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,5 @@ StreamingAssets/
StreamingAssets.meta
BlockadeLabs/Assets/Resources
BlockadeLabs/Assets/Resources.meta
BlockadeLabs/Assets/Plugins
BlockadeLabs/Assets/Plugins.meta
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,28 @@ public sealed class BlockadeLabsAuthentication : AbstractAuthentication<Blockade
/// Instantiates a new Authentication object that will load the default config.
/// </summary>
public BlockadeLabsAuthentication()
=> cachedDefault ??= (LoadFromAsset<BlockadeLabsConfiguration>() ??
LoadFromDirectory()) ??
LoadFromDirectory(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)) ??
LoadFromEnvironment();
{
cachedDefault ??= (LoadFromAsset<BlockadeLabsConfiguration>() ??
LoadFromDirectory()) ??
LoadFromDirectory(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)) ??
LoadFromEnvironment();
Info = cachedDefault?.Info;
}

/// <summary>
/// Instantiates a new Authentication object with the given <paramref name="apiKey"/>, which may be <see langword="null"/>.
/// </summary>
/// <param name="apiKey">The API key, required to access the API endpoint.</param>
public BlockadeLabsAuthentication(string apiKey) => authInfo = new BlockadeLabsAuthInfo(apiKey);
public BlockadeLabsAuthentication(string apiKey) => Info = new BlockadeLabsAuthInfo(apiKey);

/// <summary>
/// Instantiates a new Authentication object with the given <paramref name="authInfo"/>, which may be <see langword="null"/>.
/// </summary>
/// <param name="authInfo"></param>
public BlockadeLabsAuthentication(BlockadeLabsAuthInfo authInfo) => this.authInfo = authInfo;

public readonly BlockadeLabsAuthInfo authInfo;
public BlockadeLabsAuthentication(BlockadeLabsAuthInfo authInfo) => Info = authInfo;

/// <inheritdoc />
public override BlockadeLabsAuthInfo Info => authInfo ?? Default.Info;
public override BlockadeLabsAuthInfo Info { get; }

private static BlockadeLabsAuthentication cachedDefault;

Expand All @@ -48,7 +49,7 @@ public BlockadeLabsAuthentication()
/// </summary>
public static BlockadeLabsAuthentication Default
{
get => cachedDefault ?? new BlockadeLabsAuthentication();
get => cachedDefault ??= new BlockadeLabsAuthentication();
internal set => cachedDefault = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override void ValidateAuthentication()
}
}

public override bool HasValidAuthentication => !string.IsNullOrWhiteSpace(Authentication.Info.ApiKey);
public override bool HasValidAuthentication => !string.IsNullOrWhiteSpace(Authentication?.Info?.ApiKey);

internal JsonSerializerSettings JsonSerializationOptions { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,34 @@ public BlockadeLabsSettings()

var config = Resources.LoadAll<BlockadeLabsConfiguration>(string.Empty)
.FirstOrDefault(asset => asset != null);
Default = config != null
? new BlockadeLabsSettings(new BlockadeLabsSettingsInfo(config.ProxyDomain))
: new BlockadeLabsSettings(new BlockadeLabsSettingsInfo());

if (config != null)
{
Info = new BlockadeLabsSettingsInfo(config.ProxyDomain);
Default = new BlockadeLabsSettings(Info);
}
else
{
Info = new BlockadeLabsSettingsInfo();
Default = new BlockadeLabsSettings(Info);
}
}

public BlockadeLabsSettings(BlockadeLabsSettingsInfo settingsInfo)
=> this.settingsInfo = settingsInfo;
=> Info = settingsInfo;

public BlockadeLabsSettings(string domain)
=> settingsInfo = new BlockadeLabsSettingsInfo(domain);
=> Info = new BlockadeLabsSettingsInfo(domain);

private static BlockadeLabsSettings cachedDefault;

public static BlockadeLabsSettings Default
{
get => cachedDefault ?? new BlockadeLabsSettings();
get => cachedDefault ??= new BlockadeLabsSettings();
internal set => cachedDefault = value;
}

private readonly BlockadeLabsSettingsInfo settingsInfo;

public BlockadeLabsSettingsInfo Info => settingsInfo ?? Default.Info;
public BlockadeLabsSettingsInfo Info { get; }

public string BaseRequestUrlFormat => Info.BaseRequestUrlFormat;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace BlockadeLabs
{
public sealed class BlockadeLabsSettingsInfo : ISettingsInfo
{
internal const string DefaultDomain = "backend.blockadelabs.com";
internal const string DefaultDomain = "blockade.cloudshell.run";
internal const string DefaultVersion = "v1";

public BlockadeLabsSettingsInfo()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Utilities.Rest.Extensions;

namespace BlockadeLabs.Skyboxes
{
Expand All @@ -9,10 +11,12 @@ public sealed class SkyboxEndpoint : BlockadeLabsBaseEndpoint

protected override string Root => string.Empty;

public async Task GenerateSkyboxAsync(SkyboxRequest request, CancellationToken cancellationToken = default)
public async Task<string> GenerateSkyboxAsync(SkyboxRequest skyboxRequest, CancellationToken cancellationToken = default)
{

await Task.CompletedTask;
var jsonContent = JsonConvert.SerializeObject(skyboxRequest, client.JsonSerializationOptions).ToJsonStringContent();
var response = await client.Client.PostAsync(GetUrl("generate-skybox"), jsonContent, cancellationToken);
var responseAsString = await response.ReadAsStringAsync();
return responseAsString;
}

public async Task GetSkyboxCallbackAsync(CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using Newtonsoft.Json;

namespace BlockadeLabs.Skyboxes
{
public sealed class SkyboxInfo
{
[JsonConstructor]
public SkyboxInfo(
[JsonProperty("id")] int id,
[JsonProperty("skybox_style_id")] int skyboxStyleId,
[JsonProperty("skybox_style_name")] string skyboxStyleName,
[JsonProperty("status")] string status,
[JsonProperty("type")] string type,
[JsonProperty("queue_position")] int queuePosition,
[JsonProperty("file_url")] string fileUrl,
[JsonProperty("thumb_url")] string thumbUrl,
[JsonProperty("title")] string title,
[JsonProperty("user_id")] int userId,
[JsonProperty("username")] string username,
[JsonProperty("error_message")] object errorMessage,
[JsonProperty("obfuscated_id")] string obfuscatedId,
[JsonProperty("pusher_channel")] string pusherChannel,
[JsonProperty("pusher_event")] string pusherEvent,
[JsonProperty("created_at")] DateTime createdAt,
[JsonProperty("updated_at")] DateTime updatedAt
)
{
Id = id;
SkyboxStyleId = skyboxStyleId;
SkyboxStyleName = skyboxStyleName;
Status = status;
Type = type;
QueuePosition = queuePosition;
FileUrl = fileUrl;
ThumbUrl = thumbUrl;
Title = title;
UserId = userId;
Username = username;
ErrorMessage = errorMessage;
ObfuscatedId = obfuscatedId;
PusherChannel = pusherChannel;
PusherEvent = pusherEvent;
CreatedAt = createdAt;
UpdatedAt = updatedAt;
}

[JsonProperty("id")]
public int Id { get; }

[JsonProperty("skybox_style_id")]
public int SkyboxStyleId { get; }

[JsonProperty("skybox_style_name")]
public string SkyboxStyleName { get; }

[JsonProperty("status")]
public string Status { get; }

[JsonProperty("type")]
public string Type { get; }

[JsonProperty("queue_position")]
public int QueuePosition { get; }

[JsonProperty("file_url")]
public string FileUrl { get; }

[JsonProperty("thumb_url")]
public string ThumbUrl { get; }

[JsonProperty("title")]
public string Title { get; }

[JsonProperty("user_id")]
public int UserId { get; }

[JsonProperty("username")]
public string Username { get; }

[JsonProperty("error_message")]
public object ErrorMessage { get; }

[JsonProperty("obfuscated_id")]
public string ObfuscatedId { get; }

[JsonProperty("pusher_channel")]
public string PusherChannel { get; }

[JsonProperty("pusher_event")]
public string PusherEvent { get; }

[JsonProperty("created_at")]
public DateTime CreatedAt { get; }

[JsonProperty("updated_at")]
public DateTime UpdatedAt { get; }
}
}

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 @@ -144,7 +144,7 @@ public void Test_12_CustomDomainConfigurationSettings()
var auth = new BlockadeLabsAuthentication("customIssuedToken");
var settings = new BlockadeLabsSettings(domain: "api.your-custom-domain.com");
var api = new BlockadeLabsClient(auth, settings);
Console.WriteLine(api.Settings.Info.BaseRequestUrlFormat);
Debug.Log(api.Settings.Info.BaseRequestUrlFormat);
}

[TearDown]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using BlockadeLabs.Skyboxes;
using NUnit.Framework;
using UnityEngine;
using Task = System.Threading.Tasks.Task;

namespace BlockadeLabs.Tests
{
public class TestFixture_01_Skyboxes
{
[Test]
public async Task GenerateSkybox()
{
var api = new BlockadeLabsClient();
Assert.IsNotNull(api.SkyboxEndpoint);

var request = new SkyboxRequest("underwater");
var result = await api.SkyboxEndpoint.GenerateSkyboxAsync(request);
Debug.Log(result);
}
}
}

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