Browse files

Trying direct GSON serializer for High level API

  • Loading branch information...
1 parent 268fa07 commit 2e194782e0050241d5f76ef8f064455c67a8833a @richard-julien committed Mar 22, 2012
View
16 client/src/main/java/io/iron/ironworker/client/Client.java
@@ -7,6 +7,7 @@
import io.iron.ironworker.client.codes.BaseCode;
import io.iron.ironworker.client.entities.CodeEntity;
import io.iron.ironworker.client.entities.CodeRevisionEntity;
+import io.iron.ironworker.client.entities.Codes;
import io.iron.ironworker.client.entities.TaskEntity;
import java.util.ArrayList;
@@ -25,23 +26,16 @@ public APIClient getAPI() {
return api;
}
- public List<CodeEntity> getCodes(Map<String, Object> options) throws APIException {
+ public Codes getCodes(Map<String, Object> options) throws APIException {
JsonObject codes = api.codesList(options);
-
- List<CodeEntity> codesList = new ArrayList<CodeEntity>();
-
- for (JsonElement code : codes.get("codes").getAsJsonArray()) {
- codesList.add(CodeEntity.fromJsonObject(code.getAsJsonObject()));
- }
-
- return codesList;
+ return new Gson().fromJson(codes, Codes.class);
}
- public List<CodeEntity> getCodes(PaginationOptionsObject options) throws APIException {
+ public Codes getCodes(PaginationOptionsObject options) throws APIException {
return getCodes(options.create());
}
- public List<CodeEntity> getCodes() throws APIException {
+ public Codes getCodes() throws APIException {
return getCodes((Map<String, Object>) null);
}
View
126 client/src/main/java/io/iron/ironworker/client/entities/Code.java
@@ -0,0 +1,126 @@
+package io.iron.ironworker.client.entities;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.util.Date;
+
+/**
+ * User: Julien
+ * Date: 22/03/12
+ * Time: 17:27
+ */
+public class Code {
+ private String id;
+ @SerializedName("project_id")
+ private String projectId;
+ private String name;
+ private String runtime;
+ @SerializedName("latest_checksum")
+ private String latestChecksum;
+ @SerializedName("rev")
+ private int revision;
+ @SerializedName("latest_history_id")
+ private String latestHistoryId;
+ @SerializedName("latest_change")
+ private Date latestChange;
+ @SerializedName("created_at")
+ private Date createdAt;
+ @SerializedName("updated_at")
+ private Date updatedAt;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getProjectId() {
+ return projectId;
+ }
+
+ public void setProjectId(String projectId) {
+ this.projectId = projectId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getRuntime() {
+ return runtime;
+ }
+
+ public void setRuntime(String runtime) {
+ this.runtime = runtime;
+ }
+
+ public int getRevision() {
+ return revision;
+ }
+
+ public void setRevision(int revision) {
+ this.revision = revision;
+ }
+
+ public String getLatestHistoryId() {
+ return latestHistoryId;
+ }
+
+ public void setLatestHistoryId(String latestHistoryId) {
+ this.latestHistoryId = latestHistoryId;
+ }
+
+ public String getLatestChecksum() {
+ return latestChecksum;
+ }
+
+ public void setLatestChecksum(String latestChecksum) {
+ this.latestChecksum = latestChecksum;
+ }
+
+ public Date getLatestChange() {
+ return latestChange;
+ }
+
+ public void setLatestChange(Date latestChange) {
+ this.latestChange = latestChange;
+ }
+
+ public Date getCreatedAt() {
+ return createdAt;
+ }
+
+ public void setCreatedAt(Date createdAt) {
+ this.createdAt = createdAt;
+ }
+
+ public Date getUpdatedAt() {
+ return updatedAt;
+ }
+
+ public void setUpdatedAt(Date updatedAt) {
+ this.updatedAt = updatedAt;
+ }
+
+ @Override
+ public String toString() {
+ return "Code{" +
+ "id='" + id + '\'' +
+ ", projectId='" + projectId + '\'' +
+ ", name='" + name + '\'' +
+ ", runtime='" + runtime + '\'' +
+ ", latestChecksum='" + latestChecksum + '\'' +
+ ", revision=" + revision +
+ ", latestHistoryId='" + latestHistoryId + '\'' +
+ ", latestChange=" + latestChange +
+ ", createdAt=" + createdAt +
+ ", updatedAt=" + updatedAt +
+ '}';
+ }
+}
View
27 client/src/main/java/io/iron/ironworker/client/entities/Codes.java
@@ -0,0 +1,27 @@
+package io.iron.ironworker.client.entities;
+
+import java.util.List;
+
+/**
+ * User: Julien
+ * Date: 22/03/12
+ * Time: 17:27
+ */
+public class Codes {
+ private List<Code> codes;
+
+ public List<Code> getCodes() {
+ return codes;
+ }
+
+ public void setCodes(List<Code> codes) {
+ this.codes = codes;
+ }
+
+ @Override
+ public String toString() {
+ return "Codes{" +
+ "codes=" + codes +
+ '}';
+ }
+}
View
34 client/src/test/java/io/iron/ironworker/client/ClientTest.java
@@ -0,0 +1,34 @@
+package io.iron.ironworker.client;
+
+import io.iron.ironworker.client.entities.CodeEntity;
+import io.iron.ironworker.client.entities.Codes;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+/**
+ * User: Julien
+ * Date: 22/03/12
+ * Time: 17:24
+ */
+public class ClientTest {
+
+ private static String _ironToken;
+ private static String _ironProjectId;
+
+ @BeforeClass
+ public static void init() {
+ _ironToken = "P7g9m72eTekPHd0bNCkCeBytrhQ";
+ _ironProjectId = "4f63775f8de4561d19000804";
+ }
+
+ @Test
+ public void shouldHaveEnvironmentVariable() throws APIException {
+ Client client = new Client(_ironToken, _ironProjectId);
+ Codes codes = client.getCodes();
+ System.out.println(codes);
+ }
+}

0 comments on commit 2e19478

Please sign in to comment.