Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="apiKey"></param>
        /// <param name="listid"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public static MailChimpListMembersLists GetListMembers(string apiKey, string listid, MemberStatus status = MemberStatus.subscribed)
        {
            var listMembersLists = new MailChimpListMembersLists();

            var dc = GetApiDc(apiKey);

            if (dc.IsNullOrEmpty())
            {
                return(null);
            }

            try
            {
                var request = WebRequest.Create(string.Format("http://{0}.api.mailchimp.com/1.3/?method=listMembers&apikey={1}&id={2}&status={3}", dc, apiKey, string.Empty, status));
                request.Method = "GET";
                var response = request.GetResponse();

                var stream = response.GetResponseStream();
                if (stream != null)
                {
                    listMembersLists = JsonConvert.DeserializeObject <MailChimpListMembersLists>((new StreamReader(stream).ReadToEnd()));
                    return(listMembersLists);
                }
            }
            catch (Exception)
            { }

            return(listMembersLists);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="apiKey"></param>
        /// <param name="listId"></param>
        /// <param name="emails"></param>
        /// <param name="deleteMember"></param>
        /// <param name="sendGoodbye"></param>
        /// <param name="sendNotify"></param>
        /// <returns></returns>
        public static bool UnsubscribeListMembers(string apiKey, string listId, MailChimpListMembersLists lists, bool deleteMember = true, bool sendGoodbye = false, bool sendNotify = false)
        {
            if (apiKey.IsNullOrEmpty() || listId.IsNullOrEmpty() || lists.ListMembersList == null)
            {
                return(false);
            }

            var dc = GetApiDc(apiKey);

            if (dc.IsNullOrEmpty())
            {
                return(false);
            }

            var request = WebRequest.Create(string.Format("http://{0}.api.mailchimp.com/1.3/?method=listUnsubscribe&apikey={1}&id={2}&emails={3}&delete_member={4}&send_goodbye={5}&send_notify={6}",
                                                          dc,
                                                          apiKey,
                                                          listId,
                                                          string.Format("[{0}]", lists.ListMembersList.Aggregate("", (current, list) => current + list.Email)),
                                                          deleteMember,
                                                          sendGoodbye,
                                                          sendNotify));

            try
            {
                request.Method = "POST";
                var stream = request.GetResponse().GetResponseStream();
                if (stream != null)
                {
                }
            }
            catch (Exception)
            { }

            return(true);
        }