Skip to content

Commit

Permalink
fix: fix some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Dec 19, 2024
1 parent 958497a commit cc5acb0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
14 changes: 11 additions & 3 deletions AITSYS.Vimeo.Ott/Clients/VimeoOttApiClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2025 Aiko IT Systems. See https://github.com/Aiko-IT-Systems/AITSYS.Vimeo.OTT/blob/main/LICENSE.md for the license.

using System.Net;

using AITSYS.Vimeo.Ott.Entities.Customers;
using AITSYS.Vimeo.Ott.Entities.EmbeddedData;
using AITSYS.Vimeo.Ott.Entities.Pagination;
Expand Down Expand Up @@ -66,7 +68,7 @@ internal void CanNotAccessEndpointWithCustomerAuthedClient()
/// <param name="page">The page number of the paginated result.</param>
/// <param name="perPage">The page size of the paginated result.</param>
/// <returns>A paginated result.</returns>
internal async Task<OttPagination<OttCustomersEmbeddedData>> ListCustomersAsync(string? productId = null, string? email = null, string? query = null, string? sort = null, string? status = null, int page = 1, int perPage = 50)
internal async Task<OttPagination<OttCustomersEmbeddedData>> ListCustomersAsync(int? productId = null, string? email = null, string? query = null, string? sort = null, string? status = null, int page = 1, int perPage = 50)
{
this.CanNotAccessEndpointWithCustomerAuthedClient();
var route = $"{Endpoints.CUSTOMERS}";
Expand Down Expand Up @@ -102,7 +104,7 @@ internal async Task<OttPagination<OttCustomersEmbeddedData>> ListCustomersAsync(
/// <param name="customerId">The <c>id</c> of the customer being retrieved.</param>
/// <param name="productId">The <c>id</c> of a product.</param>
/// <returns>The requested customer.</returns>
internal async Task<OttCustomer<OttCustomerProductEmbeddedData>> RetrieveCustomerAsync(int customerId, int? productId = null)
internal async Task<OttCustomer<OttCustomerProductEmbeddedData>?> RetrieveCustomerAsync(int customerId, int? productId = null)
{
var route = $"{Endpoints.CUSTOMERS}/:customer_id";
var bucket = this.RestClient.GetBucket(RestRequestMethod.GET, route, new
Expand All @@ -113,6 +115,9 @@ internal async Task<OttCustomer<OttCustomerProductEmbeddedData>> RetrieveCustome
if (productId is not null)
url = url.AddParameter("product", $"{Utilities.GetApiBaseUri()}{Endpoints.PRODUCTS}/{productId}");
var res = await this.DoRequestAsync(bucket, url, RestRequestMethod.GET, route).ConfigureAwait(false);
if (res.ResponseCode == HttpStatusCode.NotFound)
return null;

var obj = JsonConvert.DeserializeObject<OttCustomer<OttCustomerProductEmbeddedData>>(res.Response)!;
obj.Client = this.Client;
foreach (var product in obj.Embedded.Products)
Expand Down Expand Up @@ -203,7 +208,7 @@ internal async Task<OttPagination<OttProductsEmbeddedData>> ListProductsAsync(st
/// </summary>
/// <param name="productId">The <c>id</c> of the product being retrieved.</param>
/// <returns>The requested product.</returns>
internal async Task<OttProduct<OttProductEmbeddedData>> RetrieveProductAsync(int productId)
internal async Task<OttProduct<OttProductEmbeddedData>?> RetrieveProductAsync(int productId)
{
var route = $"{Endpoints.PRODUCTS}/:product_id";
var bucket = this.RestClient.GetBucket(RestRequestMethod.GET, route, new
Expand All @@ -212,6 +217,9 @@ internal async Task<OttProduct<OttProductEmbeddedData>> RetrieveProductAsync(int
}, out var path);
var url = Utilities.GetApiUriFor(path);
var res = await this.DoRequestAsync(bucket, url, RestRequestMethod.GET, route).ConfigureAwait(false);
if (res.ResponseCode == HttpStatusCode.NotFound)
return null;

var obj = JsonConvert.DeserializeObject<OttProduct<OttProductEmbeddedData>>(res.Response)!;
obj.Client = this.Client;
return obj;
Expand Down
6 changes: 3 additions & 3 deletions AITSYS.Vimeo.Ott/Clients/VimeoOttClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ public VimeoOttClient(VimeoOttConfiguration configuration)
internal VimeoOttApiClient ApiClient { get; }

/// <inheritdoc cref="VimeoOttApiClient.ListCustomersAsync" />
public async Task<OttPagination<OttCustomersEmbeddedData>> ListCustomersAsync(string? productId = null, string? email = null, string? query = null, string? sort = null, string? status = null, int page = 1, int perPage = 50)
public async Task<OttPagination<OttCustomersEmbeddedData>> ListCustomersAsync(int? productId = null, string? email = null, string? query = null, string? sort = null, string? status = null, int page = 1, int perPage = 50)
=> await this.ApiClient.ListCustomersAsync(productId, email, query, sort, status, page, perPage);

/// <inheritdoc cref="VimeoOttApiClient.RetrieveCustomerAsync" />
public async Task<OttCustomer<OttCustomerProductEmbeddedData>> RetrieveCustomerAsync(int customerId, int? productId = null)
public async Task<OttCustomer<OttCustomerProductEmbeddedData>?> RetrieveCustomerAsync(int customerId, int? productId = null)
=> await this.ApiClient.RetrieveCustomerAsync(customerId, productId);

/// <inheritdoc cref="VimeoOttApiClient.ListProductsAsync" />
public async Task<OttPagination<OttProductsEmbeddedData>> ListProductsAsync(string? query = null, bool? active = null, string? sort = null, int page = 1, int perPage = 50)
=> await this.ApiClient.ListProductsAsync(query, active, sort, page, perPage);

/// <inheritdoc cref="VimeoOttApiClient.RetrieveProductAsync" />
public async Task<OttProduct<OttProductEmbeddedData>> RetrieveProductAsync(int productId)
public async Task<OttProduct<OttProductEmbeddedData>?> RetrieveProductAsync(int productId)
=> await this.ApiClient.RetrieveProductAsync(productId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ namespace AITSYS.Vimeo.Ott.Entities.EmbeddedData;
public sealed class OttWebhookEmbeddedData : IOttEmbedded
{
[JsonProperty("customer", NullValueHandling = NullValueHandling.Ignore)]
public OttCustomer<OttCustomerProductEmbeddedData> Customer { get; internal set; } = [];
public OttCustomer<OttCustomerProductEmbeddedData> Customer { get; internal set; }
}

0 comments on commit cc5acb0

Please sign in to comment.