Skip to content

Commit

Permalink
feat: add Deal/GetByName
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidRouyer committed Oct 5, 2018
1 parent ad0e48a commit 3fa0b3b
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Pipedrive.net.Tests.Integration/Clients/DealsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,27 @@ public async Task ReturnsDistinctInfosBasedOnStartPage()
}
}

public class TheGetByNameMethod
{
[IntegrationTest]
public async Task CanRetrieveDeals()
{
var pipedrive = Helper.GetAuthenticatedClient();

var deals = await pipedrive.Deal.GetByName("mon deal");

Assert.Equal(1, deals.Count);
}
}

public class TheGetMethod
{
[IntegrationTest]
public async Task CanRetrieveDeal()
{
var pipedrive = Helper.GetAuthenticatedClient();

var deal = await pipedrive.Deal.Get(1);
var deal = await pipedrive.Deal.Get(135);

Assert.True(deal.Active);
}
Expand Down
19 changes: 19 additions & 0 deletions src/Pipedrive.net.Tests/Clients/DealsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,25 @@ await connection.GetAll<Deal>(
}
}

public class TheGetByNameMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new DealsClient(connection);

await client.GetByName("name");

Received.InOrder(async () =>
{
await connection.GetAll<SimpleDeal>(Arg.Is<Uri>(u => u.ToString() == "deals/find"),
Arg.Is<Dictionary<string, string>>(d => d.Count == 1
&& d["term"] == "name"));
});
}
}

public class TheGetMethod
{
[Fact]
Expand Down
8 changes: 8 additions & 0 deletions src/Pipedrive.net/Clients/DealsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public Task<IReadOnlyList<Deal>> GetAllForUserId(int userId, DealFilters filters
return ApiConnection.GetAll<Deal>(ApiUrls.Deals(), parameters, options);
}

public Task<IReadOnlyList<SimpleDeal>> GetByName(string name)
{
var parameters = new Dictionary<string, string>();
parameters.Add("term", name);

return ApiConnection.GetAll<SimpleDeal>(ApiUrls.DealsFind(), parameters);
}

public Task<Deal> Get(long id)
{
return ApiConnection.Get<Deal>(ApiUrls.Deal(id));
Expand Down
2 changes: 2 additions & 0 deletions src/Pipedrive.net/Clients/IDealsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public interface IDealsClient

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

Task<IReadOnlyList<SimpleDeal>> GetByName(string name);

Task<Deal> Get(long id);

Task<Deal> Create(NewDeal data);
Expand Down
9 changes: 9 additions & 0 deletions src/Pipedrive.net/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ public static Uri Deals()
return _dealsUrl;
}

/// <summary>
/// return the <see cref="Uri"/> that return all the finded deals.
/// </summary>
/// <returns></returns>
public static Uri DealsFind()
{
return new Uri("deals/find", UriKind.Relative);
}

/// <summary>
/// Returns the <see cref="Uri"/> for the specified deal.
/// </summary>
Expand Down
42 changes: 42 additions & 0 deletions src/Pipedrive.net/Models/Response/SimpleDeal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Newtonsoft.Json;

namespace Pipedrive
{
public class SimpleDeal
{
public long Id { get; set; }

[JsonProperty("title")]
public string Title { get; set; }

[JsonProperty("user_id")]
public long UserId { get; set; }

[JsonProperty("visible_to")]
public Visibility VisibleTo { get; set; }

[JsonProperty("status")]
public DealStatus Status { get; set; }

[JsonProperty("value")]
public long Value { get; set; }

[JsonProperty("currency")]
public string Currency { get; set; }

[JsonProperty("person_name")]
public string PersonName { get; set; }

[JsonProperty("person_id")]
public long? PersonId { get; set; }

[JsonProperty("organization_name")]
public string OrganizationName { get; set; }

[JsonProperty("organization_id")]
public long? OrganizationId { get; set; }

[JsonProperty("formatted_value")]
public string FormattedValue { get; set; }
}
}

0 comments on commit 3fa0b3b

Please sign in to comment.