/// <summary> /// Update existing Mesage /// </summary> private string update() { //URL (PUT) (api.XXXXXXXXXXXXX.subdomain.mailee.me/messages) string url = string.Format("{0}messages/{1}.xml", Mailee.Config.UrlAPI, this.Id); //Create url params List<RestParameter> pars = new List<RestParameter>(); pars.Add(new RestParameter("message[title]", this.Title)); pars.Add(new RestParameter("message[subject]", this.Subject)); pars.Add(new RestParameter("message[from_name]", this.FromName)); pars.Add(new RestParameter("message[from_email]", this.FromEmail)); pars.Add(new RestParameter("message[analytics]", this.Analytics.ToString().ToLower())); if (this.ReplyEmail != string.Empty) pars.Add(new RestParameter("message[reply_email]", this.ReplyEmail)); if (this.Html != string.Empty) pars.Add(new RestParameter("message[html]", this.Html)); if (this.TemplateId != 0) { pars.Add(new RestParameter("message[template_id]", this.TemplateId)); foreach (KeyValuePair<int, string> item in this.Edit) pars.Add(new RestParameter(string.Format("message[edit][{0}]", item.Key), item.Value)); foreach (KeyValuePair<int, string> item in this.Repeats) pars.Add(new RestParameter(string.Format("message[repeats][{0}]", item.Key), item.Value)); } if (this.Emails != string.Empty) pars.Add(new RestParameter("message[emails]", this.Emails)); if (this.ListId != 0) { pars.Add(new RestParameter("message[list_id]", this.ListId)); if (this.SegmentId > 0) pars.Add(new RestParameter("message[segment_id]", this.SegmentId)); } //Post Data string result = Mailee.Rest.put(url, pars); return result; }
/// <summary> /// Update existing Template /// </summary> private string update() { //URL (PUT) (api.XXXXXXXXXXXXX.subdomain.mailee.me/templates) string url = string.Format("{0}templates/{1}.xml", Mailee.Config.UrlAPI, this.Id); //Create url params List<RestParameter> pars = new List<RestParameter>(); pars.Add(new RestParameter("template[title]", this.Title)); pars.Add(new RestParameter("template[html]", this.Html)); //Post Data string result = Mailee.Rest.put(url, pars); return result; }
/// <summary> /// Find all Messages /// </summary> public static List<Mailee.Message> findAll() { List<Mailee.Message> messages = new List<Mailee.Message>(); //URL (GET) (api.XXXXXXXXXXXXX.subdomain.mailee.me/messages) string url = string.Concat(Mailee.Config.UrlAPI, "messages.xml"); //Get data string htmlReponse = Mailee.Rest.get(url); //Create XML XmlDocument xmlDoc = new XmlDocument(); //Load XML xmlDoc.LoadXml(htmlReponse); //Get Messagess XmlNodeList xmlMessages = xmlDoc.GetElementsByTagName("message"); //Each Messages foreach (XmlNode xmlMessage in xmlMessages) { //Create new Message Mailee.Message newMessage = new Mailee.Message(); //Set properties newMessage.Analytics = Mailee.Util.parseBool(xmlMessage.ChildNodes[0].InnerText); newMessage.CreatedAt = Mailee.Util.parseDateTime(xmlMessage.ChildNodes[1].InnerText); newMessage.DeletedAt = Mailee.Util.parseDateTime(xmlMessage.ChildNodes[2].InnerText); newMessage.FromEmail = xmlMessage.ChildNodes[3].InnerText; newMessage.FromName = xmlMessage.ChildNodes[4].InnerText; newMessage.Id = Mailee.Util.parseInt(xmlMessage.ChildNodes[5].InnerText); //newMessage.ListId = Mailee.Util.parseInt(xmlMessage.ChildNodes[6].InnerText); newMessage.Log = xmlMessage.ChildNodes[6].InnerText; newMessage.NewsletterId = Mailee.Util.parseInt(xmlMessage.ChildNodes[7].InnerText); newMessage.ReplyEmail = xmlMessage.ChildNodes[8].InnerText; newMessage.SegmentId = Mailee.Util.parseInt(xmlMessage.ChildNodes[9].InnerText); newMessage.SendAfter = Mailee.Util.parseDateTime(xmlMessage.ChildNodes[10].InnerText); newMessage.SendWhen = xmlMessage.ChildNodes[11].InnerText; newMessage.Status = Mailee.Util.parseInt(xmlMessage.ChildNodes[12].InnerText); newMessage.Subject = xmlMessage.ChildNodes[13].InnerText; newMessage.TemplateId = Mailee.Util.parseInt(xmlMessage.ChildNodes[14].InnerText); newMessage.Title = xmlMessage.ChildNodes[15].InnerText; newMessage.Total = Mailee.Util.parseInt(xmlMessage.ChildNodes[16].InnerText); //Add Message messages.Add(newMessage); } return messages; }
/// <summary> /// Find all Templates /// </summary> public static List<Mailee.Template> findAll() { List<Mailee.Template> templates = new List<Mailee.Template>(); //URL (GET) (api.XXXXXXXXXXXXX.subdomain.mailee.me/templates) string url = string.Concat(Mailee.Config.UrlAPI, "templates.xml"); //Get data string htmlReponse = Mailee.Rest.get(url); //Create XML XmlDocument xmlDoc = new XmlDocument(); //Load XML xmlDoc.LoadXml(htmlReponse); //Get Templates XmlNodeList xmlTemplates = xmlDoc.GetElementsByTagName("template"); //Each Tenplates foreach (XmlNode xmlTemplate in xmlTemplates) { //Create new Template Mailee.Template newTemplate = new Mailee.Template(); //Set properties newTemplate.ClientId = Mailee.Util.parseInt(xmlTemplate.ChildNodes[0].InnerText); newTemplate.CreatedAt = Mailee.Util.parseDateTime(xmlTemplate.ChildNodes[1].InnerText); newTemplate.DeletedAt = Mailee.Util.parseDateTime(xmlTemplate.ChildNodes[2].InnerText); newTemplate.Html = xmlTemplate.ChildNodes[3].InnerText; newTemplate.Id = Mailee.Util.parseInt(xmlTemplate.ChildNodes[4].InnerText); newTemplate.Simulations = xmlTemplate.ChildNodes[5].InnerText; newTemplate.ThumbContentType = xmlTemplate.ChildNodes[6].InnerText; newTemplate.ThumbFileName = xmlTemplate.ChildNodes[7].InnerText; newTemplate.ThumbFileSize = Mailee.Util.parseInt(xmlTemplate.ChildNodes[8].InnerText); newTemplate.ThumbUpdatedAt = Mailee.Util.parseDateTime(xmlTemplate.ChildNodes[9].InnerText); newTemplate.Title = xmlTemplate.ChildNodes[10].InnerText; newTemplate.UpdatedAt = Mailee.Util.parseDateTime(xmlTemplate.ChildNodes[11].InnerText); //Add Template templates.Add(newTemplate); } return templates; }
/// <summary> /// Create New Template /// </summary> private string Create() { //URL (POST) (api.XXXXXXXXXXXXX.subdomain.mailee.me/templates.xml) string url = string.Concat(Mailee.Config.UrlAPI, "templates.xml"); //Create url params List<RestParameter> pars = new List<RestParameter>(); pars.Add(new RestParameter("template[title]", this.Title)); pars.Add(new RestParameter("template[html]", this.Html)); //Post Data string result = Mailee.Rest.post(url, pars); return result; }
/// <summary> /// Update existing Contact /// </summary> private string update() { //URL (PUT) (api.XXXXXXXXXXXXX.subdomain.mailee.me/contacts.xml) string url = string.Format("{0}contacts/{1}.xml", Mailee.Config.UrlAPI, this.Id); //Create url params List<RestParameter> pars = new List<RestParameter>(); pars.Add(new RestParameter("contact[id]", this.Id)); pars.Add(new RestParameter("contact[email]", this.Email)); pars.Add(new RestParameter("contact[name]", this.Name)); pars.Add(new RestParameter("contact[internal_id]", this.InternalId)); pars.Add(new RestParameter("contact[company]", this.Company)); pars.Add(new RestParameter("contact[position]", this.Position)); pars.Add(new RestParameter("contact[sex]", this.Sex)); pars.Add(new RestParameter("contact[birthday]", string.Format("{0:yyyy-MM-dd}", this.Birthday))); pars.Add(new RestParameter("contact[age]", this.Age)); pars.Add(new RestParameter("contact[phone]", this.Phone)); pars.Add(new RestParameter("contact[mobile]", this.Mobile)); pars.Add(new RestParameter("contact[address]", this.Address)); pars.Add(new RestParameter("contact[notes]", this.Notes)); foreach (KeyValuePair<string, string> dynamicValue in this.DynamicValues) pars.Add(new RestParameter(string.Format("contact[dynamic_attributes][{0}]", dynamicValue.Key), dynamicValue.Value)); //Post Data string result = Mailee.Rest.put(url, pars); return result; }
/// <summary> /// Find all Contacts with pagination /// </summary> /// <param name="page">Page</param> public static List<Mailee.Contact> findAll(int page) { List<Mailee.Contact> contacts = new List<Mailee.Contact>(); //URL (GET) (api.XXXXXXXXXXXXX.subdomain.mailee.me/contacts) string url = string.Format("{0}contacts.xml?page={1}", Mailee.Config.UrlAPI, page); //Get data string htmlReponse = Mailee.Rest.get(url); //Create XML XmlDocument xmlDoc = new XmlDocument(); //Load XML xmlDoc.LoadXml(htmlReponse); //Get Contacts XmlNodeList xmlContacts = xmlDoc.GetElementsByTagName("contact"); //Each Contacts foreach (XmlNode xmlContact in xmlContacts) { //Create new Concat Mailee.Contact newContact = new Mailee.Contact(); //Set properties newContact.Address = xmlContact.ChildNodes[0].InnerText; newContact.Age = Mailee.Util.parseInt(xmlContact.ChildNodes[1].InnerText); newContact.Birthday = Mailee.Util.parseDateTime(xmlContact.ChildNodes[2].InnerText); newContact.ClientId = Mailee.Util.parseInt(xmlContact.ChildNodes[3].InnerText); newContact.Company = xmlContact.ChildNodes[4].InnerText; newContact.ContactStatusId = Mailee.Util.parseInt(xmlContact.ChildNodes[5].InnerText); newContact.CreatedAt = Mailee.Util.parseDateTime(xmlContact.ChildNodes[6].InnerText); newContact.DeletedAt = Mailee.Util.parseDateTime(xmlContact.ChildNodes[7].InnerText); //contact.DynamicValues = xmlContact.ChildNodes[8].InnerText; newContact.Email = xmlContact.ChildNodes[9].InnerText; newContact.FacebookFollowers = Mailee.Util.parseInt(xmlContact.ChildNodes[10].InnerText); newContact.ForwardedBy = Mailee.Util.parseInt(xmlContact.ChildNodes[11].InnerText); newContact.GoodreadsConnections = Mailee.Util.parseInt(xmlContact.ChildNodes[12].InnerText); newContact.Id = Mailee.Util.parseInt(xmlContact.ChildNodes[13].InnerText); newContact.ImportId = Mailee.Util.parseInt(xmlContact.ChildNodes[14].InnerText); newContact.InternalId = Mailee.Util.parseInt(xmlContact.ChildNodes[15].InnerText); newContact.Kscore = Mailee.Util.parseFloat(xmlContact.ChildNodes[16].InnerText); newContact.Latitude = Mailee.Util.parseDecimal(xmlContact.ChildNodes[17].InnerText); newContact.LinkedinFollowers = Mailee.Util.parseInt(xmlContact.ChildNodes[18].InnerText); newContact.LinkedinRecomendations = Mailee.Util.parseInt(xmlContact.ChildNodes[19].InnerText); newContact.Longitude = Mailee.Util.parseDecimal(xmlContact.ChildNodes[20].InnerText); newContact.Mobile = xmlContact.ChildNodes[21].InnerText; newContact.Name = xmlContact.ChildNodes[22].InnerText; newContact.Notes = xmlContact.ChildNodes[23].InnerText; newContact.OriginId = Mailee.Util.parseInt(xmlContact.ChildNodes[24].InnerText); newContact.OrkutFollowers = Mailee.Util.parseInt(xmlContact.ChildNodes[25].InnerText); newContact.Phone = xmlContact.ChildNodes[26].InnerText; newContact.PhotoContentType = xmlContact.ChildNodes[27].InnerText; newContact.PhotoFileName = xmlContact.ChildNodes[28].InnerText; newContact.PhotoFileSize = Mailee.Util.parseInt(xmlContact.ChildNodes[29].InnerText); newContact.PhotoUpdatedAt = Mailee.Util.parseDateTime(xmlContact.ChildNodes[30].InnerText); newContact.PlaxoConnections = Mailee.Util.parseInt(xmlContact.ChildNodes[31].InnerText); newContact.Position = xmlContact.ChildNodes[32].InnerText; newContact.Sex = xmlContact.ChildNodes[33].InnerText; newContact.SkoobConnections = Mailee.Util.parseInt(xmlContact.ChildNodes[34].InnerText); newContact.TwitterFollowers = Mailee.Util.parseInt(xmlContact.ChildNodes[35].InnerText); newContact.UpdatedAt = Mailee.Util.parseDateTime(xmlContact.ChildNodes[36].InnerText); //Add Contact contacts.Add(newContact); } return contacts; }
/// <summary> /// Create New Contact /// </summary> private string Create() { //URL (POST) (api.XXXXXXXXXXXXX.subdomain.mailee.me/contacts.xml) string url = string.Concat(Mailee.Config.UrlAPI, "contacts.xml"); //Create url params List<RestParameter> pars = new List<RestParameter>(); pars.Add(new RestParameter("contact[email]", this.Email)); pars.Add(new RestParameter("contact[name]", this.Name)); pars.Add(new RestParameter("contact[internal_id]", this.InternalId)); pars.Add(new RestParameter("contact[company]", this.Company)); pars.Add(new RestParameter("contact[position]", this.Position)); pars.Add(new RestParameter("contact[sex]", this.Sex)); pars.Add(new RestParameter("contact[birthday]", string.Format("{0:yyyy-MM-dd}", this.Birthday))); pars.Add(new RestParameter("contact[age]", this.Age)); pars.Add(new RestParameter("contact[phone]", this.Phone)); pars.Add(new RestParameter("contact[mobile]", this.Mobile)); pars.Add(new RestParameter("contact[address]", this.Address)); pars.Add(new RestParameter("contact[notes]", this.Notes)); foreach (KeyValuePair<string, string> dynamicValue in this.DynamicValues) pars.Add(new RestParameter(string.Format("contact[dynamic_attributes][{0}]", dynamicValue.Key), dynamicValue.Value)); //Post Data string result = Mailee.Rest.post(url, pars); #region Fill Contact Data //Checks if the xml is valid bool isValidXml = Mailee.Util.IsValidXML(result); if (isValidXml == true) { //Create XML System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); //Load XML xmlDoc.LoadXml(result); //Get Contact System.Xml.XmlNodeList xmlContacts = xmlDoc.GetElementsByTagName("contact"); if (xmlContacts.Count > 0) { System.Xml.XmlNode xmlContact = xmlContacts[0]; //Set properties this.Id = Mailee.Util.parseInt(xmlContact.ChildNodes[13].InnerText); } } #endregion return result; }
/// <summary> /// Unsubscribe to list /// </summary> /// <param name="listId">List Id</param> public string Unsubscribe(int listId) { //URL (PUT) (api.XXXXXXXXXXXXX.subdomain.mailee.me/contacts/ID/list_unsubscribe.xml) string url = string.Format("{0}contacts/{1}/list_unsubscribe.xml", Mailee.Config.UrlAPI, this.Id); //Create url params List<RestParameter> pars = new List<RestParameter>(); pars.Add(new RestParameter("list_id", listId)); //Post Data string result = Mailee.Rest.put(url, pars); return result; }
/// <summary> /// Makes an HTTP PUT /// </summary> /// <param name="url">URL</param> /// <param name="parameters">Parameters</param> public static string put(string url, List<RestParameter> parameters) { //Add parameter '_method=put' parameters.Add(new RestParameter("_method", "put")); //Make HTTP Post return post(url, parameters); }
/// <summary> /// Update existing List /// </summary> private string update() { //URL (PUT) (api.XXXXXXXXXXXXX.subdomain.mailee.me/lists) string url = string.Format("{0}lists/{1}.xml", Mailee.Config.UrlAPI, this.Id); //Create url params List<RestParameter> pars = new List<RestParameter>(); pars.Add(new RestParameter("list[id]", this.Id)); pars.Add(new RestParameter("list[name]", this.Name)); pars.Add(new RestParameter("list[company]", this.Company)); pars.Add(new RestParameter("list[site]", this.Site)); pars.Add(new RestParameter("list[facebook]", this.Facebook)); pars.Add(new RestParameter("list[twitter]", this.Twitter)); pars.Add(new RestParameter("list[address]", this.Address)); pars.Add(new RestParameter("list[phone]", this.Phone)); pars.Add(new RestParameter("list[description]", this.Description)); pars.Add(new RestParameter("list[active]", this.Active.ToString().ToLower())); //Post Data string result = Mailee.Rest.put(url, pars); return result; }
/// <summary> /// Find all Lists /// </summary> public static List<Mailee.List> findAll() { List<Mailee.List> lists = new List<Mailee.List>(); //URL (GET) (api.XXXXXXXXXXXXX.subdomain.mailee.me/lists) string url = string.Concat(Mailee.Config.UrlAPI, "lists.xml"); //Get data string htmlReponse = Mailee.Rest.get(url); //Create XML XmlDocument xmlDoc = new XmlDocument(); //Load XML xmlDoc.LoadXml(htmlReponse); //Get Lists XmlNodeList xmlLists = xmlDoc.GetElementsByTagName("list"); //Each Lists foreach (XmlNode xmlList in xmlLists) { //Create new List Mailee.List newList = new Mailee.List(); //Set properties newList.Active = Mailee.Util.parseBool(xmlList.ChildNodes[0].InnerText); newList.Address = xmlList.ChildNodes[1].InnerText; newList.ClientId = Mailee.Util.parseInt(xmlList.ChildNodes[2].InnerText); newList.Company = xmlList.ChildNodes[3].InnerText; newList.CreatedAt = Mailee.Util.parseDateTime(xmlList.ChildNodes[4].InnerText); newList.DeletedAt = Mailee.Util.parseDateTime(xmlList.ChildNodes[5].InnerText); newList.Description = xmlList.ChildNodes[6].InnerText; newList.Facebook = xmlList.ChildNodes[7].InnerText; newList.Id = Mailee.Util.parseInt(xmlList.ChildNodes[8].InnerText); newList.ListsContactsCount = Mailee.Util.parseInt(xmlList.ChildNodes[10].InnerText); newList.Name = xmlList.ChildNodes[11].InnerText; newList.Phone = xmlList.ChildNodes[12].InnerText; newList.Site = xmlList.ChildNodes[13].InnerText; newList.Total = Mailee.Util.parseInt(xmlList.ChildNodes[14].InnerText); newList.Twitter = xmlList.ChildNodes[15].InnerText; //Add List lists.Add(newList); } return lists; }