Here are some of the relevant API endpoints for enumerating running orders, stories and MOS items. Note that you will need to supply an API key with these calls.
- Enumerate all available running orders: /inception/RunningOrderManager/Object/Render.js and /inception/RunningOrderManager/Object/RowCount.js
- Grab a running order with /inception/RunningOrder/Object/Render.js - there is a lot of superfluous data but here are some fields to focus on:
- object/<number>/story/id/value - the ID of the story (to query in step 4)
- object/<number>/story/object/value - the type of the story
- object/<number>/slug/value - the slug of the story
- object/<number>/page/value - the page number of the story
- Grab a story with /inception.broadcast/BroadcastStory/Object/Get.js - relevant fields:
- object/printBody - the script contents
- Enumerate the MOS items of a story with /inception.mos/MosStoryItem/Object/Get.js
- Get the raw MOS for each item with /inception.mos/MosStoryItem/Object/Object.js
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
public class MOSUplinkAPI {
private static final String RUNNING_ORDER_MANAGER_RENDER = "/inception/RunningOrderManager/Object/Render.js";
private static final String RUNNING_ORDER_MANAGER_ROWCOUNT = "/inception/RunningOrderManager/Object/RowCount.js";
public static void main(String[] args) {
String apiKey = "BpBaGOUauiHiTrp7HHqiIO80uoaaySSK8Sqd1T0hTtG6AEcPDTlDeASOpJySBiS5";
String inceptionUrl = "http://localhost";
try {
Map<String, Object> renderArgs = new HashMap<String, Object>();
renderArgs.put("showArchived", "false");
renderArgs.put("offset", "0");
Map<String, Object> response = makeApiCall(inceptionUrl, RUNNING_ORDER_MANAGER_RENDER, apiKey, new HashMap<String, Object>());
// List all the running orders
ArrayList<Map<String, Object>> runningOrders = (ArrayList<Map<String,Object>>) response.get("object");
for (Map<String,Object> runningOrder: runningOrders) {
Map<String,Object> name = (Map<String,Object>)runningOrder.get("name");
System.out.println(name.get("value"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void verifyResponse(Map<String, Object> response, String endPoint) throws Exception {
if (response.get("status") == null || response.get("status").equals("success") == false) {
String msgs = "";
List<String> responseMsgs = (List<String>) response.get("messages");
if (responseMsgs != null) {
for (String msg : responseMsgs) {
msgs += msg + "\n";
}
} else {
responseMsgs = new ArrayList<String>();
responseMsgs.add((String)response.get("status"));
}
throw new Exception("API call to " + endPoint + " failed with the following messages: " + msgs);
}
}
public static Map<String, Object> makeApiCall(String url, String endpoint, String apiKey, Map<String, Object> data) throws Exception {
HttpURLConnection inceptionConnection = null;
try {
// initialize connection
inceptionConnection = initializeConnection(url, endpoint);
data.put("api", apiKey);
// Convert data to post string
String postData = getPostString(data);
inceptionConnection.setRequestProperty("Content-Length", Integer.toString(postData.getBytes().length));
inceptionConnection.connect();
// Write post data to stream
DataOutputStream output = new DataOutputStream(inceptionConnection.getOutputStream());
output.writeBytes(postData);
output.flush();
output.close();
BufferedReader in = new BufferedReader(new InputStreamReader(inceptionConnection.getInputStream()));
StringBuffer json = new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
json.append(line);
}
Map<String, Object> response = new Gson().fromJson(json.toString(), new TypeToken<Map<String, Object>>(){}.getType());
verifyResponse(response, endpoint);
return response;
} finally {
if (inceptionConnection != null) {
inceptionConnection.disconnect();
}
}
}
public static String getPostString(Map<String, Object> data) throws UnsupportedEncodingException {
StringBuilder builder = new StringBuilder();
for (Entry<String, Object> kv : data.entrySet()) {
if (builder.length() > 0) {
builder.append("&");
}
if (kv.getValue() instanceof List<?>) {
List<Object> values = (List<Object>) kv.getValue();
for (int i = 0; i < values.size(); i++) {
if (i != 0) {
builder.append("&");
}
builder.append(kv.getKey() + "=" + URLEncoder.encode(values.get(i).toString(), "UTF-8"));
}
} else {
builder.append(kv.getKey() + "=" + URLEncoder.encode(kv.getValue().toString(), "UTF-8"));
}
}
return builder.toString();
}
public static HttpURLConnection initializeConnection(String url, String endpoint) throws Exception {
HttpURLConnection inceptionConnection = (HttpURLConnection) new URL(url + endpoint).openConnection();
inceptionConnection.setRequestMethod("POST");
inceptionConnection.setRequestProperty("Accept","*/*");
inceptionConnection.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
inceptionConnection.setRequestProperty("charset", "utf-8");
inceptionConnection.setConnectTimeout(10000);
inceptionConnection.setReadTimeout(15000);
inceptionConnection.setDoInput (true);
inceptionConnection.setDoOutput(true);
return inceptionConnection;
}
}#Inception