Пример #1
0
        public void UpdateMember_Successful()
        {
            //  Arrange
            MailChimpManager mc    = new MailChimpManager(TestGlobal.Test_APIKey);
            ListResult       lists = mc.GetLists();
            EmailParameter   email = new EmailParameter()
            {
                Email = "*****@*****.**"
            };
            var            listId              = lists.Data[0].Id;
            MyMergeVar     mergeVar            = new MyMergeVar();
            EmailParameter subscriptionResults = mc.Subscribe(listId, email, mergeVar, "html", false, true);

            //  Act
            mergeVar.FirstName = "some name";
            mc.UpdateMember(listId, subscriptionResults, mergeVar);

            // load
            List <EmailParameter> emails = new List <EmailParameter>();

            emails.Add(email);
            MemberInfoResult memberInfos = mc.GetMemberInfo(listId, emails);

            //  Assert
            Assert.IsTrue(memberInfos.Data[0].MemberMergeInfo.ContainsKey("FNAME"));
            Assert.AreEqual("some name", memberInfos.Data[0].MemberMergeInfo["FNAME"]);
        }
Пример #2
0
        public void GetMemberInfo_Successful()
        {
            //  Arrange
            MailChimpManager mc    = new MailChimpManager(TestGlobal.Test_APIKey);
            ListResult       lists = mc.GetLists();

            List <EmailParameter> emails = new List <EmailParameter>();

            EmailParameter email1 = new EmailParameter()
            {
                Email = "*****@*****.**"
            };

            EmailParameter email2 = new EmailParameter()
            {
                Email = "*****@*****.**"
            };

            emails.Add(email1);
            emails.Add(email2);

            //  Act
            MemberInfoResult results = mc.GetMemberInfo(lists.Data[1].Id, emails);

            //  Assert
            Assert.IsNotNull(results);
        }
Пример #3
0
        public void BatchSubscribe_Successful()
        {
            //  Arrange
            MailChimpManager mc    = new MailChimpManager(TestGlobal.Test_APIKey);
            ListResult       lists = mc.GetLists();

            List <BatchEmailParameter> emails = new List <BatchEmailParameter>();

            BatchEmailParameter email1 = new BatchEmailParameter()
            {
                Email = new EmailParameter()
                {
                    Email = "*****@*****.**"
                }
            };
            MergeVar mVar1 = new MergeVar();

            mVar1.Add("FNAME", "first1" + DateTime.Now);
            mVar1.Add("LNAME", "last1" + DateTime.Now);
            email1.MergeVars = mVar1;
            emails.Add(email1);

            BatchEmailParameter email2 = new BatchEmailParameter()
            {
                Email = new EmailParameter()
                {
                    Email = "*****@*****.**"
                }
            };
            MergeVar mVar2 = new MergeVar();

            mVar2.Add("FNAME", "first2" + DateTime.Now);
            mVar2.Add("LNAME", "last2" + DateTime.Now);
            email2.MergeVars = mVar2;
            emails.Add(email2);

            //  Act
            BatchSubscribeResult results = mc.BatchSubscribe(lists.Data[0].Id, emails);

            //  Assert
            Assert.IsNotNull(results);
            Assert.IsTrue(results.AddCount == 2);

            // load
            List <EmailParameter> emailsP = new List <EmailParameter>();

            emailsP.Add(email1.Email);
            MemberInfoResult memberInfo = mc.GetMemberInfo(lists.Data[0].Id, emailsP);

            Assert.AreEqual(mVar1["FNAME"], memberInfo.Data[0].MemberMergeInfo["FNAME"]);
            Assert.AreEqual(mVar1["LNAME"], memberInfo.Data[0].MemberMergeInfo["LNAME"]);
        }
Пример #4
0
    public static IEnumerable ListsMemberInterestGroupings(SqlString apikey, SqlString list_id, SqlString email, SqlString euid, SqlString leid)
    {
        List <MemberInterestGroupRow> rows = new List <MemberInterestGroupRow>();

        string cListId = list_id.ToString();

        MailChimpManager mc = new MailChimpManager(apikey.ToString());

        MemberInfoResult memberResult = mc.GetMemberInfo(cListId, new List <EmailParameter>
        {
            new EmailParameter {
                Email = email.ToString(),
                EUId  = euid.ToString(),
                LEId  = leid.ToString()
            }
        });

        if (memberResult.SuccessCount > 0)
        {
            MemberInfo memberInfo = memberResult.Data[0];

            if (memberInfo.MemberMergeInfo.Groupings != null)
            {
                foreach (Grouping grouping in memberInfo.MemberMergeInfo.Groupings)
                {
                    string groupNames = (grouping.GroupNames == null) ? string.Empty : string.Join(",", grouping.GroupNames.ToArray());

                    foreach (MailChimp.Lists.Grouping.GroupInterest interest in grouping.GroupInterests)
                    {
                        MemberInterestGroupRow row = new MemberInterestGroupRow
                        {
                            Id                = grouping.Id,
                            Name              = grouping.Name,
                            GroupNames        = groupNames,
                            GroupInterestName = interest.Name,
                            Interested        = interest.Interested
                        };
                        rows.Add(row);
                    }
                }
            }
        }
        return(rows);
    }
Пример #5
0
    public static int ListsMemberMergeVarSet(SqlString apikey, SqlString list_id, SqlString email, SqlString euid, SqlString leid, SqlString tag, SqlString value)
    {
        try
        {
            string cListId = list_id.ToString();

            MailChimpManager mc = new MailChimpManager(apikey.ToString());

            EmailParameter emailParam = new EmailParameter {
                Email = email.ToString(),
                EUId  = euid.ToString(),
                LEId  = leid.ToString()
            };

            MemberInfoResult memberResult = mc.GetMemberInfo(cListId, new List <EmailParameter> {
                emailParam
            });

            if (memberResult.SuccessCount > 0)
            {
                MemberInfo memberInfo = memberResult.Data[0];
                memberInfo.MemberMergeInfo[tag.ToString()] = value.ToString();
                mc.UpdateMember(cListId, emailParam, memberInfo.MemberMergeInfo, "", true);
            }
            else
            {
                SqlContext.Pipe.Send(String.Format("Member not found : email = {0}, euid = {1}, leid = {2}",
                                                   email.ToString(), euid.ToString(), leid.ToString()));
                return(1);
            }
        }
        catch (Exception ex)
        {
            SqlContext.Pipe.Send(ex.Message);
            return(1);
        }
        return(0);
    }
Пример #6
0
    public static IEnumerable ListsMemberNotes(SqlString apikey, SqlString list_id, SqlString email, SqlString euid, SqlString leid)
    {
        List <MemberNote> rows = new List <MemberNote>();

        string cListId = list_id.ToString();

        MailChimpManager mc = new MailChimpManager(apikey.ToString());

        MemberInfoResult memberResult = mc.GetMemberInfo(cListId, new List <EmailParameter>
        {
            new EmailParameter {
                Email = email.ToString(),
                EUId  = euid.ToString(),
                LEId  = leid.ToString()
            }
        });

        if (memberResult.SuccessCount > 0)
        {
            MemberInfo memberInfo = memberResult.Data[0];
            rows.AddRange(memberInfo.Notes);
        }
        return(rows);
    }
Пример #7
0
    public static IEnumerable ListsMemberMergeVars(SqlString apikey, SqlString list_id, SqlString email, SqlString euid, SqlString leid)
    {
        List <MemberMergeVarRow> vars = new List <MemberMergeVarRow>();

        string cListId = list_id.ToString();

        MailChimpManager mc = new MailChimpManager(apikey.ToString());

        MemberInfoResult memberResult = mc.GetMemberInfo(cListId, new List <EmailParameter>
        {
            new EmailParameter {
                Email = email.ToString(),
                EUId  = euid.ToString(),
                LEId  = leid.ToString()
            }
        });

        if (memberResult.SuccessCount > 0)
        {
            MemberInfo memberInfo = memberResult.Data[0];
            foreach (string key in memberInfo.MemberMergeInfo.Keys)
            {
                object value = memberInfo.MemberMergeInfo[key];
                vars.Add(new MemberMergeVarRow
                {
                    ListId        = cListId,
                    Email         = memberInfo.Email,
                    LEId          = memberInfo.LEId,
                    EUId          = memberInfo.Id,
                    MergeVarName  = key,
                    MergeVarValue = (value ?? string.Empty).ToString()
                });
            }
        }
        return(vars);
    }
Пример #8
0
        public void SubscribeWithGroupSelectionUsingDictonary_Successful()
        {
            //  Arrange
            MailChimpManager mc    = new MailChimpManager(TestGlobal.Test_APIKey);
            ListResult       lists = mc.GetLists();
            EmailParameter   email = new EmailParameter()
            {
                Email = "*****@*****.**"
            };

            // find a list with interest groups...
            string strListID    = null;
            int    nGroupingID  = 0;
            string strGroupName = null;

            foreach (ListInfo li in lists.Data)
            {
                List <InterestGrouping> interests = mc.GetListInterestGroupings(li.Id);
                if (interests != null)
                {
                    if (interests.Count > 0)
                    {
                        if (interests[0].GroupNames.Count > 0)
                        {
                            strListID    = li.Id;
                            nGroupingID  = interests[0].Id;
                            strGroupName = interests[0].GroupNames[0].Name;
                            break;
                        }
                    }
                }
            }
            Assert.IsNotNull(strListID, "no lists found in this account with groupings / group names");
            Assert.AreNotEqual(0, nGroupingID);
            Assert.IsNotNull(strGroupName);

            MergeVar mvso = new MergeVar();

            mvso.Groupings = new List <Grouping>();
            mvso.Groupings.Add(new Grouping());
            mvso.Groupings[0].Id         = nGroupingID;
            mvso.Groupings[0].GroupNames = new List <string>();
            mvso.Groupings[0].GroupNames.Add(strGroupName);
            mvso.Add("FNAME", "Testy" + DateTime.Now);
            mvso.Add("LNAME", "Testerson" + DateTime.Now);

            //  Act
            EmailParameter results = mc.Subscribe(strListID, email, mvso);

            //  Assert
            Assert.IsNotNull(results);
            Assert.IsTrue(!string.IsNullOrEmpty(results.LEId));

            // load
            List <EmailParameter> emails = new List <EmailParameter>();

            emails.Add(results);
            MemberInfoResult memberInfos = mc.GetMemberInfo(strListID, emails);

            // Assert
            Assert.AreEqual(1, memberInfos.SuccessCount);
            Assert.AreEqual(2, memberInfos.Data[0].MemberMergeInfo.Count);
            Assert.AreEqual(mvso["FNAME"], memberInfos.Data[0].MemberMergeInfo["FNAME"]);
            Assert.AreEqual(mvso["LNAME"], memberInfos.Data[0].MemberMergeInfo["LNAME"]);
        }
Пример #9
0
        public void GetMemberInfo_Successful()
        {
            //  Arrange
            MailChimpManager mc = new MailChimpManager(TestGlobal.Test_APIKey);
            ListResult lists = mc.GetLists();

            List<EmailParameter> emails = new List<EmailParameter>();

            EmailParameter email1 = new EmailParameter()
            {
                Email = "*****@*****.**"
            };

            EmailParameter email2 = new EmailParameter()
            {
                Email = "*****@*****.**"
            };

            emails.Add(email1);
            emails.Add(email2);

            //  Act
            MemberInfoResult results = mc.GetMemberInfo(lists.Data[1].Id, emails);

            //  Assert
            Assert.IsNotNull(results);
        }
        /// <summary>
        /// Batches the unsubscribe.
        /// </summary>
        /// <param name="recordList">The records</param>
        public virtual BatchUnsubscribeResult BatchUnsubscribe(IEnumerable<MailChimpEventQueueRecord> recordList)
        {
            if (String.IsNullOrEmpty(_mailChimpSettings.DefaultListId))
                throw new ArgumentException("MailChimp list is not specified");

            var mc = new MailChimpManager(_mailChimpSettings.ApiKey);

            var emails = recordList.Select(sub => new EmailParameter() {Email = sub.Email}).ToList();

            MemberInfoResult emailInfos = mc.GetMemberInfo(_mailChimpSettings.DefaultListId, emails);

            emails.Clear();

            foreach (var member in emailInfos.Data)
            {
                if (member!=null && member.Status.ToLower().Contains("subscribed"))
                {
                    emails.Add(new EmailParameter() { Email = member.Email });
                }
            }

            ////remove email if it's subscribed to mailchimp list
            BatchUnsubscribeResult results = mc.BatchUnsubscribe(_mailChimpSettings.DefaultListId, emails, false, true, true);

            return results;
        }
Пример #11
0
        public void BatchSubscribe_Successful()
        {
            //  Arrange
            MailChimpManager mc = new MailChimpManager(TestGlobal.Test_APIKey);
            ListResult lists = mc.GetLists();

            List<BatchEmailParameter> emails = new List<BatchEmailParameter>();

            BatchEmailParameter email1 = new BatchEmailParameter()
            {
                Email = new EmailParameter()
                {
                    Email = "*****@*****.**"
                }
            };
						MergeVar mVar1 = new MergeVar();
						mVar1.Add("FNAME", "first1" + DateTime.Now);
						mVar1.Add("LNAME", "last1" + DateTime.Now);
						email1.MergeVars = mVar1;
						emails.Add(email1);

            BatchEmailParameter email2 = new BatchEmailParameter()
            {
                Email = new EmailParameter()
                {
                    Email = "*****@*****.**"
                }
            };
						MergeVar mVar2 = new MergeVar();
						mVar2.Add("FNAME", "first2" + DateTime.Now);
						mVar2.Add("LNAME", "last2" + DateTime.Now);
						email2.MergeVars = mVar2;
            emails.Add(email2);

            //  Act
            BatchSubscribeResult results = mc.BatchSubscribe(lists.Data[0].Id, emails);

            //  Assert
            Assert.IsNotNull(results);
            Assert.IsTrue(results.AddCount == 2);

						// load
						List<EmailParameter> emailsP = new List<EmailParameter>();
						emailsP.Add(email1.Email);
						MemberInfoResult memberInfo = mc.GetMemberInfo(lists.Data[0].Id, emailsP);
						Assert.AreEqual(mVar1["FNAME"], memberInfo.Data[0].MemberMergeInfo["FNAME"]);
						Assert.AreEqual(mVar1["LNAME"], memberInfo.Data[0].MemberMergeInfo["LNAME"]);

        }
Пример #12
0
				public void SubscribeWithGroupSelectionUsingDictonary_Successful() {
					//  Arrange
					MailChimpManager mc = new MailChimpManager(TestGlobal.Test_APIKey);
					ListResult lists = mc.GetLists();
					EmailParameter email = new EmailParameter() {
						Email = "*****@*****.**"
					};

					// find a list with interest groups...
					string strListID = null;
					int nGroupingID = 0;
					string strGroupName = null;
					foreach (ListInfo li in lists.Data) {
						List<InterestGrouping> interests = mc.GetListInterestGroupings(li.Id);
						if (interests != null) {
							if (interests.Count > 0) {
								if (interests[0].GroupNames.Count > 0) {
									strListID = li.Id;
									nGroupingID = interests[0].Id;
									strGroupName = interests[0].GroupNames[0].Name;
									break;
								}
							}
						}
					}
					Assert.IsNotNull(strListID, "no lists found in this account with groupings / group names");
					Assert.AreNotEqual(0, nGroupingID);
					Assert.IsNotNull(strGroupName);

					MergeVar mvso = new MergeVar();
					mvso.Groupings = new List<Grouping>();
					mvso.Groupings.Add(new Grouping());
					mvso.Groupings[0].Id = nGroupingID;
					mvso.Groupings[0].GroupNames = new List<string>();
					mvso.Groupings[0].GroupNames.Add(strGroupName);
					mvso.Add("FNAME","Testy" + DateTime.Now);
					mvso.Add("LNAME", "Testerson" + DateTime.Now);

					//  Act
					EmailParameter results = mc.Subscribe(strListID, email, mvso);

					//  Assert
					Assert.IsNotNull(results);
					Assert.IsTrue(!string.IsNullOrEmpty(results.LEId));

					// load
					List<EmailParameter> emails = new List<EmailParameter>();
					emails.Add(results);
					MemberInfoResult memberInfos = mc.GetMemberInfo(strListID, emails);

					// Assert
					Assert.AreEqual(1, memberInfos.SuccessCount);
					Assert.AreEqual(2, memberInfos.Data[0].MemberMergeInfo.Count);
					Assert.AreEqual(mvso["FNAME"], memberInfos.Data[0].MemberMergeInfo["FNAME"]);
					Assert.AreEqual(mvso["LNAME"], memberInfos.Data[0].MemberMergeInfo["LNAME"]);

				}
Пример #13
0
        public void UpdateMember_Successful()
        {
            //  Arrange
            MailChimpManager mc = new MailChimpManager(TestGlobal.Test_APIKey);
            ListResult lists = mc.GetLists();
            EmailParameter email = new EmailParameter()
            {
                Email = "*****@*****.**"
            };
            var listId = lists.Data[0].Id;
            MyMergeVar mergeVar = new MyMergeVar();
            EmailParameter subscriptionResults = mc.Subscribe(listId, email, mergeVar, "html", false, true);

            //  Act
            mergeVar.FirstName = "some name";
            mc.UpdateMember(listId, subscriptionResults, mergeVar);

            // load
            List<EmailParameter> emails = new List<EmailParameter>();
            emails.Add(email);
            MemberInfoResult memberInfos = mc.GetMemberInfo(listId, emails);

            //  Assert
            Assert.IsTrue(memberInfos.Data[0].MemberMergeInfo.ContainsKey("FNAME"));
            Assert.AreEqual("some name", memberInfos.Data[0].MemberMergeInfo["FNAME"]);
        }