/// <summary> /// Mails the chimp_ unsubscribe. /// Will go through each ContactId in the ContactIdslist, retrieve the Contacts.FirstName, Contacts.LastName, Contacts.Email. /// Invoke the MailChimp API listBatchUnsubscribe /// </summary> /// <param name="ContactIds">The contact ids.</param> /// <param name="MailChimpListId">The mail chimp list id.</param> /// <returns></returns> public MailChimp_Response MailChimp_Unsubscribe(List <int> ContactIds, string MailChimpListId) { MailChimp_Response response = new MailChimp_Response(); response.hdr = new RespHdr(); if (ContactIds == null || ContactIds.Count == 0) { response.hdr.Successful = false; response.hdr.StatusInfo = string.Format("MailChimpMgr: ContactIds is null."); return(response); } if (string.IsNullOrEmpty(MailChimpListId)) { response.hdr.Successful = false; response.hdr.StatusInfo = string.Format("MailChimpMgr: MailChimpListId is null."); return(response); } string apiKey = string.Empty; apiKey = GetApiKey(MailChimpListId); if (string.IsNullOrEmpty(apiKey)) { response.hdr.Successful = false; response.hdr.StatusInfo = string.Format("MailChimpMgr: MailChimpAPIKey is null."); return(response); } var contacts = _dataAccess.GetMailChimpContact(ContactIds); return(_mailChimpApi.ListBatchUnsubscribe(apikey: apiKey, mailChimpListId: MailChimpListId, subscriberList: contacts)); }
public void ListBatchUnsubscribe() { var subscribers = new List <Table.MailChimpContact> { new Table.MailChimpContact { Email = "*****@*****.**", FirstName = "Jac11", LastName = "Zhang11", }, new Table.MailChimpContact { Email = "*****@*****.**", FirstName = "Jac12", LastName = "Zhang12", }, new Table.MailChimpContact { Email = "*****@*****.**", FirstName = "Jac13", LastName = "Zhang13" }, new Table.MailChimpContact { Email = "*****@*****.**", FirstName = "Jac14", LastName = "Zhang14" } }; Assert.AreEqual(true, mailChimpApi.ListBatchUnsubscribe(_apiKey, _listId, subscribers)); }