Beispiel #1
0
  public String create() {
    try {
      JsonObject gistJson = new JsonObject();
      gistJson.addProperty("description", this.getDescription());
      gistJson.addProperty("public", this.isPublic());

      JsonObject filesJson = new JsonObject();

      for (int i = 0; i < getFiles().length; i++) {
        GistFile gistFile = getFiles()[i];
        JsonObject file = new JsonObject();
        file.addProperty("content", gistFile.getContent());
        String name = gistFile.getFileName();
        filesJson.add(
            (name == null || name.isEmpty() ? "" : name + "-") + date.replace(' ', '_'), file);
      }

      gistJson.add("files", filesJson);

      HttpResponse<JsonNode> response =
          Unirest.post(GitHub.GISTS_API_URL)
              .header(
                  "authorization",
                  "token " + Nexus.getInstance().getGitHubConfig().getNexusGitHubApiKey())
              .header("accept", "application/json")
              .header("content-type", "application/json; charset=utf-8")
              .body(gistJson.toString())
              .asJson();
      return response.getBody().getObject().getString("html_url");
    } catch (UnirestException e) {
      throw new GistException("Failed to Gist!", e);
    }
  }
Beispiel #2
0
  @Override
  public boolean onCommand(CommandPerformEvent event) {
    if (event.getArgs().length != 1) {
      return false;
    }

    String channelName = event.getArgs()[0];
    if (!channelName.startsWith("#")) {
      channelName = "#" + channelName;
    }

    event.respondWithPing("Attempting to join " + channelName);
    Nexus.getInstance().sendIRC().joinChannel(channelName);
    return true;
  }