Example #1
0
    public static IEnumerable ListsMembers(SqlString apikey, SqlString list_id, SqlString status)
    {
        string cListId = list_id.ToString();
        string cStatus = status.ToString();

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

        MembersResult membersResult = mc.GetAllMembersForList(cListId, cStatus, 0, 100, "", "ASC", null);

        List <MemberInfo> members = new List <MemberInfo>(membersResult.Total);

        members.AddRange(membersResult.Data);

        int page         = 1;
        int total        = membersResult.Total;
        int currentTotal = membersResult.Data.Count;

        while (currentTotal < total)
        {
            membersResult = mc.GetAllMembersForList(cListId, cStatus, page++, 100, "", "ASC", null);
            members.AddRange(membersResult.Data);
            currentTotal += membersResult.Data.Count;
        }
        return(members);
    }
Example #2
0
        public void GetMemberActivity_Successful()
        {
            //  Arrange
            MailChimpManager mc = new MailChimpManager(TestGlobal.Test_APIKey);

            ListResult lists = mc.GetLists();

            Assert.IsNotNull(lists.Data);
            Assert.IsTrue(lists.Data.Any());

            MembersResult members = mc.GetAllMembersForList(lists.Data[0].Id);

            Assert.IsNotNull(members.Data);
            Assert.IsTrue(members.Data.Any());

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

            foreach (MemberInfo member in members.Data)
            {
                memberEmails.Add(new EmailParameter()
                {
                    Email = member.Email
                });
            }

            //  Act
            MemberActivityResult results = mc.GetMemberActivity(lists.Data[0].Id, memberEmails);

            //  Assert
            Assert.IsNotNull(results);
            Assert.IsTrue(results.Data.Any());
        }
Example #3
0
        public void SendCampaign()
        {
            if ((cmbTemplate.SelectedIndex > 0 && cmbTemplate.SelectedItem != null) && (cmbList.SelectedIndex > 0 && cmbList.SelectedItem != null))
            {
                Int32 selectedTemplateId = Convert.ToInt32(cmbTemplate.SelectedValue);

                string selectedListId = cmbList.SelectedValue.ToString();
                //IEnumerable<string> listEnum = new string[] { selectedListId.ToString() };

                //--Create Campaign
                CampaignSegmentOptions segmentOptions = new CampaignSegmentOptions();
                segmentOptions.Match = "All";
                CampaignCreateOptions options = new CampaignCreateOptions();
                options.Title      = mailchimptitle;
                options.ListId     = selectedListId;
                options.ToName     = mailchimpToName;
                options.FromEmail  = mailchimpFromEmail;
                options.FromName   = mailchimpFromName;
                options.Subject    = mailchimpSubject;
                options.TemplateID = selectedTemplateId;
                CampaignCreateContent content = new CampaignCreateContent();
                Campaign result = mc.CreateCampaign("regular", options, content, null, null);


                //GetMemberInfo
                if (chkEnableSMS.Checked)
                {
                    List <EmailParameter> emails  = new List <EmailParameter>();
                    MembersResult         results = mc.GetAllMembersForList(selectedListId, "subscribed", 0, 100);
                    foreach (var i in results.Data)
                    {
                        foreach (var j in i.MemberMergeInfo)
                        {
                            if (j.Key.Trim() == "PHONE")
                            {
                                if (!string.IsNullOrEmpty(j.Value.ToString()))
                                {
                                    //  SmsSender.SendSMS(j.Value.ToString(), "919460264151", "5b2a23d7", "59d9fa03", Uri.EscapeUriString("Test Message"));
                                }
                            }
                        }
                    }
                }
            }
            MessageBox.Show("Success");
            this.Close();
        }
 public MemberViewModel(MembersResult member)
 {
     Id       = member.id.ToString();
     Name     = member.name;
     Bio      = member.bio;
     Facebook = member.other_services?.facebook?.identifier;
     Linkedin = member.other_services?.linkedin?.identifier;
     Twitter  = member.other_services?.twitter?.identifier;
     if (member?.photo?.highres_link != null)
     {
         ImageUrlHigh = member?.photo?.highres_link;
     }
     else
     {
         ImageUrlHigh = member?.photo?.photo_link;
     }
     ImageUrl = member?.photo?.photo_link;
     City     = member.city;
 }
Example #5
0
        public void GetAllMembersForList_Successful()
        {
            //  Arrange
            MailChimpManager mc    = new MailChimpManager(TestGlobal.Test_APIKey);
            ListResult       lists = mc.GetLists();

            //  For each list
            foreach (var list in lists.Data)
            {
                //  Write out the list name:
                Debug.WriteLine("Users for the list " + list.Name);

                //  Get the first 100 members of each list:
                MembersResult results = mc.GetAllMembersForList(list.Id, "subscribed", 0, 100);

                //  Write out each member's email address:
                foreach (var member in results.Data)
                {
                    Debug.WriteLine(member.Email);
                }
            }
        }
        public static List <MemberInfo> GetAllMembers(string api_key)
        {
            int limit              = 100;
            var members            = new List <MemberInfo>();
            MailChimpManager mc    = new MailChimpManager(api_key);
            ListResult       lists = mc.GetLists();

            foreach (var list in lists.Data)
            {
                int j = 0;
                while (true)
                {
                    MembersResult results = mc.GetAllMembersForList(list.Id, "subscribed", j, limit);
                    members.AddRange(results.Data);
                    if (results.Data.Count < limit)
                    {
                        break;
                    }
                    j += limit - 1;
                }
            }
            return(members);
        }
Example #7
0
        public static void LoadContacts(string myFilter, string MailChimpListID, int GroupID, string GroupData, string MailChimpKey, string WildApricotKey)

        {
            Console.WriteLine();
            Console.WriteLine("Loading contacts");

            // Filters results to all members with with email address at gmail.com.
            // 'e-mail' is a system field, but its name can be modified by account admin.
            //  If you have problem running program with this field name, check actual name in admin view or just set filterExpression = "$filter=Member eq true"
            var filterExpression = "$filter=Member eq true and substringof('e-Mail','@gmail.com')";

            // Retrieves only the specified fields. Leave it empty to retrieve all fields.
            // 'First name',Phone,'e-mail' are system fields, but their names can be modified by account admin.
            // If you have problem running program with these fields names, check actual names in admin view or just set selectExpression = String.Empty
            var selectExpression = "$select='First name',Phone,'e-mail','Member since','Member Id'";

            // build url
            //var url = string.Format("{0}/v1/accounts/{1}/Contacts/?{2}&{3}", CONST_BaseUrl, AccountId, filterExpression, selectExpression);
            selectExpression = "";
            string url = "";
            string _filterExpression;

            if (myFilter == "")
            {
                _filterExpression = "";
            }
            else
            {
                _filterExpression = String.Concat("$filter=", myFilter);
            }


            if (filterExpression == "")
            {
                url = String.Format("{0}/v1/accounts/{1}/Contacts", CONST_BaseUrl, AccountId, filterExpression, selectExpression);
            }
            else
            {
                url = String.Format("{0}/v1/accounts/{1}/Contacts/?{2}&{3}", CONST_BaseUrl, AccountId, _filterExpression, selectExpression);
            }


            var request = LoadObject(url, WildApricotKey);



            while (true)
            {
                System.Threading.Thread.Sleep(3000);

                request = LoadObject(request.ResultUrl.ToString(), WildApricotKey);
                string state = request.State.ToString();
                //  Console.WriteLine("Request state is '{0}' at {1}", state, DateTime.Now);



                switch (state)
                {
                case "Complete":
                {
                    foreach (var contact in request.Contacts)
                    {
                        // Console.WriteLine("Contact #{0}:", contact.Id);
                        string FirstName            = "";
                        string LastName             = "";
                        string eMailAddress         = "";
                        string eMailAddressPersonal = "";
                        string isMember             = "";
                        string fieldEMail           = "Work e-Mail";
                        string fieldPersonalEMail   = "Personal e-Mail";

                        if (EMailField != "")
                        {
                            fieldEMail = EMailField;
                        }

                        if (EMailField2 != "")
                        {
                            fieldPersonalEMail = EMailField2;
                        }

                        foreach (var field in contact.FieldValues)

                        {
                            // Console.WriteLine("  {0}: {1}", field.FieldName, field.Value);

                            string caseSwitch = field.FieldName;
                            switch (caseSwitch)
                            {
                            case "First name":
                                FirstName = field.Value;
                                break;

                            case "Last name":
                                LastName = field.Value;
                                break;

                            case "E-Mail":
                                eMailAddress = field.Value;
                                break;

                            case "Member":
                                isMember = field.Value;
                                break;

                            default:
                                if (field.FieldName == fieldEMail)
                                {
                                    eMailAddress = field.Value;
                                }
                                if (field.FieldName == fieldPersonalEMail)
                                {
                                    eMailAddressPersonal = field.Value;
                                }
                                break;
                            }
                        }

                        string FullName = FirstName + " " + LastName + " " + eMailAddress;
                        //if (FullName.StartsWith("Oliver"))
                        if (FullName != "")
                        {
                            //Console.WriteLine(FullName);

                            MyMergeVar myMergeVars = new MyMergeVar();

                            if (GroupID != 0)
                            {
                                myMergeVars.Groupings = new List <Grouping>();
                                myMergeVars.Groupings.Add(new Grouping());
                                myMergeVars.Groupings[0].Id         = GroupID; // replace with your grouping id
                                myMergeVars.Groupings[0].GroupNames = new List <string>();

                                if (isMember == "True")
                                {
                                    myMergeVars.Groupings[0].GroupNames.Add("Member");
                                }
                                else
                                {
                                    myMergeVars.Groupings[0].GroupNames.Add("Contact");
                                }
                            }

                            myMergeVars.FirstName = FirstName;
                            myMergeVars.LastName  = LastName;

                            MailChimpManager mc = new MailChimpManager(MailChimpKey);

                            //  Create the email parameter
                            EmailParameter email = new EmailParameter();
                            //Console.WriteLine(eMailAddress);
                            string _Email = "";

                            if (eMailAddress != "")
                            {
                                _Email = eMailAddress;
                                if (IsValidEmailAddressByRegex(_Email) == false)
                                {
                                    Console.WriteLine(_Email + " not valid for " + FirstName + " " + LastName);
                                    if (eMailAddressPersonal != "")
                                    {
                                        _Email = eMailAddressPersonal;
                                        Console.WriteLine("Found this " + _Email + " for " + FirstName + " " + LastName);
                                    }
                                }
                            }
                            else
                            {
                                _Email = eMailAddressPersonal;
                            }


                            EmailParameter emailPar = new EmailParameter()
                            {
                                Email = _Email
                            };

                            //Check if user unsubscribed

                            //  Get the first 100 members of each list:
                            MembersResult mresults = mc.GetAllMembersForList(MailChimpListID, "unsubscribed");

                            //  Write out each member's email address:
                            bool SubscribeMe = true;
                            foreach (var member in mresults.Data)
                            {
                                //Console.WriteLine("member.Email:"  + member.Email + " -> " + member.Status);
                                if (member.Email == eMailAddress)
                                {
                                    SubscribeMe = false;
                                    //Console.WriteLine("Will not subscribe: " + member.Email);
                                }
                            }

                            if (SubscribeMe)
                            {
                                try
                                {
                                    EmailParameter results = mc.Subscribe(MailChimpListID, emailPar, myMergeVars, "html", false, true, false, false);
                                }
                                catch
                                {
                                    Console.WriteLine("Can't subscribe: " + _Email + " (EMail1: " + eMailAddress + ") (EMail2: " + eMailAddressPersonal + ") " + FirstName + " " + LastName);
                                    Console.ReadLine();
                                }
                            }
                        }
                    }
                    return;
                }

                case "Failed":
                {
                    Console.WriteLine("Error:'{0}'", request.ErrorDetails);
                    return;
                }
                }
            }
        }