Skip to content

Commit 1bf197a

Browse files
author
Ashley Medway
committed
Add contacts to contact list
1 parent 93979ba commit 1bf197a

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

MailJet.Client.Tests/ContactListTests.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using MailJet.Client.Response.Data;
1+
using MailJet.Client.Enum;
2+
using MailJet.Client.Request;
3+
using MailJet.Client.Response.Data;
24
using NUnit.Framework;
35
using System;
46
using System.Linq;
@@ -32,6 +34,38 @@ public void Setup()
3234
_client = new MailJetClient(publicKey, privateKey);
3335
}
3436

37+
[Test]
38+
public void CreateContactForList()
39+
{
40+
if (_testId == -1)
41+
{
42+
var all = _client.GetAllContactLists();
43+
var item = all.Data.Where(x => x.Name.StartsWith("Test")).FirstOrDefault();
44+
if (item == null)
45+
{
46+
Assert.Fail("Could not find a test item to test this method");
47+
}
48+
49+
_testId = item.ID;
50+
_testAddress = item.Address;
51+
}
52+
string email = String.Format("test_{0}@mailjet.net", Guid.NewGuid());
53+
const string name = "TEST CONTACT";
54+
var contact = new Contact()
55+
{
56+
Action = CreateContactAction.addnoforce,
57+
Email = email,
58+
Name = name
59+
};
60+
61+
contact.AddProperty("SomeInfo", "TestProperty");
62+
63+
var result = _client.CreateContactForList(_testId, contact);
64+
var resultItem = result.Data.Single();
65+
Assert.AreEqual(email, resultItem.Email);
66+
Assert.AreEqual(name, resultItem.Name);
67+
}
68+
3569
[Test]
3670
public void CreateContactList()
3771
{

MailJetClient/MailJet.Client.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<Compile Include="Properties\AssemblyInfo.cs" />
4444
<Compile Include="MailJetClient.cs" />
4545
<Compile Include="Request\Contact.cs" />
46+
<Compile Include="Response\Data\ContactData.cs" />
4647
<Compile Include="Response\Data\ContactListData.cs" />
4748
<Compile Include="Response\Data\DataItem.cs" />
4849
<Compile Include="Response\Data\MessageHistoryData.cs" />

MailJetClient/MailJetClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void DeleteContactList(long ID)
6262
request.AddParameter("id", ID, ParameterType.UrlSegment);
6363
}
6464

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

74-
return ExecuteRequest<ContactListData>(request);
74+
return ExecuteRequest<ContactData>(request);
7575
}
7676

7777
public Response<DataItem> SendMessage(MailMessage Message)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using MailJet.Client.Enum;
2+
using System.Collections.Generic;
3+
4+
namespace MailJet.Client.Response.Data
5+
{
6+
public class ContactData : DataItem
7+
{
8+
public string Email { get; set; }
9+
public string Name { get; set; }
10+
public CreateContactAction Action { get; set; }
11+
public Dictionary<string, string> Properties { get; set; }
12+
13+
}
14+
}

0 commit comments

Comments
 (0)