Ejemplo n.º 1
0
        private ApiResult PostToMadMimi(string url, string data, bool useMailer)
        {
            try {
                HttpWebRequest req = (HttpWebRequest) WebRequest.Create(
                    (useMailer) ? GetMadMimiMailerURL(url) : GetMadMimiURL(url)
                );
                req.Method = "POST";
                req.ContentType = "application/x-www-form-urlencoded";

                string reqStr = String.Format("username={0}&api_key={1}&{2}", Username, APIKey, data);
                req.ContentLength = reqStr.Length;

                if(debug) {
                    Console.WriteLine(reqStr);
                }

                using(StreamWriter reqStream = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII)) {
                    reqStream.Write(reqStr);
                    reqStream.Close();
                }

                lastResult = new ApiResult((HttpWebResponse) req.GetResponse());
            } catch (Exception ex) {
                lastResult = new ApiResult(ex);
                if (ThrowExceptions) {
                    throw new ApiException(ex);
                }
            }
            if(lastResult.IsError && ThrowExceptions) {
                    throw new ApiException(lastResult);
            }
            return lastResult;
        }
Ejemplo n.º 2
0
        private ApiResult GetFromMadMimi(string url, bool useMailer)
        {
            try {
                string reqStr = String.Format("{0}&username={1}&api_key={2}", url, Username, APIKey);

                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(
                    (useMailer) ? GetMadMimiMailerURL(reqStr) : GetMadMimiURL(reqStr)
                );
                req.Method = "GET";
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = 0;
                StreamWriter reqStream = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
                reqStream.Close();

                lastResult = new ApiResult((HttpWebResponse) req.GetResponse());
            } catch(Exception ex) {
                lastResult = new ApiResult(ex);
                if (ThrowExceptions) {
                    throw new ApiException(ex);
                }
            }
            if(lastResult.IsError && ThrowExceptions) {
                    throw new ApiException(lastResult);
            }
            return lastResult;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Imports a data table of audience members into Mimi. By Marc Heiligers ([email protected])
        /// </summary>
        /// <param name="audienceMembers">
        /// The datatable containing the audience member information (note: there must be an 'email' column) <see cref="DataTable"/>
        /// </param>
        /// <param name="listName">
        /// An optional name of a list that the audience members should be imported into <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// True is successful, false otherwise <see cref="System.Boolean"/>
        /// </returns>
        public ApiResult AudienceImport(DataTable audienceMembers, string listName)
        {
            try {
                StringBuilder reqData = new StringBuilder();

                string[] cols = new string[audienceMembers.Columns.Count + (listName == null ? 0 : 1)];
                int idx = 0;
                foreach (DataColumn dc in audienceMembers.Columns) {
                    cols[idx] = FormatCsvValue(dc.ColumnName);
                    idx++;
                }
                    if(listName != null) {
                        cols[idx] = "add_list"; //Special Mimi Column to add imported members to a list
                    }
                reqData.AppendLine(String.Join(",", cols));

                string[] rowData = new string[audienceMembers.Columns.Count + (listName == null ? 0 : 1)];
                foreach (DataRow dr in audienceMembers.Rows) {
                    for (idx = 0; idx < audienceMembers.Columns.Count; idx++) {
                        rowData[idx] = FormatCsvValue(dr[idx].ToString());
                    }
                    if(listName != null) {
                        rowData[idx] = FormatCsvValue(listName); //The list name to add to if supplied
                    }
                    reqData.AppendLine(String.Join(",", rowData));
                }

                string data = String.Format("csv_file={0}", HttpUtility.UrlEncode(reqData.ToString()));
                PostToMadMimi("/audience_members", data);
            } catch(Exception ex) {
                lastResult = new ApiResult(ex);
                if (ThrowExceptions) {
                    throw new ApiException(ex);
                }
            }
            if(lastResult.IsError && ThrowExceptions) {
                    throw new ApiException(lastResult);
            }
            return lastResult;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns a list of strings containg email addresses suppressed since the specified date
        /// </summary>
        /// <param name="date">Start date of suppression list</param>
        /// <returns>List of strings containing suppressed email addresses</returns>
        public List<String> SuppressedSince(DateTime date)
        {
            int ts = DateTimeToUnixTime(date);

            lastResult = GetFromMadMimi(String.Format("/audience_members/suppressed_since/{0}.txt", ts.ToString()), false);
            if(lastResult.IsSuccess) {
                return new List<string>(lastResult.ResultBody.Split('\n'));
            } else {
                return null;
            }
        }
 public ApiException(ApiResult result)
     : base(result.ResultBody, result.Exception)
 {
     statusCode = result.StatusCode;
 }