本文整理汇总了Java中com.twilio.sdk.TwilioRestResponse类的典型用法代码示例。如果您正苦于以下问题:Java TwilioRestResponse类的具体用法?Java TwilioRestResponse怎么用?Java TwilioRestResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TwilioRestResponse类属于com.twilio.sdk包,在下文中一共展示了TwilioRestResponse类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendNotification
import com.twilio.sdk.TwilioRestResponse; //导入依赖的package包/类
public Hashtable sendNotification(Notification notification, Device device) throws NotificationException {
try {
if (!(device instanceof TwilioDevice)) {
throw new NotificationException(NotificationException.NOT_ACCEPTABLE, "Supplied device is not a Twilio device");
}
String message = "You have a new notification from " + notification.getSender() + ". The subject is " + notification.getSubject()
+ ". The message is " + notification.getMessages()[0].getMessage() + ".";
String url = "http://twimlets.com/message?Message%5B0%5D=" + URLEncoder.encode(message);
TwilioDevice twilio = (TwilioDevice) device;
String accountSid = BrokerFactory.getConfigurationBroker().getStringValue("twilio.sid");
String authToken = BrokerFactory.getConfigurationBroker().getStringValue("twilio.token");
BrokerFactory.getLoggingBroker().logDebug("Sid="+accountSid);
BrokerFactory.getLoggingBroker().logDebug("token="+authToken);
TwilioRestClient client = new TwilioRestClient(accountSid, authToken);
Map<String, String> params = new HashMap<String, String>();
params.put("To", twilio.getPhoneNumber());
params.put("From", BrokerFactory.getConfigurationBroker().getStringValue("twilio.phone.from", "(720)530-8877"));
params.put("Url", url);
TwilioRestResponse response;
response = client.request("/" + APIVERSION + "/Accounts/" + client.getAccountSid() + "/Calls", "POST", params);
if (response.isError())
System.out.println("Error making outgoing call: " + response.getHttpStatus() + "\n" + response.getResponseText());
else {
BrokerFactory.getLoggingBroker().logDebug(response.getResponseText());
}
Hashtable<String, String> tracking = new Hashtable<String, String>();
tracking.put("ID", "");
return tracking;
} catch (TwilioRestException e) {
// TODO Auto-generated catch block
throw new NotificationException(400, e.getErrorMessage());
}
}