Search in sources :

Example 1 with GithubConfusingException

use of org.jetbrains.plugins.github.exceptions.GithubConfusingException in project intellij-community by JetBrains.

the class GithubApiUtil method getTokenScopes.

@NotNull
public static Collection<String> getTokenScopes(@NotNull GithubConnection connection) throws IOException {
    Header[] headers = connection.headRequest("/user", ACCEPT_V3_JSON);
    Header scopesHeader = null;
    for (Header header : headers) {
        if (header.getName().equals("X-OAuth-Scopes")) {
            scopesHeader = header;
            break;
        }
    }
    if (scopesHeader == null) {
        throw new GithubConfusingException("No scopes header");
    }
    Collection<String> scopes = new ArrayList<>();
    for (HeaderElement elem : scopesHeader.getElements()) {
        scopes.add(elem.getName());
    }
    return scopes;
}
Also used : Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) HeaderElement(org.apache.http.HeaderElement) GithubConfusingException(org.jetbrains.plugins.github.exceptions.GithubConfusingException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Header (org.apache.http.Header)1 HeaderElement (org.apache.http.HeaderElement)1 BasicHeader (org.apache.http.message.BasicHeader)1 NotNull (org.jetbrains.annotations.NotNull)1 GithubConfusingException (org.jetbrains.plugins.github.exceptions.GithubConfusingException)1