/** * Delete the Gist with the given id * * @param gistId * @throws IOException */ public void deleteGist(String gistId) throws IOException { checkGistId(gistId); StringBuilder uri = new StringBuilder(SEGMENT_GISTS); uri.append('/').append(gistId); client.delete(uri.toString()); }
/** * Star the gist with the given id * * @param gistId * @throws IOException */ public void starGist(String gistId) throws IOException { checkGistId(gistId); StringBuilder uri = new StringBuilder(SEGMENT_GISTS); uri.append('/').append(gistId); uri.append(SEGMENT_STAR); client.put(uri.toString()); }
/** * Fork gist with given id * * @param gistId * @return forked gist * @throws IOException */ public Gist forkGist(String gistId) throws IOException { checkGistId(gistId); StringBuilder uri = new StringBuilder(SEGMENT_GISTS); uri.append('/').append(gistId); uri.append(SEGMENT_FORK); return client.post(uri.toString(), null, Gist.class); } }
/** * Unstar the gist with the given id * * @param gistId * @throws IOException */ public void unstarGist(String gistId) throws IOException { checkGistId(gistId); StringBuilder uri = new StringBuilder(SEGMENT_GISTS); uri.append('/').append(gistId); uri.append(SEGMENT_STAR); client.delete(uri.toString()); }
/** * Check if a gist is starred * * @param gistId * @return true if starred, false if not starred * @throws IOException */ public boolean isStarred(String gistId) throws IOException { checkGistId(gistId); StringBuilder uri = new StringBuilder(SEGMENT_GISTS); uri.append('/').append(gistId); uri.append(SEGMENT_STAR); return check(uri.toString()); }
/** * Create comment on specified gist id * * @param gistId * @param comment * @return created issue * @throws IOException */ public Comment createComment(String gistId, String comment) throws IOException { checkGistId(gistId); if (comment == null) throw new IllegalArgumentException("Gist comment cannot be null"); //$NON-NLS-1$ StringBuilder uri = new StringBuilder(SEGMENT_GISTS); uri.append('/').append(gistId); uri.append(SEGMENT_COMMENTS); Map<String, String> params = Collections.singletonMap( IssueService.FIELD_BODY, comment); return client.post(uri.toString(), params, Comment.class); }
/** * Update a gist * * @param gist * @return updated gist * @throws IOException */ public Gist updateGist(Gist gist) throws IOException { if (gist == null) throw new IllegalArgumentException("Gist cannot be null"); //$NON-NLS-1$ String id = gist.getId(); checkGistId(id); StringBuilder uri = new StringBuilder(SEGMENT_GISTS); uri.append('/').append(id); return client.post(uri.toString(), gist, Gist.class); }
/** * Get gist * * @param id * @return gist * @throws IOException */ public Gist getGist(String id) throws IOException { checkGistId(id); StringBuilder uri = new StringBuilder(SEGMENT_GISTS); uri.append('/').append(id); GitHubRequest request = createRequest(); request.setUri(uri); request.setType(Gist.class); return (Gist) client.get(request).getBody(); }
/** * Get comments for specified gist id * * @param gistId * @return list of comments * @throws IOException */ public List<Comment> getComments(String gistId) throws IOException { checkGistId(gistId); StringBuilder uri = new StringBuilder(SEGMENT_GISTS); uri.append('/').append(gistId); uri.append(SEGMENT_COMMENTS); PagedRequest<Comment> request = createPagedRequest(); request.setUri(uri).setType(new TypeToken<List<Comment>>() { }.getType()); return getAll(request); }