/// <summary> /// Check to see if the given phone digits are /// indeed a cell phone. /// </summary> /// <param name="user">The user identity (api key) to authenticate with the provider.</param> /// <param name="password">The user password (secondary key) to authenticate with the provider.</param> /// <param name="digits">The phone number digits to check for a cell.</param> /// <returns>Indicates whether or not the digits are a cell.</returns> public bool IsACell(string user, string password, string digits) { if (String.IsNullOrEmpty(user)) { this.ApplyResponse(HttpStatusCode.InternalServerError, "Api user name is missing or empty."); return(false); } if (String.IsNullOrEmpty(password)) { this.ApplyResponse(HttpStatusCode.InternalServerError, "Api user passsword is missing or empty."); return(false); } this.auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(String.Format("{0}:{1}", user, password))); this.confirmed = false; HttpTransceiver adapter = new HttpTransceiver(); adapter.OnRequestInitialized += this.RequestInitialized; adapter.OnRequestComplete += this.PreviewRequestComplete; adapter.OnRequestError += this.PreviewRequestError; string url = String.Format("{0}{1}{2}", om.Default.api_base_url, om.Default.confirm_method_name, digits); adapter.Get(url, typeof(PreviewResponse)); return(this.confirmed); }
//[TestInitialize] public void Init() { mailResponder = new MailResponder(); server = new HttpListenerServer(new string[] { URL }, mailResponder); server.Start(); HttpWebRequest requestTemplate = (HttpWebRequest)HttpWebRequest.Create(URL); requestTemplate.Timeout = 6000; requestTemplate.Proxy = null; transceiver = new HttpTransceiver(requestTemplate); proxy = new GenericRequestor(transceiver, MailResponder.Protocol); }
/// <summary> /// Send a messsage to a cell recipient. /// </summary> /// <param name="user">The user identity (api key) to authenticate with the provider.</param> /// <param name="password">The user password (secondary key) to authenticate with the provider.</param> /// <param name="to">The cell phone number to send the message to.</param> /// <param name="from">The long or short code to send the message from.</param> /// <param name="message">The SMS message content.</param> /// <param name="reference">An optional reference to associate and keep with the message.</param> /// <param name="note">An optional note to associate and keep with the message.</param> /// <returns>Indicates the success or failure of the send.</returns> public bool Send(string user, string password, string to, string from, string message, string reference, string note) { if (String.IsNullOrEmpty(user)) { this.ApplyResponse(HttpStatusCode.InternalServerError, "Api user name is missing or empty."); return(false); } if (String.IsNullOrEmpty(password)) { this.ApplyResponse(HttpStatusCode.InternalServerError, "Api user passsword is missing or empty."); return(false); } this.auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(String.Format("{0}:{1}", user, password))); this.sent = false; SendRequest request = new SendRequest(); request.payload.destination.address = to; request.payload.source.address = from; request.payload.source.type = 1; // 1 = long code, 3 = short code request.payload.message.content = message; request.payload.message.type = "text"; if ((!String.IsNullOrEmpty(reference)) || (!String.IsNullOrEmpty(note))) { request.payload.options = new SendOptions(); request.payload.options.note1 = reference; request.payload.options.note2 = note; } HttpTransceiver adapter = new HttpTransceiver(); adapter.OnRequestInitialized += this.RequestInitialized; adapter.OnRequestComplete += this.SendRequestComplete; adapter.OnRequestError += this.SendRequestError; string url = String.Format("{0}{1}", om.Default.api_base_url, om.Default.send_method_name); adapter.Post(url, typeof(SendRequest), request, typeof(SendResponse)); return(this.sent); }
/// <summary> /// /// </summary> /// <param name="user"></param> /// <param name="password"></param> /// <param name="to"></param> /// <param name="from"></param> /// <param name="filePath"></param> /// <param name="b64Filedata"></param> /// <param name="description"></param> /// <returns></returns> public bool Media(string user, string password, string to, string from, string filePath, string b64Filedata, string description) { if (String.IsNullOrEmpty(user)) { this.ApplyResponse(HttpStatusCode.InternalServerError, "Api user name is missing or empty."); return(false); } if (String.IsNullOrEmpty(password)) { this.ApplyResponse(HttpStatusCode.InternalServerError, "Api user passsword is missing or empty."); return(false); } this.auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(String.Format("{0}:{1}", user, password))); this.sent = false; MediaRequest request = new MediaRequest(to, from, filePath, b64Filedata, description); request.OnHttpResponse += this.ApplyResponse; request.OnPostEntry += this.PostEntry; if (request.IsNotValid()) { return(false); } HttpTransceiver adapter = new HttpTransceiver(); adapter.OnRequestInitialized += this.RequestInitialized; adapter.OnRequestComplete += this.SendRequestComplete; adapter.OnRequestError += this.SendRequestError; string url = String.Format("{0}{1}", om.Default.api_base_url, om.Default.mms_method_name); adapter.Post(url, typeof(string), request.Serialize(), typeof(MediaResponse)); return(this.sent); }