From e9564f101b51bb87cca5b08fe0ebfbee41a30f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Honza=20Br=C3=A1zdil?= Date: Sun, 14 Apr 2013 05:48:29 +0200 Subject: [PATCH] implement retrieving of access token --- .../org/kohsuke/github/GHAuthorization.java | 90 +++++++++++++++++++ src/main/java/org/kohsuke/github/GitHub.java | 12 +++ 2 files changed, 102 insertions(+) create mode 100644 src/main/java/org/kohsuke/github/GHAuthorization.java diff --git a/src/main/java/org/kohsuke/github/GHAuthorization.java b/src/main/java/org/kohsuke/github/GHAuthorization.java new file mode 100644 index 0000000000..711be454c6 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHAuthorization.java @@ -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 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 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; + } +} diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 177f197819..889a5e93e4 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -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.*; @@ -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 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. */