-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced new concept with provider credentials details
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
Showing
5 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/Skybrud.VideoPicker/Models/Providers/IVideoProviderCredentialsDetails.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
|
||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/Skybrud.VideoPicker/Models/Providers/VideoProviderCredentialsDetails.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters