Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement addLead #1

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { }
}