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_EMAILS;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_FOLLOWERS;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_FOLLOWING;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_KEYS;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_USER;
 import static org.eclipse.egit.github.core.client.IGitHubConstants.SEGMENT_USERS;
 import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_FIRST;
 import static org.eclipse.egit.github.core.client.PagedRequest.PAGE_SIZE;
 
 
 import java.util.List;
 
User service class.

See also:
GitHub users API documentation
GitHub followers API documentation
GitHub user email API documentation
GitHub user keys API documentation
 
 public class UserService extends GitHubService {

Create user service
 
 	public UserService() {
 		super();
 	}

Create user service

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

Get user with given login name

Parameters:
login
Returns:
user
Throws:
java.io.IOException
 
 	public User getUser(String loginthrows IOException {
 		if (login == null)
 			throw new IllegalArgumentException("Login name cannot be null"); //$NON-NLS-1$
 		if (login.length() == 0)
 			throw new IllegalArgumentException("Login name cannot be empty"); //$NON-NLS-1$
 
 		GitHubRequest request = createRequest();
 		uri.append('/').append(login);
 		request.setUri(uri);
 		request.setType(User.class);
 		return (User.get(request).getBody();
 	}

Get currently authenticated user

Returns:
user
Throws:
java.io.IOException
 
 	public User getUser() throws IOException {
 		GitHubRequest request = createRequest();
 		request.setUri();
 		request.setType(User.class);
 		return (User.get(request).getBody();
 	}

Edit given user

Parameters:
user
Returns:
edited user
Throws:
java.io.IOException
	public User editUser(User userthrows IOException {
		if (user == null)
			throw new IllegalArgumentException("User cannot be null"); //$NON-NLS-1$
		return .post(userUser.class);
	}

Create follower request

Parameters:
start
size
user
Returns:
request
	protected PagedRequest<UsercreateFollowersRequest(int startint size,
			String user) {
		PagedRequest<Userrequest = createPagedRequest(startsize);
		if (user == null)
		else {
			uri.append('/').append(user);
			request.setUri(uri);
		}
		request.setType(new TypeToken<List<User>>() {
		}.getType());
		return request;
	}

Create following request

Parameters:
start
size
user
Returns:
request
	protected PagedRequest<UsercreateFollowingRequest(int startint size,
			String user) {
		PagedRequest<Userrequest = createPagedRequest(startsize);
		if (user == null)
		else {
			uri.append('/').append(user);
			request.setUri(uri);
		}
		request.setType(new TypeToken<List<User>>() {
		}.getType());
		return request;
	}

Get all followers of the currently authenticated user

Returns:
list of followers
Throws:
java.io.IOException
	public List<UsergetFollowers() throws IOException {
	}

Page followers of the currently authenticated user

Returns:
page iterator
	}

Page followers of the currently authenticated user

Parameters:
size
Returns:
page iterator
	public PageIterator<UserpageFollowers(final int size) {
		return pageFollowers(size);
	}

Page followers of the currently authenticated user

Parameters:
start
size
Returns:
page iterator
	public PageIterator<UserpageFollowers(final int startfinal int size) {
		PagedRequest<Userrequest = createFollowersRequest(startsizenull);
		return createPageIterator(request);
	}

Get all followers of the given user

Parameters:
user
Returns:
list of followers
Throws:
java.io.IOException
	public List<UsergetFollowers(final String userthrows IOException {
		return getAll(pageFollowers(user));
	}

Page followers of the given user

Parameters:
user
Returns:
page iterator
	public PageIterator<UserpageFollowers(final String user) {
		return pageFollowers(user);
	}

Page followers of the given user

Parameters:
size
user
Returns:
page iterator
	public PageIterator<UserpageFollowers(final String userfinal int size) {
		return pageFollowers(usersize);
	}

Page followers of the given user

Parameters:
start
size
user
Returns:
page iterator
	public PageIterator<UserpageFollowers(final String userfinal int start,
			final 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$
		PagedRequest<Userrequest = createFollowersRequest(startsizeuser);
		return createPageIterator(request);
	}

Get all users being followed by the currently authenticated user

Returns:
list of users being followed
Throws:
java.io.IOException
	public List<UsergetFollowing() throws IOException {
	}

Page users being followed by the currently authenticated user

Returns:
page iterator
	}

Page users being followed by the currently authenticated user

Parameters:
size
Returns:
page iterator
	public PageIterator<UserpageFollowing(final int size) {
		return pageFollowing(size);
	}

Page users being followed by the currently authenticated user

Parameters:
start
size
Returns:
page iterator
	public PageIterator<UserpageFollowing(final int startfinal int size) {
		PagedRequest<Userrequest = createFollowingRequest(startsizenull);
		return createPageIterator(request);
	}

Get all users being followed by the given user

Parameters:
user
Returns:
list of users being followed
Throws:
java.io.IOException
	public List<UsergetFollowing(final String userthrows IOException {
		return getAll(pageFollowing(user));
	}

Page users being followed by the given user

Parameters:
user
Returns:
page iterator
	public PageIterator<UserpageFollowing(final String user) {
		return pageFollowing(user);
	}

Page users being followed by the given user

Parameters:
user
size
Returns:
page iterator
	public PageIterator<UserpageFollowing(final String userfinal int size) {
		return pageFollowing(usersize);
	}

Page users being followed by the given user

Parameters:
user
start
size
Returns:
page iterator
	public PageIterator<UserpageFollowing(final String userfinal int start,
			final 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$
		PagedRequest<Userrequest = createFollowingRequest(startsizeuser);
		return createPageIterator(request);
	}

Check if the currently authenticated user is following the given user

Parameters:
user
Returns:
true if following, false if not following
Throws:
java.io.IOException
	public boolean isFollowing(final String userthrows IOException {
		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);
		return check(uri.toString());
	}

Follow the given user

Parameters:
user
Throws:
java.io.IOException
	public void follow(final String userthrows IOException {
		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);
	}

Unfollow the given user

Parameters:
user
Throws:
java.io.IOException
	public void unfollow(final String userthrows IOException {
		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);
	}

Get all e-mail addresses for the currently authenticated user

Returns:
list of e-mail address
Throws:
java.io.IOException
	public List<StringgetEmails() throws IOException {
		request.setType(new TypeToken<List<String>>() {
		}.getType());
		return getAll(request);
	}

Add one or more e-mail addresses to the currently authenticated user's account

Parameters:
emails
Throws:
java.io.IOException
	public void addEmail(String... emailsthrows IOException {
		if (emails == null)
			throw new IllegalArgumentException("Emails cannot be null"); //$NON-NLS-1$
		if (emails.length == 0)
			throw new IllegalArgumentException("Emails cannot be empty"); //$NON-NLS-1$
		.post( + emailsnull);
	}

Remove one or more e-mail addresses from the currently authenticated user's account

Parameters:
emails
Throws:
java.io.IOException
	public void removeEmail(String... emailsthrows IOException {
		if (emails == null)
			throw new IllegalArgumentException("Emails cannot be null"); //$NON-NLS-1$
		if (emails.length == 0)
			throw new IllegalArgumentException("Emails cannot be empty"); //$NON-NLS-1$
	}

Get all public keys for currently authenticated user

Returns:
non-null list of public keys
Throws:
java.io.IOException
	public List<KeygetKeys() throws IOException {
		request.setType(new TypeToken<List<Key>>() {
		}.getType());
		return getAll(request);
	}

Get key with given id

Parameters:
id
Returns:
key
Throws:
java.io.IOException
	public Key getKey(int idthrows IOException {
		uri.append('/').append(id);
		request.setUri(uri);
		request.setType(Key.class);
		return (Key.get(request).getBody();
	}

Create key for currently authenticated user

Parameters:
key
Returns:
created key
Throws:
java.io.IOException
	public Key createKey(Key keythrows IOException {
		return .post( + keyKey.class);
	}

Edit key for currently authenticated user

Parameters:
key
Returns:
edited key
Throws:
java.io.IOException
	public Key editKey(Key keythrows IOException {
		if (key == null)
			throw new IllegalArgumentException("Key cannot be null"); //$NON-NLS-1$
		uri.append('/').append(key.getId());
		return .post(uri.toString(), keyKey.class);
	}

Delete key with given id

Parameters:
id
Throws:
java.io.IOException
	public void deleteKey(int idthrows IOException {
		uri.append('/').append(id);
	}
New to GrepCode? Check out our FAQ X