package info.igreque.keepmecontributing;

import static spark.Spark.*;

/**
 * Server application for keep-me-contributing.
 * Download an svg representing my contributions calendar
 * from https://github.com/users/igrep/contributions.
 * Then convert it to a JSON.
 */
public class Server {
  public static void main(String[] args) {
    externalStaticFileLocation(args[0]);
    port(Integer.parseInt(args[1], 10));

    get("/users/:name/contributions", (request, response) -> {
      return "TODO: Implement";
    });
  }
}

@@ -35,16 +35,277 @@
 uting;%0A%0A
+import info.igreque.keepmecontributing.github.Github;%0Aimport org.apache.http.client.methods.CloseableHttpResponse;%0Aimport org.apache.http.impl.client.CloseableHttpClient;%0Aimport org.apache.http.impl.client.HttpClients;%0Aimport org.apache.http.util.EntityUtils;%0A%0A
 import s
@@ -325,16 +325,16 @@
 park.*;%0A
-
 %0A/**%0A * 
@@ -586,17 +586,16 @@
 %5B%5D args)
- 
 %7B%0A    ex
@@ -679,39 +679,1177 @@
     
-get(%22/users/:name/contributions
+buildEntryPointFor(%22igrep%22);%0A    //buildEntryPointFor(%22some-test-users%22);%0A  %7D%0A%0A  /**%0A   * Used to restrict users that this program gets his/her contributions via GitHub private endpoint.%0A   * Intended to reduce accesses to this server (and GitHub) by the users except me:%0A   * Maybe they are not always interested in my contributions.%0A   * @param username GitHub username.%0A   */%0A  private static void buildEntryPointFor(String username)%7B%0A    get(%22/users/%22 + username + %22/contributions%22, (request, response) -%3E %7B%0A      CloseableHttpClient httpClient = HttpClients.createDefault();%0A      CloseableHttpResponse responseFromGithub = null;%0A      try %7B%0A        responseFromGithub = (CloseableHttpResponse)%0A          new Github(username, httpClient).fetchContributionsCalendarSvg();%0A%0A        response.status(responseFromGithub.getStatusLine().getStatusCode());%0A        response.type(%22text/html; charset=utf-8%22); // same as original.%0A        return EntityUtils.toString(responseFromGithub.getEntity());%0A      %7D finally %7B%0A        if (responseFromGithub != null)%7B%0A          responseFromGithub.close();%0A        %7D%0A      %7D%0A    %7D);%0A    get(%22/users/%22 + username + %22/contributions.json
 %22, (
@@ -1912,14 +1912,15 @@
     %7D);%0A
-
   %7D%0A
+%0A
 %7D%0A

implement endpoint to get a raw SVG from github