This repository has been archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from xpouyat/dev
Dev
- Loading branch information
Showing
42 changed files
with
547 additions
and
264 deletions.
There are no files selected for viewing
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,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()); | ||
} | ||
} | ||
} |
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,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(); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
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,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; } | ||
} | ||
} |
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,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; } | ||
} | ||
} |
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,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; } | ||
} | ||
} |
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,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; } | ||
} | ||
} |
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,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; } | ||
} | ||
} |
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
Oops, something went wrong.