All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kohsuke.github.GHPerson Maven / Gradle / Ivy

There is a newer version: 2.0.0-alpha-2
Show newest version
package org.kohsuke.github;

import com.infradna.tool.bridge_method_injector.WithBridgeMethods;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import static org.kohsuke.github.ApiVersion.*;

/**
 * Common part of {@link GHUser} and {@link GHOrganization}.
 * 
 * @author Kohsuke Kawaguchi
 */
public abstract class GHPerson {
    /*package almost final*/ GitHub root;

    // common
    protected String login,location,blog,email,name,created_at,company;
    protected int id;
    protected String gravatar_id; // appears in V3 as well but presumably subsumed by avatar_url?

    // V2
    protected int public_gist_count,public_repo_count,followers_count,following_count;

    // V3
    protected String avatar_url,html_url;
    protected int followers,following,public_repos,public_gists;

    /**
     * Gets the repositories this user owns.
     */
    public synchronized Map getRepositories() throws IOException {
        Map repositories = new TreeMap();
        for (List batch : iterateRepositories(100)) {
            for (GHRepository r : batch)
                repositories.put(r.getName(),r);
        }
        return Collections.unmodifiableMap(repositories);
    }

    /**
     * Loads repository list in a pagenated fashion.
     * 
     * 

* For a person with a lot of repositories, GitHub returns the list of repositories in a pagenated fashion. * Unlike {@link #getRepositories()}, this method allows the caller to start processing data as it arrives. * * Every {@link Iterator#next()} call results in I/O. Exceptions that occur during the processing is wrapped * into {@link Error}. */ public synchronized Iterable> iterateRepositories(final int pageSize) { return new Iterable>() { public Iterator> iterator() { final Iterator pager = root.retrievePaged("/users/" + login + "/repos?per_page="+pageSize,GHRepository[].class,false, V3); return new Iterator>() { public boolean hasNext() { return pager.hasNext(); } public List next() { GHRepository[] batch = pager.next(); for (GHRepository r : batch) r.root = root; return Arrays.asList(batch); } public void remove() { throw new UnsupportedOperationException(); } }; } }; } /** * * @return * null if the repository was not found */ public GHRepository getRepository(String name) throws IOException { try { return root.retrieveWithAuth3("/repos/" + login + '/' + name, GHRepository.class).wrap(root); } catch (FileNotFoundException e) { return null; } } /** * Gravatar ID of this user, like 0cb9832a01c22c083390f3c5dcb64105 * * @deprecated * No longer available in the v3 API. */ public String getGravatarId() { return gravatar_id; } /** * Returns a string like 'https://secure.gravatar.com/avatar/0cb9832a01c22c083390f3c5dcb64105' * that indicates the avatar image URL. */ public String getAvatarUrl() { if (avatar_url!=null) return avatar_url; if (gravatar_id!=null) return "https://secure.gravatar.com/avatar/"+gravatar_id; return null; } /** * Gets the login ID of this user, like 'kohsuke' */ public String getLogin() { return login; } /** * Gets the human-readable name of the user, like "Kohsuke Kawaguchi" */ public String getName() { return name; } /** * Gets the company name of this user, like "Sun Microsystems, Inc." */ public String getCompany() { return company; } /** * Gets the location of this user, like "Santa Clara, California" */ public String getLocation() { return location; } public String getCreatedAt() { return created_at; } /** * Gets the blog URL of this user. */ public String getBlog() { return blog; } /** * Gets the e-mail address of the user. */ public String getEmail() { return email; } public int getPublicGistCount() { return Math.max(public_gist_count,public_gists); } public int getPublicRepoCount() { return Math.max(public_repo_count,public_repos); } public int getFollowingCount() { return Math.max(following_count,following); } /** * What appears to be a GitHub internal unique number that identifies this user. */ public int getId() { return id; } public int getFollowersCount() { return Math.max(followers_count,followers); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy