Skip to content

Commit

Permalink
Merge pull request #1 from The-Poolz/implement_add-lead
Browse files Browse the repository at this point in the history
Implement `addLead`
  • Loading branch information
Lomet authored Mar 6, 2024
2 parents 57896b1 + 38deae7 commit d25df9f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/Pipedrive.net/Clients/ILeadsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ namespace Pipedrive
/// </summary>
/// <remarks>
/// See the <a href="https://developers.pipedrive.com/docs/api/v1/Leads">Lead API documentation</a> for more information.
/// </remarks>
public interface ILeadsClient
{
Task<IReadOnlyList<Lead>> GetAll(LeadFilters filters);

Task<Lead> Get(Guid id);

Task<LeadCreated> Create(NewLead data);
}
}
8 changes: 8 additions & 0 deletions src/Pipedrive.net/Clients/LeadsClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Pipedrive.Helpers;

namespace Pipedrive
Expand Down Expand Up @@ -39,5 +40,12 @@ public Task<Lead> Get(Guid id)
{
return ApiConnection.Get<Lead>(ApiUrls.Lead(id));
}

public Task<LeadCreated> Create(NewLead data)
{
Ensure.ArgumentNotNull(data, nameof(data));

return ApiConnection.Post<LeadCreated>(ApiUrls.Leads(), JObject.FromObject(data));
}
}
}
45 changes: 45 additions & 0 deletions src/Pipedrive.net/Models/Request/Leads/NewLead.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Pipedrive.Models.Response;

namespace Pipedrive
{
public class NewLead : IEntityWithCustomFields
{
[JsonProperty("title")]
public string Title { get; set; }

[JsonProperty("owner_id", NullValueHandling = NullValueHandling.Ignore)]
public long? OwnerId { get; set; }

[JsonProperty("label_ids", NullValueHandling = NullValueHandling.Ignore)]
public IEnumerable<Guid> LabelIds { get; set; }

[JsonProperty("person_id", NullValueHandling = NullValueHandling.Ignore)]
public long? PersonId { get; set; }

[JsonProperty("organization_id", NullValueHandling = NullValueHandling.Ignore)]
public long? OrganizationId { get; set; }

[JsonProperty("value", NullValueHandling = NullValueHandling.Ignore)]
public CurrencyAmount Value { get; set; }

[JsonProperty("expected_close_date", NullValueHandling = NullValueHandling.Ignore)]
public DateTime? ExpectedCloseDate { get; set; }

[JsonProperty("visible_to", NullValueHandling = NullValueHandling.Ignore)]
public Visibility? VisibleTo { get; set; }

[JsonProperty("was_seen", NullValueHandling = NullValueHandling.Ignore)]
public bool? WasSeen { get; set; }

[JsonIgnore]
public IDictionary<string, ICustomField> CustomFields { get; set; } = new Dictionary<string, ICustomField>();

public NewLead(string title)
{
this.Title = title;
}
}
}
26 changes: 15 additions & 11 deletions src/Pipedrive.net/Models/Response/Leads/AbstractLead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,26 @@ public abstract class AbstractLead
[JsonProperty("label_ids")]
public List<Guid> LabelIds { get; set; }

public CurrencyAmount Value { get; set; }

[JsonProperty("expected_close_date")]
public DateTime? ExpectedCloseDate { get; set; }

public string Note { get; set; }

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

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

[JsonProperty("is_archived")]
public bool IsArchived { get; set; }

[JsonProperty("source_name")]
public string SourceName { get; set; }

[JsonProperty("is_archived")]
public bool IsArchived { get; set; }

[JsonProperty("was_seen")]
public bool WasSeen { get; set; }

public CurrencyAmount Value { get; set; }

[JsonProperty("expected_close_date")]
public DateTime? ExpectedCloseDate { get; set; }

[JsonProperty("next_activity_id")]
public long? NextActivityId { get; set; }

Expand All @@ -50,5 +48,11 @@ public abstract class AbstractLead

[JsonProperty("update_time")]
public DateTime? UpdateTime { get; set; }

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

[JsonProperty("cc_email")]
public string CcEmail { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/Pipedrive.net/Models/Response/Leads/Lead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Pipedrive
[JsonConverter(typeof(CustomFieldConverter))]
public class Lead : AbstractLead, IEntityWithCustomFields
{
public string Note { get; set; }

[JsonIgnore]
public IDictionary<string, ICustomField> CustomFields { get; set; }
}
Expand Down
4 changes: 4 additions & 0 deletions src/Pipedrive.net/Models/Response/Leads/LeadCreated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Pipedrive
{
public class LeadCreated : AbstractLead { }
}

0 comments on commit d25df9f

Please sign in to comment.