Skip to content

Commit

Permalink
Introduced new concept with provider credentials details
Browse files Browse the repository at this point in the history
Whenever we save the details about a video, it may be useful to also save a reference to the credentials that were used for retrieving the video - eg. if we later need to fetch additional information about the video.

Implements #6
  • Loading branch information
abjerner committed Oct 5, 2021
1 parent 9384532 commit 621047b
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using Newtonsoft.Json;
using Skybrud.VideoPicker.Models.Config;

namespace Skybrud.VideoPicker.Models.Providers {

/// <summary>
/// Interface describing a trimmed down version of <see cref="IProviderCredentials"/>.
///
/// The general idea with this interface is that while classes implementing <see cref="IProviderCredentials"/> may
/// expose sensitive information (eg. API keys or access tokens for the provider), classes implementing
/// <see cref="IVideoProviderCredentialsDetails"/> should instead be seen as a reference to the crendentials - and
/// without any sensitive information.
/// </summary>
public interface IVideoProviderCredentialsDetails {

/// <summary>
/// Gets the unique ID of the credentials.
/// </summary>
[JsonProperty("id")]
Guid Id { get; }

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using Newtonsoft.Json.Linq;
using Skybrud.Essentials.Json.Extensions;
using Skybrud.VideoPicker.Models.Config;

namespace Skybrud.VideoPicker.Models.Providers {

/// <summary>
/// Default implementation of the <see cref="IVideoProviderCredentialsDetails"/> interface.
/// </summary>
public class VideoProviderCredentialsDetails : IVideoProviderCredentialsDetails {

#region Properties

/// <summary>
/// Gets the unique ID of the credentials.
/// </summary>
public Guid Id { get; }

#endregion

#region Constructors

private VideoProviderCredentialsDetails(JObject json) {
Id = json.GetGuid("id");
}

/// <summary>
/// Initializes a new instance from the specified <paramref name="credentials"/>.
/// </summary>
/// <param name="credentials">The full crendentials model this instance should be based on.</param>
public VideoProviderCredentialsDetails(IProviderCredentials credentials) {
Id = credentials.Id;
}

#endregion

#region Static methods

/// <summary>
/// Parses the specified <paramref name="json"/> into an instance of <see cref="VideoProviderCredentialsDetails"/>.
/// </summary>
/// <param name="json">The instance of <see cref="JObject"/> to be parsed.</param>
/// <returns>An instance of <see cref="VideoProviderCredentialsDetails"/>.</returns>
public static VideoProviderCredentialsDetails Parse(JObject json) {
return json == null ? null : new VideoProviderCredentialsDetails(json);
}

#endregion

}

}
14 changes: 14 additions & 0 deletions src/Skybrud.VideoPicker/Models/VideoPickerValue.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Web;
using Newtonsoft.Json;
using Skybrud.Essentials.Json.Converters;
using Skybrud.VideoPicker.Models.Config;
using Skybrud.VideoPicker.Models.Providers;
using Skybrud.VideoPicker.Models.Videos;

Expand All @@ -13,6 +14,12 @@ public class VideoPickerValue {
[JsonProperty("provider")]
public IVideoProviderDetails Provider { get; }

/// <summary>
/// Gets a reference to the credentials used when this video was inserted.
/// </summary>
[JsonProperty("credentials")]
public IVideoProviderCredentialsDetails Credentials { get; }

[JsonProperty("details")]
public IVideoDetails Details { get; }

Expand All @@ -33,6 +40,13 @@ public VideoPickerValue(IVideoProviderDetails provider, IVideoDetails details, I
Embed = embed;
}

public VideoPickerValue(IVideoProviderDetails provider, IVideoProviderCredentialsDetails credentials, IVideoDetails details, IVideoEmbedOptions embed) {
Provider = provider;
Credentials = credentials;
Details = details;
Embed = embed;
}

#endregion

}
Expand Down
8 changes: 6 additions & 2 deletions src/Skybrud.VideoPicker/Providers/Vimeo/VimeoVideoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,27 @@ public VideoPickerValue GetVideo(VideoPickerService service, IVideoOptions optio

VideoProviderDetails provider = new VideoProviderDetails(Alias, Name);

VideoProviderCredentialsDetails credentailsDetails = new VideoProviderCredentialsDetails(credentials);

VimeoVideoDetails details = new VimeoVideoDetails(video);

VimeoVideoEmbedOptions embed = new VimeoVideoEmbedOptions(details);

return new VideoPickerValue(provider, details, embed);
return new VideoPickerValue(provider, credentailsDetails, details, embed);

}

public VideoPickerValue ParseValue(JObject obj, IProviderDataTypeConfig config) {

VideoProviderDetails provider = new VideoProviderDetails(Alias, Name);

VideoProviderCredentialsDetails credentials = obj.GetObject("credentials", VideoProviderCredentialsDetails.Parse);

VimeoVideoDetails details = obj.GetObject("details", VimeoVideoDetails.Parse);

VimeoVideoEmbedOptions embed = new VimeoVideoEmbedOptions(details, config as VimeoDataTypeConfig);

return new VideoPickerValue(provider, details, embed);
return new VideoPickerValue(provider, credentials, details, embed);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ public VideoPickerValue ParseValue(JObject obj, IProviderDataTypeConfig config)

VideoProviderDetails provider = new VideoProviderDetails(Alias, Name);

VideoProviderCredentialsDetails credentials = obj.GetObject("credentials", VideoProviderCredentialsDetails.Parse);

YouTubeVideoDetails details = obj.GetObject("details", YouTubeVideoDetails.Parse);

YouTubeVideoEmbedOptions embed = new YouTubeVideoEmbedOptions(details, config as YouTubeDataTypeConfig);

return new VideoPickerValue(provider, details, embed);
return new VideoPickerValue(provider, credentials, details, embed);

}

Expand Down

0 comments on commit 621047b

Please sign in to comment.