Skip to content

Commit

Permalink
Added a readme. Also removed the StageState since the enum was not ad…
Browse files Browse the repository at this point in the history
…ding any value
  • Loading branch information
itspanzi authored and janmejay committed Nov 29, 2011
1 parent 65eb812 commit 08a31d6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
35 changes: 35 additions & 0 deletions Readme.textile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
h2. Introduction

*Go API Client* is a client library that allows users to interact with a "Thoughtworks Studios Go":http://studios.thoughtworks.com/go server's web API.

The Go server exposes data and actions over HTTP RESTful APIs. This library lets users use Java as the client library.

h2. Why?

This library:

* Shields the user from knowing the format of the XML documents returned as resources
* Expose POJOs which give access to different domain concepts like pipeline, stage, job, material etc
* Adds client side caching so that the Go server is not spammed more than required
* Expose nice helper methods which help build custom reports quite easily
* Provide version specific APIs

h2. How do I use this?

@TalkToGo@ is the interface that exposes everything that can be done with the Go server. There is a release specific implementation of this interface. For example, if you always want the latest server API, you can use the @TalkToGoLatest@ implementation.

A sample usage of this client is as follows:

@
HttpClientWrapper wrapper = new HttpClientWrapper("server.host", 8153, "username", "password");
TalkToGoLatest talkToGo = new TalkToGoLatest("pipeline", wrapper, false);
Stage stage = talkToGo.latestStage("stage");
System.out.println("The latest stage result is: " + stage.getResult());
System.out.println(String.format("Latest stage info: %s %s %s", stage.getCounter(), stage.getPipelineLabel(), stage.getPipelineCounter()));
@

You need to create a @HttpClientWrapper@ which is what is used to interact with the Go server. @TalkToGoLatest@ is created for the pipeline with name "pipeline". Using this instance, you can start interacting with the Go server to get the latest stage, latest pipeline instance etc.

h2. API Documentation

Since this is an API client, you can checkout the Javadocs on all the Java classes.
8 changes: 4 additions & 4 deletions src/com/thoughtworks/go/domain/Stage.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public class Stage {
private final StagePipeline pipeline;
private final Date lastUpdated;
private final String result;
private final StageState state;
private final String state;
private final String approvedBy;
private final List<StageJob> stageJobs;
private HttpClientWrapper httpClientWrapper;

private Stage(String name, int counter, StagePipeline pipeline, Date lastUpdated, String result, StageState state, String approvedBy, List<StageJob> stageJobs) {
private Stage(String name, int counter, StagePipeline pipeline, Date lastUpdated, String result, String state, String approvedBy, List<StageJob> stageJobs) {
this.name = name;
this.counter = counter;
this.pipeline = pipeline;
Expand All @@ -46,7 +46,7 @@ public static Stage create(String resourceText) {
StagePipeline pip = new StagePipeline(attrVal(pipeline, "name"), attrVal(pipeline, "counter"), attrVal(pipeline, "label"), attrVal(pipeline, "href"));
Date lastUpdated = DateUtil.toDate(nodeText(doc, "//updated"));
String result = nodeText(doc, "//result");
StageState state = StageState.valueOf(nodeText(doc, "//state"));
String state = nodeText(doc, "//state");
String approvedBy = nodeText(doc, "//approvedBy");
List<StageJob> stageJobs = stageJobs(doc);
return new Stage(name, Integer.parseInt(counter), pip, lastUpdated, result, state, approvedBy, stageJobs);
Expand Down Expand Up @@ -138,7 +138,7 @@ public String getResult() {
*
* @return the state of the stage.
*/
public StageState getState() {
public String getState() {
return state;
}

Expand Down
5 changes: 0 additions & 5 deletions src/com/thoughtworks/go/domain/StageState.java

This file was deleted.

7 changes: 2 additions & 5 deletions test/com/thoughtworks/go/domain/StageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@

import java.io.IOException;
import java.io.File;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.TimeZone;

import static junit.framework.Assert.fail;
import com.thoughtworks.go.domain.Pipeline;
import com.thoughtworks.go.domain.Job;
import com.thoughtworks.go.domain.Stage;

import com.thoughtworks.go.http.HttpClientWrapper;

public class StageTest {
Expand All @@ -35,7 +32,7 @@ public void shouldCreateAStage() throws Exception {
gregorianCalendar.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta"));
assertThat(stage.getLastUpdated(), is(gregorianCalendar.getTime()));
assertThat(stage.getResult(), is("Failed"));
assertThat(stage.getState(), is(StageState.Failing));
assertThat(stage.getState(), is("Failing"));
assertThat(stage.getApprovedBy(), is("CruiseTimer"));
assertThat(stage.getStageLocator(), is("pipeline/9/stage/1"));
}
Expand Down

0 comments on commit 08a31d6

Please sign in to comment.