Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011 GitHub Inc. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: Kevin Sawicki (GitHub Inc.) - initial API and implementation /
 
 package org.eclipse.egit.github.core.service;
 
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_COMMENTS;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_FORK;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_GISTS;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_PUBLIC;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_STAR;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_STARRED;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_USERS;
 
 
 import java.util.List;
 import java.util.Map;
 
Service class for interacting with Gists and Gist comments.

See also:
GitHub Gist API documentation
GitHub Gist comments API documentation
 
 public class GistService extends GitHubService {

Create gist service
 
 	public GistService() {
 		super();
 	}

Create gist service

Parameters:
client
 
 	public GistService(GitHubClient client) {
 		super(client);
 	}

Check that gist id is non-null and non-empty

Parameters:
gistId
Returns:
gist id
 
 	protected String checkGistId(String gistId) {
 		if (gistId == null)
 			throw new IllegalArgumentException("Gist id cannot be null"); //$NON-NLS-1$
 		if (gistId.length() == 0)
 			throw new IllegalArgumentException("Gist id cannot be empty"); //$NON-NLS-1$
 		return gistId;
 	}

Get gist

Parameters:
id
Returns:
gist
Throws:
java.io.IOException
 
 	public Gist getGist(String idthrows IOException {
 		uri.append('/').append(id);
 		GitHubRequest request = createRequest();
 		request.setUri(uri);
 		request.setType(Gist.class);
 		return (Gist.get(request).getBody();
 	}

Get starred gists for currently authenticated user

Returns:
list of gists
Throws:
java.io.IOException
 
 	public List<GistgetStarredGists() throws IOException {
		request.setType(new TypeToken<List<Gist>>() {
		}.getType());
		return getAll(request);
	}

Create user gist paged request

Parameters:
user
start
size
Returns:
request
	protected PagedRequest<GistcreateUserGistRequest(String userint start,
			int size) {
		if (user == null)
			throw new IllegalArgumentException("User cannot be null"); //$NON-NLS-1$
		if (user.length() == 0)
			throw new IllegalArgumentException("User cannot be empty"); //$NON-NLS-1$
		uri.append('/').append(user);
		PagedRequest<Gistrequest = createPagedRequest(startsize);
		request.setUri(uri).setType(new TypeToken<List<Gist>>() {
		}.getType());
		return request;
	}

Get gists for specified user

Parameters:
user
Returns:
list of gists
Throws:
java.io.IOException
	public List<GistgetGists(String userthrows IOException {
		return getAll(request);
	}

Create page iterator for given user's gists

Parameters:
user
Returns:
gist page iterator
	public PageIterator<GistpageGists(final String user) {
	}

Create page iterator for given user's gists

Parameters:
user
size size of page
Returns:
gist page iterator
	public PageIterator<GistpageGists(final String userfinal int size) {
		return pageGists(user.size);
	}

Create page iterator for given user's gists

Parameters:
user
size size of page
start starting page
Returns:
gist page iterator
	public PageIterator<GistpageGists(final String userfinal int start,
			final int size) {
		PagedRequest<Gistrequest = createUserGistRequest(userstartsize);
		return createPageIterator(request);
	}

Create page iterator for all public gists

Returns:
gist page iterator
	}

Create page iterator for all public gists

Parameters:
size size of page
Returns:
gist page iterator
	public PageIterator<GistpagePublicGists(final int size) {
	}

Create page iterator for all public gists

Parameters:
start starting page number
size size of page
Returns:
gist page iterator
	public PageIterator<GistpagePublicGists(final int startfinal int size) {
		PagedRequest<Gistrequest = createPagedRequest(startsize);
		request.setType(new TypeToken<List<Gist>>() {
		}.getType());
		return createPageIterator(request);
	}

Create a gist

Parameters:
gist
Returns:
created gist
Throws:
java.io.IOException
	public Gist createGist(Gist gistthrows IOException {
		if (gist == null)
			throw new IllegalArgumentException("Gist cannot be null"); //$NON-NLS-1$
		return .post(gistGist.class);
	}

Update a gist

Parameters:
gist
Returns:
updated gist
Throws:
java.io.IOException
	public Gist updateGist(Gist gistthrows IOException {
		if (gist == null)
			throw new IllegalArgumentException("Gist cannot be null"); //$NON-NLS-1$
		String id = gist.getId();
		uri.append('/').append(id);
		return .post(uri.toString(), gistGist.class);
	}

Create comment on specified gist id

Parameters:
gistId
comment
Returns:
created issue
Throws:
java.io.IOException
	public Comment createComment(String gistIdString comment)
			throws IOException {
		checkGistId(gistId);
		if (comment == null)
			throw new IllegalArgumentException("Gist comment cannot be null"); //$NON-NLS-1$
		uri.append('/').append(gistId);
		Map<StringStringparams = Collections.singletonMap(
		return .post(uri.toString(), paramsComment.class);
	}

Get comments for specified gist id

Parameters:
gistId
Returns:
list of comments
Throws:
java.io.IOException
	public List<CommentgetComments(String gistIdthrows IOException {
		checkGistId(gistId);
		uri.append('/').append(gistId);
		request.setUri(uri).setType(new TypeToken<List<Comment>>() {
		}.getType());
		return getAll(request);
	}

Delete the Gist with the given id

Parameters:
gistId
Throws:
java.io.IOException
	public void deleteGist(String gistIdthrows IOException {
		checkGistId(gistId);
		uri.append('/').append(gistId);
	}

Get gist comment with id

Parameters:
commentId
Returns:
comment
Throws:
java.io.IOException
	public Comment getComment(long commentIdthrows IOException {
		uri.append('/').append(commentId);
		request.setUri(uri);
		request.setType(Comment.class);
		return (Comment.get(request).getBody();
	}

Edit gist comment

Parameters:
comment
Returns:
edited comment
Throws:
java.io.IOException
	public Comment editComment(Comment commentthrows IOException {
		if (comment == null)
			throw new IllegalArgumentException("Comment cannot be null"); //$NON-NLS-1$
		uri.append('/').append(comment.getId());
		return .post(uri.toString(), commentComment.class);
	}

Delete the Gist comment with the given id

Parameters:
commentId
Throws:
java.io.IOException
	public void deleteComment(long commentIdthrows IOException {
		uri.append('/').append(commentId);
	}

Star the gist with the given id

Parameters:
gistId
Throws:
java.io.IOException
	public void starGist(String gistIdthrows IOException {
		checkGistId(gistId);
		uri.append('/').append(gistId);
	}

Unstar the gist with the given id

Parameters:
gistId
Throws:
java.io.IOException
	public void unstarGist(String gistIdthrows IOException {
		checkGistId(gistId);
		uri.append('/').append(gistId);
	}

Check if a gist is starred

Parameters:
gistId
Returns:
true if starred, false if not starred
Throws:
java.io.IOException
	public boolean isStarred(String gistIdthrows IOException {
		checkGistId(gistId);
		uri.append('/').append(gistId);
		return check(uri.toString());
	}

Fork gist with given id

Parameters:
gistId
Returns:
forked gist
Throws:
java.io.IOException
	public Gist forkGist(String gistIdthrows IOException {
		checkGistId(gistId);
		uri.append('/').append(gistId);
		return .post(uri.toString(), nullGist.class);
	}
New to GrepCode? Check out our FAQ X