-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement Deal List * Added missing interface for ListAsync, fixed doc * Deal amount should be decimal not int
- Loading branch information
1 parent
c33954b
commit 3afb06e
Showing
11 changed files
with
255 additions
and
9 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
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,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Skarp.HubSpotClient.Deal | ||
{ | ||
public class DealListRequestOptions | ||
{ | ||
private int _numberOfDealsToReturn = 100; | ||
|
||
/// <summary> | ||
/// Gets or sets the number of deals to return. | ||
/// </summary> | ||
/// <remarks> | ||
/// Defaults to 20 which is also the hubspot api default. Max value is 100 | ||
/// </remarks> | ||
/// <value> | ||
/// The number of deals to return. | ||
/// </value> | ||
public int NumberOfDealsToReturn | ||
{ | ||
get => _numberOfDealsToReturn; | ||
set | ||
{ | ||
if (value < 1 || value > 250) | ||
{ | ||
throw new ArgumentException( | ||
$"Number of deals to return must be a positive integer greater than 0 and less than 251 - you provided {value}"); | ||
} | ||
_numberOfDealsToReturn = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Get or set the continuation offset when calling list many times to enumerate all your deals | ||
/// </summary> | ||
/// <remarks> | ||
/// The return DTO from List contains the current "offset" that you can inject into your next list call | ||
/// to continue the listing process | ||
/// </remarks> | ||
public long? DealOffset { get; set; } = null; | ||
|
||
public List<string> PropertiesToInclude { get; set; } = new List<string>(); | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Collections.Generic; | ||
using System.Runtime.Serialization; | ||
using Skarp.HubSpotClient.Deal.Interfaces; | ||
|
||
namespace Skarp.HubSpotClient.Deal.Dto | ||
{ | ||
[DataContract] | ||
public class DealListHubSpotEntity<T> : IDealListHubSpotEntity<T> where T : IDealHubSpotEntity | ||
{ | ||
/// <inheritdoc /> | ||
/// <summary> | ||
/// Gets or sets the deals. | ||
/// </summary> | ||
/// <value> | ||
/// The deals. | ||
/// </value> | ||
[DataMember(Name = "deals")] | ||
public IList<T> Deals { get; set; } = new List<T>(); | ||
|
||
/// <inheritdoc /> | ||
/// <summary> | ||
/// Gets or sets a value indicating whether more results are available. | ||
/// </summary> | ||
/// <value> | ||
/// <c>true</c> if [more results available]; otherwise, <c>false</c>. | ||
/// </value> | ||
/// <remarks> | ||
/// This is a mapping of the "hasMore" prop in the JSON return data from HubSpot | ||
/// </remarks> | ||
[DataMember(Name = "hasMore")] | ||
public bool MoreResultsAvailable { get; set; } | ||
|
||
/// <inheritdoc /> | ||
/// <summary> | ||
/// Gets or sets the continuation offset. | ||
/// </summary> | ||
/// <value> | ||
/// The continuation offset. | ||
/// </value> | ||
/// <remarks> | ||
/// This is a mapping of the "offset" prop in the JSON return data from HubSpot | ||
/// </remarks> | ||
[DataMember(Name = "offset")] | ||
public long ContinuationOffset { get; set; } | ||
|
||
public string RouteBasePath => "/deals/v1"; | ||
|
||
public bool IsNameValue => false; | ||
|
||
public List<string> PropertiesToInclude { get; set; } = new List<string>(); | ||
|
||
public virtual void ToHubSpotDataEntity(ref dynamic converted) | ||
{ | ||
|
||
} | ||
|
||
public virtual void FromHubSpotDataEntity(dynamic hubspotData) | ||
{ | ||
|
||
} | ||
} | ||
} |
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
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,42 @@ | ||
using System.Collections.Generic; | ||
using Skarp.HubSpotClient.Core.Interfaces; | ||
|
||
namespace Skarp.HubSpotClient.Deal.Interfaces | ||
{ | ||
public interface IDealListHubSpotEntity<T> : IHubSpotEntity where T : IDealHubSpotEntity | ||
{ | ||
/// <summary> | ||
/// Gets or sets the deals. | ||
/// </summary> | ||
/// <value> | ||
/// The deals. | ||
/// </value> | ||
IList<T> Deals { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether more results are available. | ||
/// </summary> | ||
/// <remarks> | ||
/// This is a mapping of the "hasMore" prop in the JSON return data from HubSpot | ||
/// </remarks> | ||
/// <value> | ||
/// <c>true</c> if [more results available]; otherwise, <c>false</c>. | ||
/// </value> | ||
bool MoreResultsAvailable { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the continuation offset. | ||
/// </summary> | ||
/// <remarks> | ||
/// This is a mapping of the "vid-offset" prop in the JSON reeturn data from HubSpot | ||
/// </remarks> | ||
/// <value> | ||
/// The continuation offset. | ||
/// </value> | ||
long ContinuationOffset { get; set; } | ||
|
||
string RouteBasePath { get; } | ||
|
||
List<string> PropertiesToInclude { 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
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,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using RapidCore.Network; | ||
using Skarp.HubSpotClient.Core.Requests; | ||
using Skarp.HubSpotClient.Deal; | ||
using Skarp.HubSpotClient.Deal.Dto; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace integration.Deal | ||
{ | ||
public class HubSpotDealClientIntegrationTest : IntegrationTestBase<HubSpotDealClient> | ||
{ | ||
private readonly HubSpotDealClient _client; | ||
private readonly string _apiKey; | ||
private readonly bool _isAppVeyorEnv; | ||
|
||
public HubSpotDealClientIntegrationTest(ITestOutputHelper output) : base(output) | ||
{ | ||
_apiKey = Environment.GetEnvironmentVariable("HUBSPOT_API_KEY") ?? "demo"; | ||
_isAppVeyorEnv = (Environment.GetEnvironmentVariable("APPVEYOR") ?? "false").Equals("true", StringComparison.InvariantCultureIgnoreCase); | ||
; _client = new HubSpotDealClient( | ||
new RealRapidHttpClient(new HttpClient()), | ||
base.Logger, | ||
new RequestSerializer(new RequestDataConverter(LoggerFactory.CreateLogger<RequestDataConverter>())), | ||
"https://api.hubapi.com", | ||
_apiKey | ||
); | ||
} | ||
|
||
[Fact] | ||
public async Task List() | ||
{ | ||
var deals = | ||
await _client.ListAsync<DealListHubSpotEntity<DealHubSpotEntity>>(new DealListRequestOptions | ||
{ | ||
PropertiesToInclude = new List<string> { "dealname", "amount" }, | ||
NumberOfDealsToReturn = 2 | ||
}); | ||
|
||
Assert.NotNull(deals); | ||
Assert.NotNull(deals.Deals); | ||
Assert.NotEmpty(deals.Deals); | ||
Assert.True(deals.Deals.Count > 1, "contacts.Deals.Count > 1"); | ||
} | ||
} | ||
} |
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