-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: GET /filters & GET /filters/{id}
- Loading branch information
1 parent
9a63371
commit 82d7cc0
Showing
11 changed files
with
254 additions
and
2 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
37 changes: 37 additions & 0 deletions
37
src/Pipedrive.net.Tests.Integration/Clients/FiltersClientTests.cs
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 @@ | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Pipedrive.Tests.Integration.Clients | ||
{ | ||
public class FiltersClientTests | ||
{ | ||
public class TheGetAllMethod | ||
{ | ||
[IntegrationTest] | ||
public async Task CanRetrieveFilters() | ||
{ | ||
var pipedrive = Helper.GetAuthenticatedClient(); | ||
|
||
var filters = await pipedrive.Filter.GetAll(FilterFilters.None); | ||
|
||
Assert.True(filters.Count >= 1); | ||
Assert.Equal("All open deals", filters[0].Name); | ||
Assert.True(filters[0].ActiveFlag); | ||
} | ||
} | ||
|
||
public class TheGetMethod | ||
{ | ||
[IntegrationTest] | ||
public async Task CanRetrieveFilter() | ||
{ | ||
var pipedrive = Helper.GetAuthenticatedClient(); | ||
|
||
var filter = await pipedrive.Filter.Get(1); | ||
|
||
Assert.True(filter.ActiveFlag); | ||
Assert.Equal("All open deals", filter.Name); | ||
} | ||
} | ||
} | ||
} |
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,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace Pipedrive.Tests.Clients | ||
{ | ||
public class FiltersClientTests | ||
{ | ||
public class TheCtor | ||
{ | ||
[Fact] | ||
public void EnsuresNonNullArguments() | ||
{ | ||
Assert.Throws<ArgumentNullException>(() => new FiltersClient(null)); | ||
} | ||
} | ||
|
||
public class TheGetAllMethod | ||
{ | ||
[Fact] | ||
public async Task RequestsCorrectUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new FiltersClient(connection); | ||
|
||
await client.GetAll(FilterFilters.None); | ||
|
||
Received.InOrder(async () => | ||
{ | ||
await connection.GetAll<Filter>(Arg.Is<Uri>(u => u.ToString() == "filters"), | ||
Arg.Is<Dictionary<string, string>>(d => d.Count == 0)); | ||
}); | ||
} | ||
} | ||
|
||
public class TheGetMethod | ||
{ | ||
[Fact] | ||
public async Task RequestsCorrectUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new FiltersClient(connection); | ||
|
||
await client.Get(123); | ||
|
||
Received.InOrder(async () => | ||
{ | ||
await connection.Get<Filter>(Arg.Is<Uri>(u => u.ToString() == "filters/123")); | ||
}); | ||
} | ||
} | ||
} | ||
} |
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,36 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Pipedrive.Helpers; | ||
|
||
namespace Pipedrive | ||
{ | ||
/// <summary> | ||
/// A client for Pipedrive's Filter API. | ||
/// </summary> | ||
/// <remarks> | ||
/// See the <a href="https://developers.pipedrive.com/docs/api/v1/Filters">Filter API documentation</a> for more information. | ||
public class FiltersClient : ApiClient, IFiltersClient | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FiltersClient"/> class. | ||
/// </summary> | ||
/// <param name="apiConnection">An API connection</param> | ||
public FiltersClient(IApiConnection apiConnection) : base(apiConnection) | ||
{ | ||
} | ||
|
||
public Task<IReadOnlyList<Filter>> GetAll(FilterFilters filters) | ||
{ | ||
Ensure.ArgumentNotNull(filters, nameof(filters)); | ||
|
||
var parameters = filters.Parameters; | ||
|
||
return ApiConnection.GetAll<Filter>(ApiUrls.Filters(), parameters); | ||
} | ||
|
||
public Task<Filter> Get(long id) | ||
{ | ||
return ApiConnection.Get<Filter>(ApiUrls.Filter(id)); | ||
} | ||
} | ||
} |
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,17 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Pipedrive | ||
{ | ||
/// <summary> | ||
/// A client for Pipedrive's Filter API. | ||
/// </summary> | ||
/// <remarks> | ||
/// See the <a href="https://developers.pipedrive.com/docs/api/v1/Filters">Filter API documentation</a> for more information. | ||
public interface IFiltersClient | ||
{ | ||
Task<IReadOnlyList<Filter>> GetAll(FilterFilters filters); | ||
|
||
Task<Filter> Get(long id); | ||
} | ||
} |
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,11 @@ | ||
namespace Pipedrive | ||
{ | ||
public enum FilterType | ||
{ | ||
deals, | ||
org, | ||
people, | ||
products, | ||
activity | ||
} | ||
} |
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,31 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Pipedrive | ||
{ | ||
public class FilterFilters | ||
{ | ||
public static FilterFilters None | ||
{ | ||
get { return new FilterFilters(); } | ||
} | ||
|
||
public FilterType? Type { get; set; } | ||
|
||
/// <summary> | ||
/// Get the query parameters that will be appending onto the search | ||
/// </summary> | ||
public IDictionary<string, string> Parameters | ||
{ | ||
get | ||
{ | ||
var d = new Dictionary<string, string>(); | ||
if (Type.HasValue) | ||
{ | ||
d.Add("type", Type.Value.ToString()); | ||
} | ||
|
||
return d; | ||
} | ||
} | ||
} | ||
} |
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,35 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace Pipedrive | ||
{ | ||
public class Filter | ||
{ | ||
public long Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
[JsonProperty("active_flag")] | ||
public bool ActiveFlag { get; set; } | ||
|
||
public string Type { get; set; } | ||
|
||
[JsonProperty("temporary_flag")] | ||
public string TemporaryFlag { get; set; } | ||
|
||
[JsonProperty("user_id")] | ||
public long UserId { get; set; } | ||
|
||
[JsonProperty("add_time")] | ||
public DateTime AddTime { get; set; } | ||
|
||
[JsonProperty("update_time")] | ||
public DateTime? UpdateTime { get; set; } | ||
|
||
[JsonProperty("visible_to")] | ||
public long VisibleTo { get; set; } | ||
|
||
[JsonProperty("custom_view_id")] | ||
public long? CustomViewId { 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