Skip to content

Commit

Permalink
Add contacts to contact list
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley Medway committed Mar 7, 2016
1 parent 93979ba commit 1bf197a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
36 changes: 35 additions & 1 deletion MailJet.Client.Tests/ContactListTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using MailJet.Client.Response.Data;
using MailJet.Client.Enum;
using MailJet.Client.Request;
using MailJet.Client.Response.Data;
using NUnit.Framework;
using System;
using System.Linq;
Expand Down Expand Up @@ -32,6 +34,38 @@ public void Setup()
_client = new MailJetClient(publicKey, privateKey);
}

[Test]
public void CreateContactForList()
{
if (_testId == -1)
{
var all = _client.GetAllContactLists();
var item = all.Data.Where(x => x.Name.StartsWith("Test")).FirstOrDefault();
if (item == null)
{
Assert.Fail("Could not find a test item to test this method");
}

_testId = item.ID;
_testAddress = item.Address;
}
string email = String.Format("test_{0}@mailjet.net", Guid.NewGuid());
const string name = "TEST CONTACT";
var contact = new Contact()
{
Action = CreateContactAction.addnoforce,
Email = email,
Name = name
};

contact.AddProperty("SomeInfo", "TestProperty");

var result = _client.CreateContactForList(_testId, contact);
var resultItem = result.Data.Single();
Assert.AreEqual(email, resultItem.Email);
Assert.AreEqual(name, resultItem.Name);
}

[Test]
public void CreateContactList()
{
Expand Down
1 change: 1 addition & 0 deletions MailJetClient/MailJet.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="MailJetClient.cs" />
<Compile Include="Request\Contact.cs" />
<Compile Include="Response\Data\ContactData.cs" />
<Compile Include="Response\Data\ContactListData.cs" />
<Compile Include="Response\Data\DataItem.cs" />
<Compile Include="Response\Data\MessageHistoryData.cs" />
Expand Down
4 changes: 2 additions & 2 deletions MailJetClient/MailJetClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void DeleteContactList(long ID)
request.AddParameter("id", ID, ParameterType.UrlSegment);
}

public Response<ContactListData> CreateContactForList(long ID, Contact contact)
public Response<ContactData> CreateContactForList(long ID, Contact contact)
{
var request = new RestRequest("REST/contactslist/{id}/managecontact", Method.POST);
request.AddParameter("id", ID, ParameterType.UrlSegment);
Expand All @@ -71,7 +71,7 @@ public Response<ContactListData> CreateContactForList(long ID, Contact contact)
request.AddParameter("properties", contact.Properties, ParameterType.GetOrPost);
request.AddParameter("action", System.Enum.GetName(typeof(CreateContactAction), contact.Action), ParameterType.GetOrPost);

return ExecuteRequest<ContactListData>(request);
return ExecuteRequest<ContactData>(request);
}

public Response<DataItem> SendMessage(MailMessage Message)
Expand Down
14 changes: 14 additions & 0 deletions MailJetClient/Response/Data/ContactData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using MailJet.Client.Enum;
using System.Collections.Generic;

namespace MailJet.Client.Response.Data
{
public class ContactData : DataItem
{
public string Email { get; set; }
public string Name { get; set; }
public CreateContactAction Action { get; set; }
public Dictionary<string, string> Properties { get; set; }

}
}

0 comments on commit 1bf197a

Please sign in to comment.