Skip to content

Commit

Permalink
Merge pull request sdesyllas#3 from sdesyllas/MCNET_DoubleOptIn
Browse files Browse the repository at this point in the history
Double Opt In added on subscribe methods
  • Loading branch information
sdesyllas committed Oct 8, 2013
2 parents b653c11 + 568ed11 commit e857557
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion MailChimp.Net.Api/Domain/Subscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Subscriber : MailChimpItem

[JsonProperty("update_existing")]
public bool UpdateExisting { get; set; }

[JsonProperty("id")]
public string ListId { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions MailChimp.Net.Api/IMailChimpApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public interface IMailChimpApiService
{
ServiceResponse PingMailChimpServer();

ServiceResponse Subscribe(string email);
ServiceResponse Subscribe(string email, bool enableDoubleOptIn);

ServiceResponse Subscribe(string email, List<Grouping> groupings, Dictionary<string, string> field);
ServiceResponse Subscribe(string email, List<Grouping> groupings, Dictionary<string, string> field, bool enableDoubleOptIn);

ServiceResponse Unsubscribe(string email);
}
Expand Down
12 changes: 6 additions & 6 deletions MailChimp.Net.Api/MailChimpApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@ public ServiceResponse PingMailChimpServer()
return serviceResponse;
}

public ServiceResponse Subscribe(string email)
public ServiceResponse Subscribe(string email, bool doubleOptIn)
{
var res = Subscribe(email, null, null);
var res = Subscribe(email, null, null, doubleOptIn);
return res;
}


private ServiceResponse SubscribeWithMergeVars(string email, dynamic mergeVars)
private ServiceResponse SubscribeWithMergeVars(string email, dynamic mergeVars, bool enableDoubleOptIn)
{
ServiceResponse serviceResponse = new ServiceResponse();
var urlTemplate = String.Format("{0}{1}/subscribe.json/", MailChimpServiceConfiguration.Settings.ServiceUrl,
MailChimpServiceConfiguration.Settings.ListsRelatedSection);

var subscriber = new Subscriber();

subscriber.DoubleOptIn = enableDoubleOptIn;
subscriber.ApiKey = _apiKey;
subscriber.ListId = MailChimpServiceConfiguration.Settings.SubscriberListId;
var emailObject = new Email { EmailValue = email };
Expand Down Expand Up @@ -109,7 +109,7 @@ private ServiceResponse SubscribeWithMergeVars(string email, dynamic mergeVars)
return serviceResponse;
}

public ServiceResponse Subscribe(string email, List<Grouping> groupings, Dictionary<string, string> fields)
public ServiceResponse Subscribe(string email, List<Grouping> groupings, Dictionary<string, string> fields, bool enableDoubleOptIn)
{
dynamic mergeVars = new Dictionary<string, Object>();
mergeVars.Add("groupings", groupings);
Expand All @@ -120,7 +120,7 @@ public ServiceResponse Subscribe(string email, List<Grouping> groupings, Diction
//http://stackoverflow.com/questions/4938397/dynamically-adding-properties-to-an-expandoobject
mergeVars.Add(nameValue.Key, nameValue.Value);
}
var response = this.SubscribeWithMergeVars(String.Format(email), mergeVars);
var response = this.SubscribeWithMergeVars(String.Format(email), mergeVars, enableDoubleOptIn);

return response;
}
Expand Down
4 changes: 2 additions & 2 deletions MailChimp.Net.Tests/SectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void TestSubscribe(string emailPattern, int numberOfEmails)
IMailChimpApiService mailChimpApiService = new MailChimpApiService(MailChimpServiceConfiguration.Settings.ApiKey);
for (int i = 0; i < numberOfEmails; i++)
{
var response = mailChimpApiService.Subscribe(String.Format(emailPattern, i));
var response = mailChimpApiService.Subscribe(String.Format(emailPattern, i), false);
Console.WriteLine(response.ResponseJson);
Assert.AreEqual(true, response.IsSuccesful);
}
Expand Down Expand Up @@ -61,7 +61,7 @@ public void TestSubscribeWithGroupingsAndMergeVars(string emailPattern, int numb
{"COUNTRY", "Greece"}
};

var response = mailChimpApiService.Subscribe(String.Format(emailPattern, i), new List<Grouping>() { subscribeSources, couponsGained, interests }, fields);
var response = mailChimpApiService.Subscribe(String.Format(emailPattern, i), new List<Grouping>() { subscribeSources, couponsGained, interests }, fields, false);
Console.WriteLine(response.ResponseJson);
Assert.AreEqual(true, response.IsSuccesful);
}
Expand Down

0 comments on commit e857557

Please sign in to comment.