Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.voxeo.tropo.Tropo Maven / Gradle / Ivy
package com.voxeo.tropo;
import static com.voxeo.tropo.Key.BARGEIN;
import static com.voxeo.tropo.Key.BEEP;
import static com.voxeo.tropo.Key.CHANNEL;
import static com.voxeo.tropo.Key.EVENT;
import static com.voxeo.tropo.Key.EXIT_TONE;
import static com.voxeo.tropo.Key.FORMAT;
import static com.voxeo.tropo.Key.FROM;
import static com.voxeo.tropo.Key.MILLISECONDS;
import static com.voxeo.tropo.Key.NAME;
import static com.voxeo.tropo.Key.NETWORK;
import static com.voxeo.tropo.Key.NEXT;
import static com.voxeo.tropo.Key.PASSWORD;
import static com.voxeo.tropo.Key.REQUIRED;
import static com.voxeo.tropo.Key.SEND_TONES;
import static com.voxeo.tropo.Key.SENSITIVITY;
import static com.voxeo.tropo.Key.TIMEOUT;
import static com.voxeo.tropo.Key.TO;
import static com.voxeo.tropo.Key.URL;
import static com.voxeo.tropo.Key.USERNAME;
import static com.voxeo.tropo.Key.VALUE;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.client.HttpClient;
import support.ActionSupportHandler;
import com.voxeo.tropo.actions.ArrayBackedJsonAction;
import com.voxeo.tropo.actions.AskAction;
import com.voxeo.tropo.actions.CallAction;
import com.voxeo.tropo.actions.ChoicesAction;
import com.voxeo.tropo.actions.ConferenceAction;
import com.voxeo.tropo.actions.MessageAction;
import com.voxeo.tropo.actions.OnAction;
import com.voxeo.tropo.actions.RecordAction;
import com.voxeo.tropo.actions.RedirectAction;
import com.voxeo.tropo.actions.SayAction;
import com.voxeo.tropo.actions.StartRecordingAction;
import com.voxeo.tropo.actions.TransferAction;
import com.voxeo.tropo.actions.WaitAction;
import com.voxeo.tropo.enums.Channel;
import com.voxeo.tropo.enums.Format;
import com.voxeo.tropo.enums.LogSecurityState;
import com.voxeo.tropo.enums.Network;
public class Tropo extends ArrayBackedJsonAction {
private TropoParser parser;
private String baseUrl = "https://api.tropo.com/v1/";
private ActionSupportHandler sayActionSupportHandler = new ActionSupportHandler(SayAction.class);
private ActionSupportHandler askActionSupportHandler = new ActionSupportHandler(AskAction.class);
private ActionSupportHandler conferenceActionSupportHandler = new ActionSupportHandler(ConferenceAction.class);
private ActionSupportHandler choicesActionSupportHandler = new ActionSupportHandler(ChoicesAction.class);
private ActionSupportHandler onActionSupportHandler = new ActionSupportHandler(OnAction.class);
private ActionSupportHandler recordActionSupportHandler = new ActionSupportHandler(RecordAction.class);
private ActionSupportHandler redirectActionSupportHandler = new ActionSupportHandler(RedirectAction.class);
private ActionSupportHandler startRecordingActionSupportHandler = new ActionSupportHandler(StartRecordingAction.class);
private ActionSupportHandler transferActionSupportHandler = new ActionSupportHandler(TransferAction.class);
private ActionSupportHandler callActionSupportHandler = new ActionSupportHandler(CallAction.class);
private ActionSupportHandler messageActionSupportHandler = new ActionSupportHandler(MessageAction.class);
private ActionSupportHandler waitActionSupportHandler = new ActionSupportHandler(WaitAction.class);
public Tropo() {
super("tropo");
parser = new TropoParser();
}
public SayAction say(String text) {
return say(VALUE(text));
}
public SayAction say(Key... keys) {
return sayActionSupportHandler.build(this, "tropo", keys);
}
public AskAction ask(Key... keys) {
return askActionSupportHandler.build(this, "tropo", keys);
}
/**
* @deprecated A choices and a say are required.
* @see Tropo#ask(Key...)
* @since 0.4.6
*/
@Deprecated
public AskAction ask(String name, Boolean bargein, Float timeout, Boolean required) {
return ask(NAME(name), BARGEIN(bargein), TIMEOUT(timeout), REQUIRED(required));
}
/**
* @deprecated A choices and a say are required.
* @see Tropo#ask(Key...)
* @since 0.4.6
*/
@Deprecated
public AskAction ask(String name, Boolean bargein, Float timeout, Float sensitivity, Boolean required) {
return ask(NAME(name), BARGEIN(bargein), TIMEOUT(timeout), SENSITIVITY(sensitivity), REQUIRED(required));
}
public ChoicesAction choices(Key... keys) {
return choicesActionSupportHandler.build(this, "tropo", keys);
}
public ConferenceAction conference(Key... keys) {
return conferenceActionSupportHandler.build(this, "tropo", keys);
}
public OnAction on(Key... keys) {
return onActionSupportHandler.build(this, "tropo", keys);
}
/**
* @deprecated A say is required.
* @see Tropo#on(Key...)
* @since 0.4.8
*/
@Deprecated
public OnAction on(String event, String next) {
return on(EVENT(event), NEXT(next));
}
public RecordAction record(Key... keys) {
return recordActionSupportHandler.build(this, "tropo", keys);
}
/**
* @deprecated A sendTones and a exitTone are invalid.
* @see Tropo#record(String, String, Boolean)
* @since 0.4.8
*/
@Deprecated
public RecordAction record(String name, String url, Boolean beep, Boolean sendTones, String exitTone) {
return record(NAME(name), URL(url), BEEP(beep), SEND_TONES(sendTones), EXIT_TONE(exitTone));
}
public RecordAction record(String name, String url, Boolean beep) {
return record(NAME(name), URL(url), BEEP(beep));
}
public RedirectAction redirect(Key... keys) {
return redirectActionSupportHandler.build(this, "tropo", keys);
}
/**
* @deprecated A name is invalid.
* @see Tropo#redirect(Key...)
* @since 0.4.8
*/
@Deprecated
public RedirectAction redirect(String to) {
return redirect(TO(to));
}
/**
* @deprecated A name is invalid.
* @see Tropo#redirect(Key...)
* @since 0.4.8
*/
@Deprecated
public RedirectAction redirect(String to, String from) {
return redirect(TO(to), FROM(from));
}
public StartRecordingAction startRecording(Key... keys) {
return startRecordingActionSupportHandler.build(this, "tropo", keys);
}
public StartRecordingAction startRecording(String url) {
return startRecording(URL(url));
}
public StartRecordingAction startRecording(String url, Format format) {
return startRecording(URL(url), FORMAT(format));
}
public StartRecordingAction startRecording(String url, Format format, String username, String password) {
return startRecording(URL(url), FORMAT(format), USERNAME(username), PASSWORD(password));
}
public void hangup(Key... key) {
addNull("tropo", "hangup");
}
public void stopRecording(Key... key) {
addNull("tropo", "stopRecording");
}
public void reject(Key... key) {
addNull("tropo", "reject");
}
public TransferAction transfer(Key... keys) {
return transferActionSupportHandler.build(this, "tropo", keys);
}
public TransferAction transfer(String to, String name) {
return transfer(Key.TO(to), Key.NAME(name));
}
public TransferAction transfer(String to, String from, String name) {
return transfer(Key.TO(to), Key.FROM(from), Key.NAME(name));
}
public CallAction call(Key... keys) {
return callActionSupportHandler.build(this, "tropo", keys);
}
public CallAction call(String name, String to) {
return call(NAME(name), TO(to));
}
public CallAction call(String name, String to, Network network) {
return call(NAME(name), TO(to), NETWORK(network));
}
public CallAction call(String name, String to, Network network, String from) {
return call(NAME(name), TO(to), NETWORK(network), FROM(from));
}
public CallAction call(String name, String to, Network network, String from, Channel channel) {
return call(NAME(name), TO(to), NETWORK(network), FROM(from), CHANNEL(channel));
}
public MessageAction message(Key... keys) {
return messageActionSupportHandler.build(this, "tropo", keys);
}
/**
* @deprecated A say and a name are required.
* @see Tropo#message(Key...)
* @since 0.4.7
*/
@Deprecated
public MessageAction message(String to) {
return message(TO(to));
}
/**
* @deprecated A say and a name are required.
* @see Tropo#message(Key...)
* @since 0.4.7
*/
@Deprecated
public MessageAction message(String to, Network network) {
return message(TO(to), NETWORK(network));
}
/**
* @deprecated A say and a name are required.
* @see Tropo#message(Key...)
* @since 0.4.7
*/
@Deprecated
public MessageAction message(String to, Network network, String from) {
return message(TO(to), NETWORK(network), FROM(from));
}
/**
* @deprecated A say and a name are required.
* @see Tropo#message(Key...)
* @since 0.4.7
*/
@Deprecated
public MessageAction message(String to, Network network, String from, Channel channel) {
return message(TO(to), NETWORK(network), FROM(from), CHANNEL(channel));
}
public WaitAction serverWait(Long milliseconds) {
return serverWait(MILLISECONDS(milliseconds));
}
public WaitAction serverWait(Key... keys){
return waitActionSupportHandler.build(this, "tropo", keys);
}
public TropoResult parse(String json) {
return parser.parse(json);
}
public TropoSession session(String json) {
return parser.session(json);
}
public TropoResult parse(HttpServletRequest request) {
return parser.parse(request);
}
public TropoSession session(HttpServletRequest request) {
return parser.session(request);
}
public void render(HttpServletResponse response) {
render(response, text());
}
public void render(HttpServletResponse response, String json) {
try {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(text());
response.getWriter().flush();
response.getWriter().close();
} catch (IOException ioe) {
throw new TropoException("An error happened while rendering response", ioe);
}
}
public boolean isEmpty() {
return super.isEmpty();
}
@SuppressWarnings("unchecked")
public TropoLaunchResult launchSession(String token) {
return launchSession(token, Collections.EMPTY_MAP);
}
public TropoLaunchResult launchSession(String token, Map params) {
SessionLauncher launcher = new SessionLauncher();
return launcher.launchSession(baseUrl, token, params);
}
public TropoLaunchResult launchSession(String token, Map params, HttpClient httpClient) {
SessionLauncher launcher = new SessionLauncher(httpClient);
return launcher.launchSession(baseUrl, token, params);
}
public void generalLogSecurity(LogSecurityState value) {
addObject("tropo", "generalLogSecurity", value.toString());
}
public String getBaseUrl() {
return baseUrl;
}
public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}
}