Skip to content

Commit

Permalink
Merge pull request hub4j#61 from lucamilanesio/master
Browse files Browse the repository at this point in the history
Fetching of user's verified keys through standard OAuth scope.
  • Loading branch information
kohsuke committed Jan 1, 2014
2 parents 4e8e28d + 4b52414 commit a4b8b9b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/kohsuke/github/GHKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
public class GHKey {
/*package almost final*/ GitHub root;

private String url, key, title;
private boolean verified;
private int id;
protected String url, key, title;
protected boolean verified;
protected int id;

public int getId() {
return id;
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/kohsuke/github/GHMyself.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,31 @@ public List<String> getEmails() throws IOException {
/**
* Returns the read-only list of all the pulic keys of the current user.
*
* NOTE: When using OAuth authenticaiton, the READ/WRITE User scope is
* required by the GitHub APIs, otherwise you will get a 404 NOT FOUND.
*
* @return
* Always non-null.
*/
public List<GHKey> getPublicKeys() throws IOException {
return Collections.unmodifiableList(Arrays.asList(root.retrieve().to("/user/keys", GHKey[].class)));
}

/**
* Returns the read-only list of all the pulic verified keys of the current user.
*
* Differently from the getPublicKeys() method, the retrieval of the user's
* verified public keys does not require any READ/WRITE OAuth Scope to the
* user's profile.
*
* @return
* Always non-null.
*/
public List<GHVerifiedKey> getPublicVerifiedKeys() throws IOException {
return Collections.unmodifiableList(Arrays.asList(root.retrieve().to(
"/users/" + getLogin() + "/keys", GHVerifiedKey[].class)));
}

/**
* Gets the organization that this user belongs to.
*/
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/kohsuke/github/GHVerifiedKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.kohsuke.github;

public class GHVerifiedKey extends GHKey {

public GHVerifiedKey() {
this.verified = true;
}

@Override
public String getTitle() {
return (title == null ? "key-" + id : title);
}
}

0 comments on commit a4b8b9b

Please sign in to comment.