本文整理汇总了C#中API.Send方法的典型用法代码示例。如果您正苦于以下问题:C# API.Send方法的具体用法?C# API.Send怎么用?C# API.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API
的用法示例。
在下文中一共展示了API.Send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReceiveSms
private async Task<dynamic> ReceiveSms()
{
var smsMessage = this.Bind<SmsMessage>();
var result = _smsRepository.FindByMessageId(smsMessage.Msg_ID);
if (result != null) return HttpStatusCode.OK;
_smsRepository.Add(smsMessage);
var response = await HandleSms(smsMessage);
var clockworkApi = new API("508ed11cab000a796881e015fc5e022daf1bb6d3");
if (!string.IsNullOrWhiteSpace(response))
{
clockworkApi.Send(new SMS { To = smsMessage.From, Message = response });
}
else
{
clockworkApi.Send(new SMS { To = smsMessage.From, Message = "Thanks for playing. You will stop receiving messages." });
}
return HttpStatusCode.OK;
}
示例2: SendMessage
public ActionResult SendMessage(MessageToSend msg)
{
try
{
if (msg.to != null && msg.body != null)
{
Clockwork.API api = new API(apiKey);
SMSResult result = api.Send(new Clockwork.SMS { To = msg.to, Message = "Hello World" });
if (result.Success){
ViewBag.result = result;
return View();
//Console.WriteLine("SMS Sent to {0}, Clockwork ID: {1}", result.SMS.To, result.ID);
}
else
Console.WriteLine("SMS to {0} failed, Clockwork Error: {1} {2}", result.SMS.To, result.ErrorCode, result.ErrorMessage);
}
}
catch (APIException ex)
{
// You'll get an API exception for errors
// such as wrong username or password
Console.WriteLine("API Exception: " + ex.Message);
}
catch (WebException ex)
{
// Web exceptions mean you couldn't reach the Clockwork server
Console.WriteLine("Web Exception: " + ex.Message);
}
catch (ArgumentException ex)
{
// Argument exceptions are thrown for missing parameters,
// such as forgetting to set the username
Console.WriteLine("Argument Exception: " + ex.Message);
}
catch (Exception ex)
{
// Something else went wrong, the error message should help
Console.WriteLine("Unknown Exception: " + ex.Message);
}
return View("/");
}
示例3: sendMessage_Click
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);
}
}
示例4: Send
public void Send(string number, string body)
{
try
{
Clockwork.API api = new API("e26d24050e1147c7f8a57bdeeb574581dd5ca5f1");
SMSResult result = api.Send(
new SMS
{
To = number,
Message = body
});
if (!result.Success)
{
throw new Exception(result.ErrorMessage);
}
}
catch (APIException ex)
{
// You’ll get an API exception for errors
// such as wrong username or password
Console.WriteLine("API Exception: " + ex.Message);
}
catch (WebException ex)
{
// Web exceptions mean you couldn’t reach the Clockwork server
Console.WriteLine("Web Exception: " + ex.Message);
}
catch (ArgumentException ex)
{
// Argument exceptions are thrown for missing parameters,
// such as forgetting to set the username
Console.WriteLine("Argument Exception: " + ex.Message);
}
catch (Exception ex)
{
// Something else went wrong, the error message should help
Console.WriteLine("Unknown Exception: " + ex.Message);
}
}
示例5: SendSmsToVolunteer
public static void SendSmsToVolunteer(int volunteerId)
{
var volunteer = VolunteerRepository.Get(volunteerId);
if (volunteer != null)
{
var mobile = volunteer.Mobile.Replace(" ", "");
var api = new API(ClockworkSmsKey);
var result = api.Send(
new SMS
{
To = mobile,
Message = "Go help Granny Smith!"
});
if (!result.Success)
{
Debug.WriteLine($"Failed to send SMS to {mobile}");
Debug.WriteLine($"Clockwork SMS ErrorCode: {result.ErrorCode}");
Debug.WriteLine($"Clockwork SMS ErrorMessage: {result.ErrorMessage}");
}
}
}
示例6: SendOneSMS_UseProxy
public void SendOneSMS_UseProxy()
{
string proxyHost = "";
int proxyPort = 0;
proxyHost = System.Configuration.ConfigurationManager.AppSettings["ProxyHost"];
if (String.IsNullOrWhiteSpace(proxyHost))
Assert.Inconclusive("Proxy host not configured - Skipping test");
string proxyPortTemp = System.Configuration.ConfigurationManager.AppSettings["ProxyPort"];
if (String.IsNullOrWhiteSpace(proxyPortTemp))
Assert.Inconclusive("Proxy port not configured - Skipping test");
if(!int.TryParse(proxyPortTemp, out proxyPort))
Assert.Inconclusive("Proxy port could not be parsed - Skipping test");
Clockwork.API api = new API(key);
api.Proxy = new System.Net.WebProxy(proxyHost, proxyPort);
SMSResult result = api.Send(new SMS { To = "44123457890", Message = "Hello World" });
Assert.IsTrue(result.Success);
}
示例7: SendOneSMS_Single
public void SendOneSMS_Single()
{
Clockwork.API api = new API(key);
SMSResult result = api.Send(new SMS { To = "441234567890", Message = "Hello World" });
Assert.IsTrue(result.Success);
}
示例8: SendOneSMS_Response_Matches_Send
public void SendOneSMS_Response_Matches_Send()
{
Clockwork.API api = new API(key);
List<SMS> smsList = new List<SMS>();
SMS sms = new SMS { To = "441234567891", Message = "Hello World" };
smsList.Add(sms);
List<SMSResult> result = api.Send(smsList);
Assert.AreSame(sms, result[0].SMS);
}
示例9: SendOneSMS_List
public void SendOneSMS_List()
{
Clockwork.API api = new API(key);
List<SMS> sms = new List<SMS>();
sms.Add(new SMS { To = "441234567891", Message = "Hello World" });
List<SMSResult> result = api.Send(sms);
Assert.IsTrue(result[0].Success);
}
示例10: SendOneSMS_InvalidNumber
public void SendOneSMS_InvalidNumber()
{
Clockwork.API api = new API(key);
SMSResult result = api.Send(new SMS { To = "not_a_number", Message = "Hello World" });
Assert.IsNotNull(result);
Assert.IsFalse(result.Success);
Assert.AreEqual(10, result.ErrorCode);
}
示例11: SendNullSMS_Single
public void SendNullSMS_Single()
{
Clockwork.API api = new API(key);
SMS sms = null;
SMSResult result = api.Send(sms);
}
示例12: SendNullSMS_List
public void SendNullSMS_List()
{
Clockwork.API api = new API(key);
List<SMS> smsList = null;
List<SMSResult> result = api.Send(smsList);
}
示例13: SendMultiSMS_Success
public void SendMultiSMS_Success()
{
Clockwork.API api = new API(key);
List<SMS> smsList = new List<SMS>();
smsList.Add(new SMS { To = "441234567891", Message = "Hello World" });
smsList.Add(new SMS { To = "441234567892", Message = "Hello World" });
List<SMSResult> result = api.Send(smsList);
Assert.IsTrue(result[0].Success && result[1].Success);
}
示例14: SendMultiSMS_BothNoMessage
public void SendMultiSMS_BothNoMessage()
{
Clockwork.API api = new API(key);
List<SMS> smsList = new List<SMS>();
smsList.Add(new SMS { To = "441234567891" });
smsList.Add(new SMS { To = "441234567892" });
List<SMSResult> result = api.Send(smsList);
Assert.IsFalse(result[0].Success || result[1].Success);
}
示例15: SendEmptySMS_List
public void SendEmptySMS_List()
{
List<SMS> sms = new List<SMS>();
Clockwork.API api = new API(key);
List<SMSResult> result = api.Send(sms);
}