private AccessToken generateInstallationToken()

in src/main/java/com/spotify/github/v3/clients/GitHubClient.java [869:899]


  private AccessToken generateInstallationToken(final String jwtToken, final int installationId)
      throws Exception {
    log.info("Got JWT Token. Now getting Github access_token for installation {}", installationId);
    final String url = String.format(urlFor(GET_ACCESS_TOKEN_URL), installationId);
    final Request request =
        new Request.Builder()
            .addHeader("Accept", "application/vnd.github.machine-man-preview+json")
            .addHeader("Authorization", "Bearer " + jwtToken)
            .url(url)
            .method("POST", RequestBody.create(parse(MediaType.APPLICATION_JSON), ""))
            .build();

    final Response response = client.newCall(request).execute();

    if (!response.isSuccessful()) {
      throw new Exception(
          String.format(
              "Got non-2xx status %s when getting an access token from GitHub: %s",
              response.code(), response.message()));
    }

    if (response.body() == null) {
      throw new Exception(
          String.format(
              "Got empty response body when getting an access token from GitHub, HTTP status was: %s",
              response.message()));
    }
    final String text = response.body().string();
    response.body().close();
    return Json.create().fromJson(text, AccessToken.class);
  }