package info.maccac.recorder.client;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.intellij.openapi.diagnostic.Logger;
import info.maccac.recorder.TestResults;

public class TestResultsClientImpl implements TestResultsClient {

    private static final Logger logger = Logger.getInstance("TestResultsClientImpl");

    private Gson gson;

    public TestResultsClientImpl() {
        this.gson = new GsonBuilder().create();
    }

    @Override
    public void postTestResults(TestResults breakdown) {
        logger.info("Posting: " + gson.toJson(breakdown));
    }
}

@@ -120,72 +120,377 @@
 lij.
-openapi.diagnostic.Logger;%0Aimport info.maccac.recorder.TestResul
+notification.Notification;%0Aimport com.intellij.notification.NotificationType;%0Aimport com.intellij.notification.Notifications;%0Aimport com.intellij.openapi.diagnostic.Logger;%0Aimport info.maccac.recorder.TestResults;%0Aimport org.jetbrains.annotations.NotNull;%0A%0Aimport java.io.*;%0Aimport java.net.HttpURLConnection;%0Aimport java.net.URL;%0Aimport java.nio.charset.StandardCharse
 ts;%0A
@@ -642,16 +642,96 @@
 tImpl%22);
+%0A    private static final String DEFAULT_HOST = %22http://localhost:8080/results%22;
 %0A%0A    pr
@@ -793,16 +793,17 @@
         
+ 
 this.gso
@@ -924,57 +924,1758 @@
     
-logger.info(%22Posting: %22 + gson.toJson(breakdown))
+try %7B%0A            String jsonBody = gson.toJson(breakdown);%0A            HttpURLConnection connection = postJson(jsonBody);%0A            if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) %7B%0A                logger.error(%22Failed to send results to server.%22);%0A            %7D%0A        %7D catch (IOException e) %7B%0A            logger.warn(e);%0A            Notification notification = new Notification(%22Test recorder%22, %22Failed to post results%22, e.getMessage(), NotificationType.INFORMATION);%0A            Notifications.Bus.notify(notification);%0A        %7D%0A    %7D%0A%0A    @NotNull%0A    private HttpURLConnection postJson(String jsonBody) throws IOException %7B%0A        HttpURLConnection connection = createHttpUrlConnectionTo(DEFAULT_HOST);%0A        connection.setRequestMethod(%22POST%22);%0A        connection.setRequestProperty(%22Content-Type%22, %22text/json%22);%0A        connection.setRequestProperty(%22charset%22, %22utf-8%22);%0A        byte%5B%5D jsonAsBytes = jsonBody.getBytes(StandardCharsets.UTF_8);%0A        connection.setRequestProperty(%22Content-Length%22, Integer.toString(jsonAsBytes.length));%0A%0A        try (DataOutputStream out = new DataOutputStream(connection.getOutputStream())) %7B%0A            out.write(jsonAsBytes);%0A        %7D%0A%0A        return connection;%0A    %7D%0A%0A    @NotNull%0A    private HttpURLConnection createHttpUrlConnectionTo(String defaultHost) throws IOException %7B%0A        URL url = new URL(defaultHost);%0A        HttpURLConnection connection = (HttpURLConnection) url.openConnection();%0A        connection.setDoOutput(true);%0A        connection.setDoInput(true);%0A        connection.setInstanceFollowRedirects(false);%0A        connection.setUseCaches(false);%0A        connection.setConnectTimeout(2000);%0A        connection.setReadTimeout(2000);%0A        return connection
 ;%0A  

Send results to an external service