-
Notifications
You must be signed in to change notification settings - Fork 2
Use the Tasks API to associate tasks with CRM records. #1
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,4 +52,4 @@ public async void SearchAsync_ByName_Succeeds() | |
|
|
||
| page.Results.Should().NotBeEmpty(); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| using System.Net; | ||
| using FluentAssertions; | ||
| using HubSpot.Api.Exceptions; | ||
| using HubSpot.Api.Models; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace HubSpot.Api.Test.Crm; | ||
|
|
||
| public class TaskTests(ITestOutputHelper testOutputHelper) : TestBase(testOutputHelper) | ||
| { | ||
| [Fact] | ||
| public async void CreateReadUpdateAndDelete_Succeeds() | ||
| { | ||
| var createRequest = new CreateRequest | ||
| { | ||
| Properties = new Dictionary<string, string> | ||
| { | ||
| { "hs_timestamp", "2019-10-30T03:30:17.883Z" }, | ||
| { "hs_task_body", """ | ||
| <h3>Send Proposal</h3> | ||
| <a href="https://example.com">Example</a> | ||
| """ }, | ||
| { "hs_task_subject", "Follow-up for Brian Buyer" }, | ||
| { "hs_task_status", "NOT_STARTED" }, | ||
| { "hs_task_priority", "HIGH" }, | ||
| { "hs_task_type", "TODO" } | ||
| }, | ||
| Associations = [] | ||
| }; | ||
|
|
||
| HubSpotObject createdObject; | ||
| try | ||
| { | ||
| createdObject = await Client.Crm.Tasks.CreateAsync(createRequest); | ||
| createdObject.Should().NotBeNull(); | ||
| } | ||
| catch (HubSpotApiErrorException e) when (e.StatusCode == HttpStatusCode.Conflict) | ||
| { | ||
| e.Error.Category.Should().Be(ErrorCategory.Conflict); | ||
| createdObject = new HubSpotObject | ||
| { | ||
| Id = e.Message.Split(' ').Last(), | ||
| Properties = createRequest.Properties, | ||
| Archived = false, | ||
| CreatedAt = DateTime.UtcNow, | ||
| UpdatedAt = DateTime.UtcNow | ||
| }; | ||
| } | ||
|
|
||
| // Re-read the item | ||
| var readObject = await Client.Crm.Tasks.GetAsync(createdObject.Id); | ||
| readObject.Should().NotBeNull(); | ||
| readObject.Id.Should().Be(createdObject.Id); | ||
| readObject.Properties.Should().NotBeEmpty(); | ||
|
|
||
| // Delete the item | ||
| await Client | ||
| .Crm | ||
| .Tasks | ||
| .ArchiveAsync(createdObject.Id); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,55 @@ | ||||||||||
| using HubSpot.Api.Models; | ||||||||||
| using Refit; | ||||||||||
|
|
||||||||||
| namespace HubSpot.Api.Interfaces.Crm; | ||||||||||
|
|
||||||||||
| public interface ITasks | ||||||||||
| { | ||||||||||
| // https://developers.hubspot.com/docs/guides/api/crm/engagements/tasks | ||||||||||
|
|
||||||||||
| [Post("/crm/v3/objects/tasks")] | ||||||||||
| Task<HubSpotObject> CreateAsync( | ||||||||||
| [Body] CreateRequest createRequest, | ||||||||||
| CancellationToken cancellationToken = default | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Codacy found a critical ErrorProne issue: Use the overloading mechanism instead of the optional parameters. The issue identified by the SonarC# linter is that using optional parameters, such as To fix this issue, you can create an overloaded version of the
Suggested change
This comment was generated by an experimental AI tool. |
||||||||||
| ); | ||||||||||
|
|
||||||||||
| [Get("/crm/v3/objects/tasks/{id}")] | ||||||||||
| Task<HubSpotObject> GetAsync( | ||||||||||
| string id, | ||||||||||
| [Query] IReadOnlyList<string>? properties = null, | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Codacy found a critical ErrorProne issue: Use the overloading mechanism instead of the optional parameters. The issue identified by the SonarC# linter suggests that using optional parameters can lead to ambiguity and may hinder method overloading. Instead of using optional parameters, it is recommended to create overloaded methods that provide distinct signatures for different scenarios. This enhances clarity and makes the API more intuitive. To address this issue, we can create an overloaded version of the Here is the suggested change:
Suggested change
This comment was generated by an experimental AI tool. |
||||||||||
| [Query] IReadOnlyList<string>? propertiesWithHistory = null, | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Codacy found a critical ErrorProne issue: Use the overloading mechanism instead of the optional parameters. The issue identified by the SonarC# linter is that using optional parameters can lead to ambiguity and can complicate method overloading. Instead of defining parameters as optional (with a default value of To address the issue, you can remove the optional parameter and create an overloaded version of the Here’s the single-line code suggestion to fix the issue by removing the optional parameter:
Suggested change
You would then create a new overload for the method that includes the
Suggested change
This way, you can call the appropriate version of the method based on the parameters needed, avoiding the use of optional parameters. This comment was generated by an experimental AI tool. |
||||||||||
| [Query] IReadOnlyList<string>? associations = null, | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Codacy found a critical ErrorProne issue: Use the overloading mechanism instead of the optional parameters. The issue highlighted by the SonarC# linter indicates that using optional parameters can lead to ambiguity and can complicate the method signature. Instead of using an optional parameter for To fix this issue, we can create an overloaded version of the Here’s the suggested code change:
Suggested change
This change involves creating a new overload of the This comment was generated by an experimental AI tool. |
||||||||||
| [Query] bool? archived = null, | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Codacy found a critical ErrorProne issue: Use the overloading mechanism instead of the optional parameters. The issue identified by the SonarC# linter is related to the use of optional parameters in the method signature. The linter suggests that instead of using optional parameters, you should use method overloading to provide different method signatures. This can improve clarity and usability by allowing callers to specify only the parameters they need without ambiguity. To fix this issue, you can create an overloaded version of the Here's the code suggestion to implement this change:
Suggested change
This comment was generated by an experimental AI tool. |
||||||||||
| CancellationToken cancellationToken = default | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| [Patch("/crm/v3/objects/tasks/{id}")] | ||||||||||
| Task<HubSpotObject> PatchAsync( | ||||||||||
| string id, | ||||||||||
| [Body] HubSpotPatchObject hubSpotObject, | ||||||||||
| CancellationToken cancellationToken = default | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| [Get("/crm/v3/objects/tasks")] | ||||||||||
| Task<CrmPage> GetPageAsync( | ||||||||||
| int? limit = null, | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Codacy found a critical ErrorProne issue: Use the overloading mechanism instead of the optional parameters. The issue identified by the SonarC# linter is that the use of optional parameters (like To fix the issue, we can provide an overloaded version of the Here's the code suggestion to implement this change:
Suggested change
This line adds an overload of the This comment was generated by an experimental AI tool. |
||||||||||
| string? after = null, | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Codacy found a critical ErrorProne issue: Use the overloading mechanism instead of the optional parameters. The issue identified by the SonarC# linter suggests that instead of using optional parameters (like To resolve this issue, you can create an overloaded version of the Here’s the suggested change:
Suggested change
This comment was generated by an experimental AI tool. |
||||||||||
| ICollection<string>? properties = null, | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Codacy found a critical ErrorProne issue: Use the overloading mechanism instead of the optional parameters. The issue identified by the SonarC# linter is that optional parameters can lead to ambiguity in method overloads, especially when there are multiple optional parameters of the same type. Instead of using optional parameters, the linter suggests using method overloading to provide clearer and more maintainable code. To fix the issue, we can create an overloaded version of the Here's the suggested change:
Suggested change
This change involves creating an overload that omits the This comment was generated by an experimental AI tool. |
||||||||||
| ICollection<string>? propertiesWithHistory = null, | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Codacy found a critical ErrorProne issue: Use the overloading mechanism instead of the optional parameters. The issue identified by the SonarC# linter suggests that using optional parameters can lead to ambiguity and can make the method signature less clear. Instead of using optional parameters, it recommends using method overloading to provide different variations of the method for different use cases. This can improve code readability and maintainability. To address this, we can create an overloaded method that omits the
Suggested change
This change removes the optional parameter This comment was generated by an experimental AI tool. |
||||||||||
| ICollection<string>? associations = null, | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Codacy found a critical ErrorProne issue: Use the overloading mechanism instead of the optional parameters. The issue identified by the SonarC# linter suggests that instead of using optional parameters in the method signature, you should consider using method overloading. This is because optional parameters can lead to ambiguity and make the API less clear, especially when there are multiple optional parameters. To resolve the issue, you can create an overloaded version of the Here's the suggested change:
Suggested change
This change creates a new method overload without the This comment was generated by an experimental AI tool. |
||||||||||
| bool? archived = null, | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ Codacy found a critical ErrorProne issue: Use the overloading mechanism instead of the optional parameters. The issue identified by the SonarC# linter is that optional parameters can lead to ambiguity and may complicate method overloading and usage. Instead of using optional parameters, it's recommended to create overloaded versions of the method to handle different scenarios. This can improve code clarity and maintainability. To fix the issue, we can create an overloaded version of the Here's the code suggestion to implement this change:
Suggested change
This comment was generated by an experimental AI tool. |
||||||||||
| CancellationToken cancellationToken = default | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| [Delete("/crm/v3/objects/tasks/{id}")] | ||||||||||
| Task ArchiveAsync( | ||||||||||
| string id, | ||||||||||
| CancellationToken cancellationToken = default | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| [Post("/crm/v3/objects/tasks/search")] | ||||||||||
| Task<CrmPage> SearchAsync( | ||||||||||
| [Body] SearchRequest searchRequest, | ||||||||||
| CancellationToken cancellationToken = default | ||||||||||
| ); | ||||||||||
| } | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue identified by the SonarC# linter is that the method
CreateReadUpdateAndDelete_Succeedsis defined with a return type ofasync void. This is generally discouraged in asynchronous programming because it can lead to unhandled exceptions and makes it difficult to await the completion of the method. Instead, asynchronous methods should return aTask, which allows the calling code to await the method and handle exceptions properly.To fix this issue, you should change the return type from
async voidtoasync Task. Here's the code suggestion to implement this change:This comment was generated by an experimental AI tool.