package com.hubspot.blazar.client;

import com.google.common.base.Optional;
import com.hubspot.blazar.base.ModuleBuild;
import com.hubspot.horizon.HttpClient;
import com.hubspot.horizon.HttpRequest;
import com.hubspot.horizon.HttpRequest.Method;
import com.hubspot.horizon.HttpResponse;

public class BlazarClient {
  private static final String MODULE_BUILD_PATH = "/modules/builds";
  private static final String GET_MODULE_BUILD_PATH = MODULE_BUILD_PATH + "/%s";
  private static final String START_MODULE_BUILD_PATH = MODULE_BUILD_PATH + "/%s/start";
  private static final String COMPLETE_MODULE_BUILD_SUCCESS_PATH = MODULE_BUILD_PATH + "/%s/success";
  private static final String COMPLETE_MODULE_BUILD_FAILURE_PATH = MODULE_BUILD_PATH + "/%s/failure";

  private final HttpClient httpClient;
  private final String baseUrl;

  // Create via BlazarClientConfig
  BlazarClient(HttpClient httpClient, String baseUrl) {
    this.httpClient = httpClient;
    this.baseUrl = baseUrl;
  }

  public Optional<ModuleBuild> getModuleBuild(long moduleBuildId) {
    String url = String.format(baseUrl + GET_MODULE_BUILD_PATH, moduleBuildId);
    HttpRequest request = HttpRequest.newBuilder().setMethod(Method.GET).setUrl(url).build();

    HttpResponse response = httpClient.execute(request);
    if (response.getStatusCode() == 404) {
      return Optional.absent();
    } else if (response.getStatusCode() == 200) {
      return Optional.of(response.getAs(ModuleBuild.class));
    } else {
      throw toException(response);
    }
  }

  public void startModuleBuild(long moduleBuildId, String taskId) {
    String url = String.format(baseUrl + START_MODULE_BUILD_PATH, moduleBuildId);
    HttpRequest request = HttpRequest.newBuilder().setMethod(Method.PUT).setUrl(url).build();

    HttpResponse response = httpClient.execute(request);
    if (response.getStatusCode() != 200) {
      throw toException(response);
    }
  }

  public void completeModuleBuildSuccess(long moduleBuildId) {
    String url = String.format(baseUrl + COMPLETE_MODULE_BUILD_SUCCESS_PATH, moduleBuildId);
    HttpRequest request = HttpRequest.newBuilder().setMethod(Method.PUT).setUrl(url).build();

    HttpResponse response = httpClient.execute(request);
    if (response.getStatusCode() != 200) {
      throw toException(response);
    }
  }

  public void completeModuleBuildFailure(long moduleBuildId) {
    String url = String.format(baseUrl + COMPLETE_MODULE_BUILD_FAILURE_PATH, moduleBuildId);
    HttpRequest request = HttpRequest.newBuilder().setMethod(Method.PUT).setUrl(url).build();

    HttpResponse response = httpClient.execute(request);
    if (response.getStatusCode() != 200) {
      throw toException(response);
    }
  }

  private BlazarClientException toException(HttpResponse response) {
    String messageFormat = "Error hitting URL %s, status code: %s, response: %s";
    String message = String.format(messageFormat, response.getRequest().getUrl(), response.getStatusCode(), response.getAsString());
    throw new BlazarClientException(message);
  }
}

@@ -100,22 +100,110 @@
 ar.base.
-Module
+GitInfo;%0Aimport com.hubspot.blazar.base.ModuleBuild;%0Aimport com.hubspot.blazar.base.Repository
 Build;%0Ai
@@ -397,16 +397,165 @@
 lient %7B%0A
+  private static final String GET_GIT_INFO_PATH = %22/branches/%25s%22;%0A%0A  private static final String GET_REPOSITORY_BUILD_PATH = %22/branches/builds/%25s%22;%0A%0A
   privat
@@ -1187,16 +1187,16 @@
 Client;%0A
-
     this
@@ -1216,24 +1216,1112 @@
 seUrl;%0A  %7D%0A%0A
+  public Optional%3CGitInfo%3E getGitInfo(long branchId) %7B%0A    String url = String.format(baseUrl + GET_GIT_INFO_PATH, branchId);%0A    HttpRequest request = HttpRequest.newBuilder().setMethod(Method.GET).setUrl(url).build();%0A%0A    HttpResponse response = httpClient.execute(request);%0A    if (response.getStatusCode() == 404) %7B%0A      return Optional.absent();%0A    %7D else if (response.getStatusCode() == 200) %7B%0A      return Optional.of(response.getAs(GitInfo.class));%0A    %7D else %7B%0A      throw toException(response);%0A    %7D%0A  %7D%0A%0A  public Optional%3CRepositoryBuild%3E getRepositoryBuild(long repositoryBuildId) %7B%0A    String url = String.format(baseUrl + GET_REPOSITORY_BUILD_PATH, repositoryBuildId);%0A    HttpRequest request = HttpRequest.newBuilder().setMethod(Method.GET).setUrl(url).build();%0A%0A    HttpResponse response = httpClient.execute(request);%0A    if (response.getStatusCode() == 404) %7B%0A      return Optional.absent();%0A    %7D else if (response.getStatusCode() == 200) %7B%0A      return Optional.of(response.getAs(RepositoryBuild.class));%0A    %7D else %7B%0A      throw toException(response);%0A    %7D%0A  %7D%0A%0A
   public Opt

Add client methods to get repo build and git info