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

implement retrieving of access token #31

Merged
merged 1 commit into from
Apr 16, 2013
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
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