private void sendMessage_Click(object sender, EventArgs e) { try { API api = new API(key.Text); SMS sms = new SMS { To = to.Text, Message = message.Text }; SMSResult result = api.Send(sms); if (result.Success) MessageBox.Show("Sent\nID: " + result.ID); else MessageBox.Show("Error: " + result.ErrorMessage); } catch (APIException ex) { // You'll get an API exception for errors // such as wrong key MessageBox.Show("API Exception: " + ex.Message); } catch (WebException ex) { // Web exceptions mean you couldn't reach the mediaburst server MessageBox.Show("Web Exception: " + ex.Message); } catch (ArgumentException ex) { // Argument exceptions are thrown for missing parameters, // such as forgetting to set the username MessageBox.Show("Argument Exception: " + ex.Message); } catch (Exception ex) { // Something else went wrong, the error message should help MessageBox.Show("Unknown Exception: " + ex.Message); } }
public void Send(SMS sms) { var api = new Clockwork.API(""); api.Send(sms); }
private ResultModel Send(string phoneNumber, string from, string message) { var resultModel = new ResultModel(); if (!Convert.ToBoolean(ConfigurationManager.AppSettings["useApi"])) { resultModel.Success = true; resultModel.Message = "API usage is currently turned off."; return resultModel; } try { var api = new API("832c41038f002083db24aa54f567244c9c6c5375"); var sms = new SMS { To = phoneNumber, From = from, Message = message }; var result = api.Send(sms); if (result.Success) { resultModel.Message = $"SMS Sent to {result.SMS.To}. Clockwork ID: {result.ID}"; resultModel.Success = true; } else { resultModel.Message = $"SMS to {result.SMS.To} failed. " + $"Clockwork Error: {result.ErrorCode} {result.ErrorMessage}"; } } catch (APIException ex) { // You’ll get an API exception for errors // such as wrong username or password resultModel.Message = "API Exception: " + ex.Message; } catch (WebException ex) { // Web exceptions mean you couldn’t reach the Clockwork server resultModel.Message = "Web Exception: " + ex.Message; } catch (ArgumentException ex) { // Argument exceptions are thrown for missing parameters, // such as forgetting to set the username resultModel.Message = "Argument Exception: " + ex.Message; } catch (Exception ex) { // Something else went wrong, the error message should help resultModel.Message = "Unknown Exception: " + ex.Message; } return resultModel; }