public static async Task <SubscriberInfo> AddSubscriber() { var credential = new RestCredentialInfo(); credential.ReadFromConfiguration(); var subscriberInfo = new SubscriberInfo { EmailAddress = "*****@*****.**", Status = "subscribed" }; var mergeFieldInfo = new MergeFieldInfo(); mergeFieldInfo.FirstName = "Kim"; mergeFieldInfo.LastName = "Jung"; subscriberInfo.MergeFields = new MergeFieldInfo { FirstName = "Kim", LastName = "Jung" }; var result = await Subscriber.Subscribe( credential, subscriberInfo, "Site Registration" ); return(result); }
public static async Task <TwilioMessage> GetMessageInfo() { var smsInfo = new RestCredentialInfo(); smsInfo.ReadFromConfiguration(); var twilioMessage = await Twilio.GetMessage(smsInfo, "SM1e8208f4b4e44720bafc9ea0334eb72d"); return(twilioMessage); }
public static async Task <ListsInfo> GetMailChimpLists() { var credential = new RestCredentialInfo(); credential.ReadFromConfiguration(); var lists = await Lists.GetLists(credential); return(lists); }
public static async Task SendMessage() { var twilioMessage = new TwilioMessage(); twilioMessage.ReadFromConfiguration(); twilioMessage.Message = "All in the game"; var smsInfo = new RestCredentialInfo(); smsInfo.ReadFromConfiguration(); message = await Twilio.SendMessage(smsInfo, twilioMessage); }
public static async Task <ListsInfo> GetLists( RestCredentialInfo restCredentialInfo) { var restCredential = new Rest( "dummy", restCredentialInfo.MailChimpApiKey); var url = string.Format( GetUrl, restCredentialInfo.MailChimpLocation); var response = await restCredential.GetAsync( url); var responseContent = await response.Content.ReadAsStringAsync(); var fetch = JsonConvert.DeserializeObject <ListsInfo>(responseContent); //var listsInfo = fetch.First(); return(fetch); }
public static async Task <SubscriberInfo> Subscribe( RestCredentialInfo restCredentialInfo, SubscriberInfo subscriberInfo, string listName) { var restCredential = new Rest( "dummy", restCredentialInfo.MailChimpApiKey); var lists = await Lists.GetLists(restCredentialInfo); string listId = string.Empty; if (lists != null) { foreach (ListInfo list in lists.Lists) { if (list.Name == listName) { listId = list.Id; break; } } } if (string.IsNullOrEmpty(listId)) { throw new Exception($"Could not find the list: {listName}"); } var url = string.Format( PostUrl, restCredentialInfo.MailChimpLocation, listId); var stringContent = new StringContent(JsonConvert.SerializeObject(subscriberInfo)); var response = await restCredential.PostAsync( url, stringContent); var responseContent = await response.Content.ReadAsStringAsync(); return(null); }
public static async Task <TwilioMessage> SendMessage( RestCredentialInfo restCredentialInfo, TwilioMessage twilioMessage) { var restCredential = new Rest( restCredentialInfo.AccountId, restCredentialInfo.SecretKey); var url = string.Format( SmsPostUrl, restCredentialInfo.AccountId); var content = new StringContent(twilioMessage.ToMessageString()); var response = await restCredential.PostAsync( url, content); var responseContent = await response.Content.ReadAsStringAsync(); var xmlDoc = new XmlDocument(); xmlDoc.LoadXml( responseContent); if (!response.IsSuccessStatusCode) { var restException = new TwilioException(); try { restException.Code = Convert.ToInt32( xmlDoc.SelectSingleNode( "TwilioResponse/RestException/Code") .InnerText); restException.Message = xmlDoc.SelectSingleNode( "TwilioResponse/RestException/Message").InnerText; restException.MoreInfo = xmlDoc.SelectSingleNode( "TwilioResponse/RestException/MoreInfo").InnerText; restException.Status = Convert.ToInt32( xmlDoc.SelectSingleNode( "TwilioResponse/RestException/Status") .InnerText); } catch (Exception ex) { restException = new TwilioException { Code = 0, Message = ex.Message, MoreInfo = "", Status = 0 }; } twilioMessage.Status = "failed"; twilioMessage.RestException = restException; } else { try { twilioMessage.ReturnSid = xmlDoc.SelectSingleNode( "TwilioResponse/Message/Sid").InnerText; twilioMessage.Created = Convert.ToDateTime( xmlDoc.SelectSingleNode( "TwilioResponse/Message/DateCreated") .InnerText); twilioMessage.Updated = Convert.ToDateTime( xmlDoc.SelectSingleNode( "TwilioResponse/Message/DateUpdated") .InnerText); var sentValue = xmlDoc.SelectSingleNode( "TwilioResponse/Message/DateSent"); if (sentValue.Value != null) { twilioMessage.Sent = Convert.ToDateTime(sentValue.InnerText); } twilioMessage.NumberOfSms = Convert.ToInt32( xmlDoc.SelectSingleNode( "TwilioResponse/Message/NumSegments") .InnerText); twilioMessage.Direction = xmlDoc.SelectSingleNode( "TwilioResponse/Message/Direction").InnerText; twilioMessage.Status = xmlDoc.SelectSingleNode( "TwilioResponse/Message/Status").InnerText; } catch (Exception ex) { } } return(twilioMessage); }
public static async Task <TwilioMessage> GetMessage( RestCredentialInfo restCredentialInfo, string messageId) { var restCredential = new Rest( restCredentialInfo.AccountId, restCredentialInfo.SecretKey); var url = string.Format( SmsGetUrl, restCredentialInfo.AccountId, messageId); var response = await restCredential.GetAsync( url); var responseContent = await response.Content.ReadAsStringAsync(); var twilioMessage = new TwilioMessage(); var xmlDoc = new XmlDocument(); xmlDoc.LoadXml( responseContent); if (response.IsSuccessStatusCode) { try { twilioMessage.ReturnSid = xmlDoc.SelectSingleNode( "TwilioResponse/Message/Sid").InnerText; twilioMessage.Created = Convert.ToDateTime( xmlDoc.SelectSingleNode( "TwilioResponse/Message/DateCreated") .InnerText); twilioMessage.Updated = Convert.ToDateTime( xmlDoc.SelectSingleNode( "TwilioResponse/Message/DateUpdated") .InnerText); twilioMessage.Sent = Convert.ToDateTime( xmlDoc.SelectSingleNode( "TwilioResponse/Message/DateSent") .InnerText); twilioMessage.From = xmlDoc.SelectSingleNode( "TwilioResponse/Message/From").InnerText; twilioMessage.To = xmlDoc.SelectSingleNode( "TwilioResponse/Message/To").InnerText; twilioMessage.Message = xmlDoc.SelectSingleNode( "TwilioResponse/Message/Body").InnerText; twilioMessage.NumberOfSms = Convert.ToInt32(xmlDoc.SelectSingleNode( "TwilioResponse/Message/NumSegments").InnerText); twilioMessage.Status = xmlDoc.SelectSingleNode( "TwilioResponse/Message/Status").InnerText; twilioMessage.Direction = xmlDoc.SelectSingleNode( "TwilioResponse/Message/Direction").InnerText; var errorCode = xmlDoc.SelectSingleNode( "TwilioResponse/Message/ErrorCode"); if (errorCode != null) { var twilioException = new TwilioException() { Code = Convert.ToInt32(errorCode.InnerText), Message = xmlDoc.SelectSingleNode( "TwilioResponse/Message/ErrorMessage").InnerText }; twilioMessage.RestException = twilioException; } } catch { } } return(twilioMessage); }