Skip to content

Commit 3fa0b3b

Browse files
committed
feat: add Deal/GetByName
1 parent ad0e48a commit 3fa0b3b

File tree

6 files changed

+94
-1
lines changed

6 files changed

+94
-1
lines changed

src/Pipedrive.net.Tests.Integration/Clients/DealsClientTests.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,27 @@ public async Task ReturnsDistinctInfosBasedOnStartPage()
6666
}
6767
}
6868

69+
public class TheGetByNameMethod
70+
{
71+
[IntegrationTest]
72+
public async Task CanRetrieveDeals()
73+
{
74+
var pipedrive = Helper.GetAuthenticatedClient();
75+
76+
var deals = await pipedrive.Deal.GetByName("mon deal");
77+
78+
Assert.Equal(1, deals.Count);
79+
}
80+
}
81+
6982
public class TheGetMethod
7083
{
7184
[IntegrationTest]
7285
public async Task CanRetrieveDeal()
7386
{
7487
var pipedrive = Helper.GetAuthenticatedClient();
7588

76-
var deal = await pipedrive.Deal.Get(1);
89+
var deal = await pipedrive.Deal.Get(135);
7790

7891
Assert.True(deal.Active);
7992
}

src/Pipedrive.net.Tests/Clients/DealsClientTests.cs

+19
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ await connection.GetAll<Deal>(
135135
}
136136
}
137137

138+
public class TheGetByNameMethod
139+
{
140+
[Fact]
141+
public async Task RequestsCorrectUrl()
142+
{
143+
var connection = Substitute.For<IApiConnection>();
144+
var client = new DealsClient(connection);
145+
146+
await client.GetByName("name");
147+
148+
Received.InOrder(async () =>
149+
{
150+
await connection.GetAll<SimpleDeal>(Arg.Is<Uri>(u => u.ToString() == "deals/find"),
151+
Arg.Is<Dictionary<string, string>>(d => d.Count == 1
152+
&& d["term"] == "name"));
153+
});
154+
}
155+
}
156+
138157
public class TheGetMethod
139158
{
140159
[Fact]

src/Pipedrive.net/Clients/DealsClient.cs

+8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ public Task<IReadOnlyList<Deal>> GetAllForUserId(int userId, DealFilters filters
6767
return ApiConnection.GetAll<Deal>(ApiUrls.Deals(), parameters, options);
6868
}
6969

70+
public Task<IReadOnlyList<SimpleDeal>> GetByName(string name)
71+
{
72+
var parameters = new Dictionary<string, string>();
73+
parameters.Add("term", name);
74+
75+
return ApiConnection.GetAll<SimpleDeal>(ApiUrls.DealsFind(), parameters);
76+
}
77+
7078
public Task<Deal> Get(long id)
7179
{
7280
return ApiConnection.Get<Deal>(ApiUrls.Deal(id));

src/Pipedrive.net/Clients/IDealsClient.cs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public interface IDealsClient
1616

1717
Task<IReadOnlyList<Deal>> GetAllForUserId(int userId, DealFilters filters);
1818

19+
Task<IReadOnlyList<SimpleDeal>> GetByName(string name);
20+
1921
Task<Deal> Get(long id);
2022

2123
Task<Deal> Create(NewDeal data);

src/Pipedrive.net/Helpers/ApiUrls.cs

+9
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ public static Uri Deals()
9696
return _dealsUrl;
9797
}
9898

99+
/// <summary>
100+
/// return the <see cref="Uri"/> that return all the finded deals.
101+
/// </summary>
102+
/// <returns></returns>
103+
public static Uri DealsFind()
104+
{
105+
return new Uri("deals/find", UriKind.Relative);
106+
}
107+
99108
/// <summary>
100109
/// Returns the <see cref="Uri"/> for the specified deal.
101110
/// </summary>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Pipedrive
4+
{
5+
public class SimpleDeal
6+
{
7+
public long Id { get; set; }
8+
9+
[JsonProperty("title")]
10+
public string Title { get; set; }
11+
12+
[JsonProperty("user_id")]
13+
public long UserId { get; set; }
14+
15+
[JsonProperty("visible_to")]
16+
public Visibility VisibleTo { get; set; }
17+
18+
[JsonProperty("status")]
19+
public DealStatus Status { get; set; }
20+
21+
[JsonProperty("value")]
22+
public long Value { get; set; }
23+
24+
[JsonProperty("currency")]
25+
public string Currency { get; set; }
26+
27+
[JsonProperty("person_name")]
28+
public string PersonName { get; set; }
29+
30+
[JsonProperty("person_id")]
31+
public long? PersonId { get; set; }
32+
33+
[JsonProperty("organization_name")]
34+
public string OrganizationName { get; set; }
35+
36+
[JsonProperty("organization_id")]
37+
public long? OrganizationId { get; set; }
38+
39+
[JsonProperty("formatted_value")]
40+
public string FormattedValue { get; set; }
41+
}
42+
}

0 commit comments

Comments
 (0)