Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #11 from xpouyat/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
xpouyat authored Oct 20, 2023
2 parents 957debf + f07bd3b commit ca4c5f6
Show file tree
Hide file tree
Showing 42 changed files with 547 additions and 264 deletions.
124 changes: 124 additions & 0 deletions MK.IO/Account/AccountOperations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace MK.IO
{
/// <summary>
/// REST Client for MKIO
/// https://io.mediakind.com
///
/// </summary>
internal class AccountOperations : IAccountOperations
{
//
// subscription operations
//
private const string _accountProfileApiUrl = "api/profile/";
private const string _accountStatsApiUrl = "api/ams/{0}/stats/";
private const string _accountApiUrl = "api/accounts/{0}/";
private const string _accountSubscriptionsUrl = _accountApiUrl + "subscriptions/";
private const string _accountSubscriptionUrl = _accountSubscriptionsUrl + "{1}";
private const string _locationsApiUrl = "api/locations/";

/// <summary>
/// Gets a reference to the AzureMediaServicesClient
/// </summary>
private MKIOClient Client { get; set; }

/// <summary>
/// Initializes a new instance of the SubscriptionOperations class.
/// </summary>
/// <param name='client'>
/// Reference to the service client.
/// </param>
/// <exception cref="ArgumentNullException">
/// Thrown when a required parameter is null
/// </exception>
internal AccountOperations(MKIOClient client)
{
Client = client ?? throw new ArgumentNullException(nameof(client));
}

/// <inheritdoc/>
public AccountStats GetSubscriptionStats()
{
var task = Task.Run(async () => await GetSubscriptionStatsAsync());
return task.GetAwaiter().GetResult();
}

/// <inheritdoc/>
public async Task<AccountStats> GetSubscriptionStatsAsync()
{
var url = Client.GenerateApiUrl(_accountStatsApiUrl);
string responseContent = await Client.GetObjectContentAsync(url);
return AccountStats.FromJson(responseContent);
}

/// <inheritdoc/>
public UserInfo GetUserProfile()
{
var task = Task.Run(async () => await GetUserProfileAsync());
return task.GetAwaiter().GetResult();
}

/// <inheritdoc/>
public async Task<UserInfo> GetUserProfileAsync()
{
string responseContent = await Client.GetObjectContentAsync(Client._baseUrl + _accountProfileApiUrl);
return AccountProfile.FromJson(responseContent).Spec;
}

/// <inheritdoc/>
public List<SubscriptionResponseSchema> ListAllSubscriptions()
{
var task = Task.Run(async () => await ListAllSubscriptionsAsync());
return task.GetAwaiter().GetResult();
}

/// <inheritdoc/>
public async Task<List<SubscriptionResponseSchema>> ListAllSubscriptionsAsync()
{
string responseContent = await Client.GetObjectContentAsync(GenerateAccountApiUrl(_accountSubscriptionsUrl));
return SubscriptionListResponseSchema.FromJson(responseContent).Items;
}

/// <inheritdoc/>
public SubscriptionResponseSchema GetSubscription()
{
var task = Task.Run(async () => await GetSubscriptionAsync());
return task.GetAwaiter().GetResult();
}

/// <inheritdoc/>
public async Task<SubscriptionResponseSchema> GetSubscriptionAsync()
{
string responseContent = await Client.GetObjectContentAsync(GenerateSubscriptionApiUrl(_accountSubscriptionUrl));
return SubscriptionResponseSchema.FromJson(responseContent);
}

/// <inheritdoc/>
public List<LocationResponseSchema> ListAllLocations()
{
var task = Task.Run(async () => await ListAllLocationsAsync());
return task.GetAwaiter().GetResult();
}

/// <inheritdoc/>
public async Task<List<LocationResponseSchema>> ListAllLocationsAsync()
{
string responseContent = await Client.GetObjectContentAsync(Client._baseUrl + _locationsApiUrl);
return LocationListResponseSchema.FromJson(responseContent).Items;
}


internal string GenerateAccountApiUrl(string urlPath)
{
return Client._baseUrl + string.Format(urlPath, Client.GetCustomerId());
}

internal string GenerateSubscriptionApiUrl(string urlPath)
{
return Client._baseUrl + string.Format(urlPath, Client.GetCustomerId(), Client.GetSubscriptionId());
}
}
}
68 changes: 68 additions & 0 deletions MK.IO/Account/IAccountOperations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace MK.IO
{
public interface IAccountOperations
{
/// <summary>
/// Get statistics for the current MK/IO subscription.
/// </summary>
/// <returns></returns>
AccountStats GetSubscriptionStats();

/// <summary>
/// Get statistics for the current MK/IO subscription.
/// </summary>
/// <returns></returns>
Task<AccountStats> GetSubscriptionStatsAsync();

/// <summary>
/// Get user profile information.
/// </summary>
/// <returns></returns>
UserInfo GetUserProfile();

/// <summary>
/// Get user profile information.
/// </summary>
/// <returns></returns>
Task<UserInfo> GetUserProfileAsync();

/// <summary>
/// Get the list of all MK/IO subscriptions for the account.
/// </summary>
/// <returns></returns>
List<SubscriptionResponseSchema> ListAllSubscriptions();

/// <summary>
/// Get the list of all MK/IO subscriptions for the account.
/// </summary>
/// <returns></returns>
Task<List<SubscriptionResponseSchema>> ListAllSubscriptionsAsync();

/// <summary>
/// Get the current MK/IO subscription.
/// </summary>
/// <returns></returns>
SubscriptionResponseSchema GetSubscription();

/// <summary>
/// Get the current MK/IO subscription.
/// </summary>
/// <returns></returns>
Task<SubscriptionResponseSchema> GetSubscriptionAsync();

/// <summary>
/// List all possible locations for MK/IO (Ids and names).
/// </summary>
/// <returns></returns>
List<LocationResponseSchema> ListAllLocations();

/// <summary>
/// List all possible locations for MK/IO (Ids and names).
/// </summary>
/// <returns></returns>
Task<List<LocationResponseSchema>> ListAllLocationsAsync();
}
}
27 changes: 27 additions & 0 deletions MK.IO/Account/Models/LocationListResponseSchema.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Newtonsoft.Json;

namespace MK.IO
{
public partial class LocationListResponseSchema
{
public static LocationListResponseSchema FromJson(string json)
{
return JsonConvert.DeserializeObject<LocationListResponseSchema>(json, ConverterLE.Settings);
}

public string ToJson()
{
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}


[JsonProperty("kind")]
public string Kind { get; set; }

[JsonProperty("items")]
public List<LocationResponseSchema> Items { get; set; }
}
}
37 changes: 37 additions & 0 deletions MK.IO/Account/Models/LocationResponseSchema.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Newtonsoft.Json;

namespace MK.IO
{
public partial class LocationResponseSchema
{
public static LocationResponseSchema FromJson(string json)
{
return JsonConvert.DeserializeObject<LocationResponseSchema>(json, ConverterLE.Settings);
}

public string ToJson()
{
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}


[JsonProperty("metadata")]
public MetadataLocation Metadata { get; set; }
}


public class MetadataLocation
{
[JsonProperty("id")]
public Guid Id { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("displayName")]
public string DisplayName { get; set; }
}
}
27 changes: 27 additions & 0 deletions MK.IO/Account/Models/SubscriptionListResponseSchema.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Newtonsoft.Json;

namespace MK.IO
{
public partial class SubscriptionListResponseSchema
{
public static SubscriptionListResponseSchema FromJson(string json)
{
return JsonConvert.DeserializeObject<SubscriptionListResponseSchema>(json, ConverterLE.Settings);
}

public string ToJson()
{
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}


[JsonProperty("kind")]
public string Kind { get; set; }

[JsonProperty("items")]
public List<SubscriptionResponseSchema> Items { get; set; }
}
}
39 changes: 39 additions & 0 deletions MK.IO/Account/Models/SubscriptionResponseSchema.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Newtonsoft.Json;

namespace MK.IO
{

public class SubscriptionResponseSchema
{
public static SubscriptionResponseSchema FromJson(string json)
{
return JsonConvert.DeserializeObject<SubscriptionResponseSchema>(json, ConverterLE.Settings);
}

public string ToJson()
{
return JsonConvert.SerializeObject(this, ConverterLE.Settings);
}

[JsonProperty("metadata")]
public MetadataSubscription Metadata { get; set; }

[JsonProperty("spec")]
public SubscriptionSchema Spec { get; set; }
}

public class MetadataSubscription
{
[JsonProperty("id")]
public Guid Id { get; set; }

[JsonProperty("created")]
public DateTime Created { get; set; }

[JsonProperty("updated")]
public DateTime Updated { get; set; }
}
}
46 changes: 46 additions & 0 deletions MK.IO/Account/Models/SubscriptionSchema.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Newtonsoft.Json;

namespace MK.IO
{
public class SubscriptionSchema
{
[JsonProperty("customerId")]
public Guid CustomerId { get; set; }

[JsonProperty("createdById")]
public Guid CreatedById { get; set; }

[JsonProperty("locationId")]
public Guid LocationId { get; set; }

[JsonProperty("azureSubscriptionName")]
public string AzureSubscriptionName { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("isActive")]
public bool IsActive { get; set; }

[JsonProperty("projectSubscriptionId")]
public Guid ProjectSubscriptionId { get; set; }

[JsonProperty("productPublicationId")]
public Guid ProductPublicationId { get; set; }

[JsonProperty("azureSubscriptionStatus")]
public string AzureSubscriptionStatus { get; set; }

[JsonProperty("azureSubscriptionId")]
public Guid AzureSubscriptionId { get; set; }

[JsonProperty("azureSubscriptionOfferId")]
public string AzureSubscriptionOfferId { get; set; }

[JsonProperty("azureSubscriptionPlanId")]
public string AzureSubscriptionPlanId { get; set; }
}
}
2 changes: 1 addition & 1 deletion MK.IO/AccountFilter/AccountFiltersOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task<List<AccountFilterSchema>> ListAsync()
{
var url = Client.GenerateApiUrl(_accountFiltersApiUrl);
string responseContent = await Client.GetObjectContentAsync(url);
return JsonConvert.DeserializeObject<AccountFilterListResponseSchema>(responseContent, ConverterLE.Settings).Filters;
return JsonConvert.DeserializeObject<AccountFilterListResponseSchema>(responseContent, ConverterLE.Settings).Value;
}

/// <inheritdoc/>
Expand Down
2 changes: 1 addition & 1 deletion MK.IO/Asset/AssetsOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public List<AssetStreamingLocator> ListStreamingLocators(string assetName)
public async Task<List<AssetStreamingLocator>> ListStreamingLocatorsAsync(string assetName)
{
var url = Client.GenerateApiUrl(_assetListStreamingLocatorsApiUrl, assetName);
string responseContent = await Client.GetObjectContentAsync(url);
string responseContent = await Client.GetObjectPostContentAsync(url);
return AssetListStreamingLocators.FromJson(responseContent).StreamingLocators;
}

Expand Down
Loading

0 comments on commit ca4c5f6

Please sign in to comment.