/**
* Submit a paste to the server.
*
* @see <a href="https://pastee.github.io/docs/#submit-a-new-paste">Pastee Docs: Submit a new paste</a>
* @param paste the paste to submit
*
* @return the response of the submit request
*/
public SubmitResponse submit(Paste paste) {
final String route = "/pastes";
JSONObject json = new JSONObject();
json.put("encrypted", paste.isEncrypted());
json.putOpt("description", paste.getDescription());
JSONArray sectionsJson = new JSONArray();
paste.getSections().forEach(section -> {
JSONObject sectionJson = new JSONObject();
sectionJson.putOpt("name", section.getName());
if(section.getSyntax() != null)
sectionJson.putOpt("syntax", section.getSyntax().getShortName());
sectionJson.put("contents", section.getContents());
sectionsJson.put(sectionJson);
});
json.put("sections", sectionsJson);
try {
return new SubmitResponse(post(route, json).getBody().getObject());
} catch(UnirestException e) {
return new SubmitResponse(e);
}
}
JPastee.java 文件源码
java
阅读 18
收藏 0
点赞 0
评论 0
项目:JPastee
作者:
评论列表
文章目录