Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New endpoint for getting an owner by id #20

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions HubSpot.NET/Api/Owner/HubSpotOwnerApi.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System.Net;
using HubSpot.NET.Core;
using RestSharp;
using HubSpot.NET.Api.Owner.Dto;
using HubSpot.NET.Core.Extensions;
using HubSpot.NET.Core.Interfaces;

namespace HubSpot.NET.Api.Owner
{
using HubSpot.NET.Api.Owner.Dto;
using HubSpot.NET.Core.Extensions;
using HubSpot.NET.Core.Interfaces;

public class HubSpotOwnerApi : IHubSpotOwnerApi
{
Expand Down Expand Up @@ -32,5 +36,28 @@ public OwnerListHubSpotModel<T> GetAll<T>(OwnerGetAllRequestOptions opts = null)

return _client.ExecuteList<OwnerListHubSpotModel<T>>(path, convertToPropertiesSchema: false);
}

/// <summary>
/// Gets a single owner by ID
/// </summary>
/// <param name="ownerId">ID of the owner</param>
/// <typeparam name="T">Implementation of OwnerHubSpotModel</typeparam>
/// <returns>The owner entity or null if the owner does not exist</returns>
public T GetById<T>(long ownerId) where T: OwnerHubSpotModel, new()
{
var path = $"{new OwnerHubSpotModel().RouteBasePath}/owners/{ownerId}";

try
{
var data = _client.Execute<T>(path, Method.GET, convertToPropertiesSchema: true);
return data;
}
catch (HubSpotException exception)
{
if (exception.ReturnedError.StatusCode == HttpStatusCode.NotFound)
return null;
throw;
}
}
}
}
Loading