Skip to content

Commit 2d07a36

Browse files
committed
Clean up metadata, fix gallery serialization, other general cleanup
1 parent 3a6e272 commit 2d07a36

File tree

6 files changed

+34
-33
lines changed

6 files changed

+34
-33
lines changed

src/main/java/com/creatubbles/api/CreatubblesAPI.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.glassfish.jersey.client.JerseyClient;
1111
import org.glassfish.jersey.client.JerseyClientBuilder;
1212

13+
import com.creatubbles.api.core.Gallery;
1314
import com.creatubbles.api.core.LandingUrl;
1415
import com.creatubbles.api.request.amazon.UploadS3FileRequest;
1516
import com.creatubbles.api.request.creation.CreateCreationRequest;
@@ -43,8 +44,9 @@ public class CreatubblesAPI {
4344
public static final String URL_BASE_STAGING = "https://api.staging.creatubbles.com/v2/";
4445

4546
public final static Gson GSON = new GsonBuilder()
47+
.registerTypeAdapter(Gallery.class, new Gallery.Serializer())
4648
.registerTypeAdapter(String.class, new StringAdapter())
47-
.registerTypeAdapterFactory(new JsonHackx())
49+
.registerTypeAdapterFactory(new JsonHacks())
4850
.create();
4951

5052
public final static JerseyClient CLIENT = JerseyClientBuilder
@@ -121,7 +123,7 @@ public String deserialize(JsonElement json, Type typeOfT,
121123
}
122124
}
123125

124-
private static class JsonHackx implements TypeAdapterFactory {
126+
private static class JsonHacks implements TypeAdapterFactory {
125127

126128
@Override
127129
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {

src/main/java/com/creatubbles/api/core/CreatubblesRequest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
import javax.ws.rs.core.Response;
1414

1515
import jersey.repackaged.com.google.common.base.Throwables;
16-
import jersey.repackaged.com.google.common.collect.Lists;
1716

1817
import org.glassfish.jersey.client.JerseyWebTarget;
1918
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
2019

2120
import com.creatubbles.api.CreatubblesAPI;
2221
import com.creatubbles.api.response.ArrayResponse;
22+
import com.creatubbles.api.response.meta.Metadata;
2323
import com.creatubbles.api.util.HttpMethod;
2424
import com.google.gson.JsonObject;
2525
import com.google.gson.JsonSyntaxException;
@@ -35,7 +35,7 @@ public abstract class CreatubblesRequest<T extends CreatubblesResponse> {
3535
private T responseCache;
3636
private T[] responseArrayCache;
3737
private JsonObject metaCache;
38-
38+
3939
private String accessToken;
4040
private static final String EMPTY_RESPONSE = "{}";
4141
private static final String APPLICATION_VND_API_JSON = "application/vnd.api+json";
@@ -225,7 +225,7 @@ private T createDefaultResponse(String json) {
225225
throw Throwables.propagate(e);
226226
}
227227
}
228-
228+
229229
public final boolean isArrayResponse() {
230230
return getResponseClass().isAnnotationPresent(ArrayResponse.class);
231231
}
@@ -247,10 +247,10 @@ public final T getResponse() {
247247
*/
248248
public final List<T> getResponseList() {
249249
initResponse();
250-
return responseArrayCache == null ? Lists.<T>newArrayList() : Arrays.asList(responseArrayCache);
250+
return responseArrayCache == null ? null : Arrays.asList(responseArrayCache);
251251
}
252-
253-
public final <M> M getMetadata(Class<M> metaClass) {
252+
253+
public final <M extends Metadata> M getMetadata(Class<M> metaClass) {
254254
return CreatubblesAPI.GSON.fromJson(metaCache, metaClass);
255255
}
256256

src/main/java/com/creatubbles/api/core/Gallery.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,55 @@
1414
@Value
1515
@Builder
1616
public class Gallery {
17-
17+
1818
int id;
1919
String name, description;
20-
20+
2121
@SerializedName("type")
2222
String type;
2323
@SerializedName("created_at")
2424
String createdDate;
2525
Image banner;
26-
26+
2727
@SerializedName("open_for_all")
28-
public boolean openForAll;
29-
28+
boolean openForAll;
29+
3030
@SerializedName("owner_id")
31-
public int ownerId;
31+
int ownerId;
3232
@SerializedName("owner_type")
33-
public String ownerType;
34-
33+
String ownerType;
34+
3535
public static class Serializer implements JsonSerializer<Gallery> {
36-
36+
3737
@Override
3838
public JsonElement serialize(Gallery src, Type typeOfSrc, JsonSerializationContext context) {
39-
39+
4040
JsonObject root = new JsonObject();
41-
41+
4242
JsonObject data = new JsonObject();
4343
data.addProperty("type", src.type);
44-
44+
4545
JsonObject attributes = new JsonObject();
4646
attributes.addProperty("name", src.name);
4747
attributes.addProperty("descrtiption", src.description);
4848
attributes.addProperty("open_for_all", src.openForAll ? 1 : 0);
49-
49+
5050
JsonObject relationships = new JsonObject();
51-
51+
5252
JsonObject owner = new JsonObject();
5353
JsonObject ownerdata = new JsonObject();
5454
ownerdata.addProperty("type", src.ownerType);
5555
ownerdata.addProperty("id", src.ownerId);
5656
owner.add("data", ownerdata);
57-
57+
5858
relationships.add("owner", owner);
59-
59+
6060
data.add("attributes", attributes);
6161
data.add("relationships", relationships);
62-
62+
6363
root.add("data", data);
6464
return root;
6565
}
6666
}
67-
67+
6868
}

src/main/java/com/creatubbles/api/core/Group.java

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/main/java/com/creatubbles/api/response/meta/MetaPagination.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.google.gson.annotations.SerializedName;
66

77
@Value
8-
public class MetaPagination {
8+
public class MetaPagination implements Metadata {
99

1010
@SerializedName("total_count")
1111
int objectCount;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.creatubbles.api.response.meta;
2+
3+
public interface Metadata {
4+
5+
}

0 commit comments

Comments
 (0)