Skip to content

Commit

Permalink
implement retrieving of access token
Browse files Browse the repository at this point in the history
  • Loading branch information
janinko committed Apr 14, 2013
1 parent ba416b1 commit e9564f1
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
90 changes: 90 additions & 0 deletions src/main/java/org/kohsuke/github/GHAuthorization.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.kohsuke.github;

import java.net.URL;
import java.util.Date;
import java.util.List;

/**
*
* @author janinko
*/
public class GHAuthorization {
public static final String USER = "user";
public static final String USER_EMAIL = "user:email";
public static final String USER_FOLLOW = "user:follow";
public static final String PUBLIC_REPO = "public_repo";
public static final String REPO = "repo";
public static final String REPO_STATUS = "repo:status";
public static final String DELETE_REPO = "delete_repo";
public static final String NOTIFICATIONS = "notifications";
public static final String GIST = "gist";

private GitHub root;
private int id;
private String url;
private List<String> scopes;
private String token;
private App app;
private String note;
private String note_url;
private String updated_at;
private String created_at;

public GitHub getRoot() {
return root;
}

public int getId() {
return id;
}

public List<String> getScopes() {
return scopes;
}

public String getToken(){
return token;
}

public URL getAppUrl(){
return GitHub.parseURL(app.url);
}

public String getAppName() {
return app.name;
}

public URL getApiURL(){
return GitHub.parseURL(url);
}

public String getNote() {
return note;
}

public URL getNoteUrl(){
return GitHub.parseURL(note_url);
}

public Date getCreatedAt() {
return GitHub.parseDate(created_at);
}

public Date getUpdatedAt() {
return GitHub.parseDate(updated_at);
}

/*package*/ GHAuthorization wrap(GitHub root) {
this.root = root;
return this;
}





private static class App{
private String url;
private String name;
}
}
12 changes: 12 additions & 0 deletions src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TimeZone;

import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.*;
Expand Down Expand Up @@ -303,6 +306,15 @@ public GHRepository createRepository(String name, String description, String hom
return requester.method("POST").to("/user/repos", GHRepository.class).wrap(this);
}

public GHAuthorization createToken(Collection<String> scope, String note, String noteUrl) throws IOException{
Requester requester = new Requester(this)
.with("scopes",scope)
.with("note",note)
.with("note_url",noteUrl);

return requester.method("POST").to("/authorizations", GHAuthorization.class).wrap(this);
}

/**
* Ensures that the credential is valid.
*/
Expand Down

0 comments on commit e9564f1

Please sign in to comment.