diff --git a/src/main/java/org/kohsuke/github/GHGist.java b/src/main/java/org/kohsuke/github/GHGist.java index c4c91737d6..df94fcda9f 100644 --- a/src/main/java/org/kohsuke/github/GHGist.java +++ b/src/main/java/org/kohsuke/github/GHGist.java @@ -6,6 +6,7 @@ import java.net.URL; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; @@ -159,6 +160,57 @@ public void delete() throws IOException { new Requester(root).method("DELETE").to("/gists/" + id); } + private String getApiRoute() { + return "/gists/" + id; + } + + private void edit(String key, Object value) throws IOException { + new Requester(root)._with(key, value).method("PATCH").to(getApiRoute()); + } + + public void setDescription(String value) throws IOException { + edit("description",value); + } + + /** + * Adds a file. + */ + public void addFile(String fileName, String content) throws IOException + { + updateFile(fileName, content); + } + +// /** +// * Deletes a file. +// */ +// // NOTE: I can't get this to work, even when using "curl" from the command +// // line. It may be an issue with the underlying API itself. +// public void deleteFile(String fileName) throws IOException { +// LinkedHashMap filesMap = new LinkedHashMap(); +// filesMap.put(fileName, Collections.singletonMap("filename", null)); +// edit("files",filesMap); +// } + + /** + * Replaces the content of a file. + */ + public void updateFile(String fileName, String content) throws IOException + { + LinkedHashMap filesMap = new LinkedHashMap(); + filesMap.put(fileName, Collections.singletonMap("content", content)); + edit("files",filesMap); + } + + /** + * Renames a file. + */ + public void renameFile(String fileName, String newFileName) throws IOException + { + LinkedHashMap filesMap = new LinkedHashMap(); + filesMap.put(fileName, Collections.singletonMap("filename", newFileName)); + edit("files",filesMap); + } + @Override public boolean equals(Object o) { if (this == o) return true;