Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetching of user's verified keys through standard OAuth scope. #61

Merged
merged 1 commit into from
Jan 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}