Skip to content

Commit 8eb66e3

Browse files
committed
Merge branch 'master' of https://github.com/creatubbles/api
# Conflicts: # src/main/java/com/creatubbles/api/CreatubblesAPI.java # src/main/java/com/creatubbles/api/util/EndPoints.java
2 parents d69a624 + 84b5239 commit 8eb66e3

18 files changed

+301
-70
lines changed

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

+39-10
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,37 @@
55
import java.lang.reflect.Type;
66
import java.nio.file.Files;
77

8-
import com.google.gson.*;
9-
108
import org.glassfish.jersey.client.ClientProperties;
119
import org.glassfish.jersey.client.JerseyClient;
1210
import org.glassfish.jersey.client.JerseyClientBuilder;
1311

1412
import com.creatubbles.api.core.Gallery;
15-
import com.creatubbles.api.request.amazon.UploadS3ImageRequest;
13+
import com.creatubbles.api.core.LandingUrl;
14+
import com.creatubbles.api.request.amazon.UploadS3FileRequest;
1615
import com.creatubbles.api.request.creation.CreateCreationRequest;
1716
import com.creatubbles.api.request.creation.CreationsUploadsRequest;
1817
import com.creatubbles.api.request.creation.PingCreationsUploadsRequest;
18+
import com.creatubbles.api.request.landingurls.GetLandingUrlsRequest;
19+
import com.creatubbles.api.request.landingurls.GetSpecificLandingUrlRequest;
1920
import com.creatubbles.api.response.auth.SignUpResponse;
2021
import com.creatubbles.api.response.creation.CreateCreationResponse;
2122
import com.creatubbles.api.response.creation.CreationsUploadsResponse;
2223
import com.creatubbles.api.response.creation.GetCreationsResponse;
23-
import com.creatubbles.api.response.creation.LandingURLResponse;
2424
import com.creatubbles.api.response.creator.CreateCreatorResponse;
2525
import com.creatubbles.api.response.creator.GetCreatorsResponse;
2626
import com.creatubbles.api.response.gallery.CreateUserGalleryResponse;
27+
import com.creatubbles.api.response.landingurls.GetCreationLandingUrlResponse;
28+
import com.creatubbles.api.response.landingurls.GetLandingUrlsResponse;
29+
import com.creatubbles.api.response.landingurls.GetSpecificLandingUrlResponse;
2730
import com.creatubbles.api.response.user.UserProfileResponse;
2831
import com.creatubbles.api.util.EndPoints;
32+
import com.creatubbles.api.util.HttpUtil;
33+
import com.google.gson.Gson;
34+
import com.google.gson.GsonBuilder;
35+
import com.google.gson.JsonDeserializationContext;
36+
import com.google.gson.JsonDeserializer;
37+
import com.google.gson.JsonElement;
38+
import com.google.gson.JsonParseException;
2939

3040

3141
@SuppressWarnings("deprecation")
@@ -41,7 +51,9 @@ public class CreatubblesAPI {
4151
.registerTypeAdapter(GetCreationsResponse.class, new GetCreationsResponse())
4252
.registerTypeAdapter(CreateCreationResponse.class, new CreateCreationResponse())
4353
.registerTypeAdapter(CreationsUploadsResponse.class, new CreationsUploadsResponse())
44-
.registerTypeAdapter(LandingURLResponse.class, new LandingURLResponse())
54+
.registerTypeAdapter(GetLandingUrlsResponse.class, new GetLandingUrlsResponse())
55+
.registerTypeAdapter(GetSpecificLandingUrlResponse.class, new GetSpecificLandingUrlResponse())
56+
.registerTypeAdapter(GetCreationLandingUrlResponse.class, new GetCreationLandingUrlResponse())
4557
.registerTypeAdapter(String.class, new StringAdapter())
4658
.create();
4759

@@ -52,6 +64,9 @@ public class CreatubblesAPI {
5264
.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, Boolean.TRUE);
5365

5466
public static String buildURL(final String endPoint) {
67+
if (endPoint.startsWith("https://")) {
68+
return endPoint;
69+
}
5570
String base = staging ? EndPoints.URL_BASE_STAGING : EndPoints.URL_BASE;
5671
return base.concat(endPoint);
5772
}
@@ -64,25 +79,39 @@ public static void setStagingMode(boolean staging) {
6479

6580
public static void main(String[] args) throws IOException {
6681
// Additional examples can be found in the JUnit test files
67-
82+
6883
CreatubblesAPI.setStagingMode(true);
6984
String accessToken = ""; // TODO commit tests AuthTests.getAuthToken();
7085

7186
CreateCreationRequest createCreation = new CreateCreationRequest(accessToken);
7287
CreateCreationResponse createCreationResponse = createCreation.execute().getResponse();
7388
System.out.println(createCreationResponse.creation.id);
7489

75-
CreationsUploadsRequest creationsUploads = new CreationsUploadsRequest(createCreationResponse.creation.id, accessToken);
90+
File file = new File("C:/dev/1.png");
91+
String extension = HttpUtil.getExtension(file.getPath());
92+
93+
CreationsUploadsRequest creationsUploads = new CreationsUploadsRequest(createCreationResponse.creation.id, extension, accessToken);
7694
CreationsUploadsResponse creationsUploadsResponse = creationsUploads.execute().getResponse();
7795
System.out.println(creationsUploadsResponse.url);
7896
System.out.println(creationsUploadsResponse.id);
7997

80-
File file = new File("C:/dev/1.png");
98+
GetLandingUrlsRequest getLandingUrls = new GetLandingUrlsRequest(accessToken);
99+
for (LandingUrl landingUrl : getLandingUrls.execute().getResponse().urls) {
100+
System.out.println(landingUrl.type + ":" + landingUrl.url);
101+
}
102+
103+
GetSpecificLandingUrlRequest getSpecificLandingUrl = new GetSpecificLandingUrlRequest(accessToken, LandingUrl.LandingUrlType.CTB_USER_PROFILE);
104+
GetSpecificLandingUrlResponse getSpecificLandingUrlResponse = getSpecificLandingUrl.execute().getResponse();
105+
LandingUrl url = getSpecificLandingUrlResponse.url;
106+
System.out.println("specific url - " + url.type + ":" + url.url);
107+
81108
byte[] data = Files.readAllBytes(file.toPath());
82-
UploadS3ImageRequest uploadS3Image = new UploadS3ImageRequest(data, creationsUploadsResponse.url);
109+
110+
UploadS3FileRequest uploadS3Image = new UploadS3FileRequest(data, creationsUploadsResponse.url, creationsUploadsResponse.content_type);
83111
uploadS3Image.execute().getResponse();
84112

85-
PingCreationsUploadsRequest pingCreationsUploads = new PingCreationsUploadsRequest(creationsUploadsResponse.id, accessToken);
113+
PingCreationsUploadsRequest pingCreationsUploads = new PingCreationsUploadsRequest(creationsUploadsResponse.ping_url, accessToken);
114+
pingCreationsUploads.setData("");
86115
pingCreationsUploads.execute().getResponse();
87116
System.out.println("-Finish-");
88117
}

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

-16
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
public abstract class CreatubblesRequest<T extends CreatubblesResponse> {
2121
private String endPoint, acceptLanguage, data;
22-
private String xSource = "mc-mod";
2322
private HttpMethod httpMethod;
2423
private Map<String, String> urlParameters;
2524
private Response response;
@@ -87,15 +86,6 @@ public CreatubblesRequest<T> setAcceptLanguage(String acceptLanguage) {
8786
return this;
8887
}
8988

90-
public String getXSource() {
91-
return xSource;
92-
}
93-
94-
public CreatubblesRequest<T> setXSource(String xSource) {
95-
this.xSource = xSource;
96-
return this;
97-
}
98-
9989
public String getData() {
10090
return data;
10191
}
@@ -214,9 +204,6 @@ public CreatubblesRequest<T> execute() {
214204
if (accessToken != null && !accessToken.isEmpty()) {
215205
invocationBuilder.header("Authorization", "Bearer " + accessToken);
216206
}
217-
if (xSource != null && !xSource.isEmpty()) {
218-
invocationBuilder.header("X-Source", xSource.toLowerCase());
219-
}
220207

221208
if (httpMethod == HttpMethod.GET) {
222209
response = invocationBuilder.get();
@@ -251,9 +238,6 @@ public CreatubblesRequest<T> async() {
251238
if (accessToken != null && !accessToken.isEmpty()) {
252239
invocationBuilder.header("Authorization", "Bearer " + accessToken);
253240
}
254-
if (xSource != null && !xSource.isEmpty()) {
255-
invocationBuilder.header("X-Source", xSource.toLowerCase());
256-
}
257241

258242
if (httpMethod == HttpMethod.GET) {
259243
futureResponse = invocationBuilder.async().get();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.creatubbles.api.core;
2+
3+
/**
4+
* Created by Jevgeni on 10.03.2016.
5+
*/
6+
public class LandingUrl {
7+
8+
public LandingUrlType type;
9+
public String url;
10+
11+
public enum LandingUrlType {
12+
13+
CTB_ABOUT_US("ctb-about_us"),
14+
CTB_TERMS_OF_USE("ctb-terms_of_use"),
15+
CTB_PRIVACY_POLICY("ctb-privacy_policy"),
16+
CTB_REGISTRATION("ctb-registration"),
17+
CTB_FORGOT_PASSWORD("ctb-forgot_password"),
18+
CTB_USER_PROFILE("ctb-user_profile"),
19+
CTB_EXPLORE("ctb-explore");
20+
21+
private String type;
22+
23+
public String getType() {
24+
return type;
25+
}
26+
27+
LandingUrlType(String type) {
28+
this.type = type;
29+
}
30+
31+
public static LandingUrlType from(String type) {
32+
for (LandingUrlType e : LandingUrlType.values()) {
33+
if (e.getType().equals(type)) {
34+
return e;
35+
}
36+
}
37+
throw new IllegalStateException();
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return type;
43+
}
44+
}
45+
}

src/main/java/com/creatubbles/api/request/amazon/UploadS3ImageRequest.java renamed to src/main/java/com/creatubbles/api/request/amazon/UploadS3FileRequest.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.creatubbles.api.APIVersion;
44
import com.creatubbles.api.core.CreatubblesRequest;
5-
import com.creatubbles.api.response.amazon.UploadS3ImageResponse;
5+
import com.creatubbles.api.response.amazon.UploadS3FileResponse;
66
import com.creatubbles.api.util.HttpUtil;
77
import com.creatubbles.api.util.HttpUtil.Response;
88

@@ -12,28 +12,30 @@
1212
* Created by Jevgeni on 28.10.2015.
1313
*/
1414
@APIVersion(2)
15-
public class UploadS3ImageRequest extends CreatubblesRequest<UploadS3ImageResponse> {
15+
public class UploadS3FileRequest extends CreatubblesRequest<UploadS3FileResponse> {
1616

1717
private byte[] data;
1818
private String url;
19+
private String contentType;
1920

20-
public UploadS3ImageRequest(byte[] data, String url) {
21+
public UploadS3FileRequest(byte[] data, String url, String contentType) {
2122
super(null, null);
2223
this.data = data;
2324
this.url = url;
25+
this.contentType = contentType;
2426
}
2527

2628
@Override
27-
public Class<? extends UploadS3ImageResponse> getResponseClass() {
28-
return UploadS3ImageResponse.class;
29+
public Class<? extends UploadS3FileResponse> getResponseClass() {
30+
return UploadS3FileResponse.class;
2931
}
3032

3133
@Override
32-
public CreatubblesRequest<UploadS3ImageResponse> execute() {
34+
public CreatubblesRequest<UploadS3FileResponse> execute() {
3335
resetResponse();
34-
UploadS3ImageResponse response = new UploadS3ImageResponse();
36+
UploadS3FileResponse response = new UploadS3FileResponse();
3537
try {
36-
Response resp = HttpUtil.uploadObject(data, url, HttpUtil.IMAGE_JPEG_CONTENT_TYPE);
38+
Response resp = HttpUtil.uploadObject(data, url, contentType);
3739
response.success = isSuccessStatusCode(resp.code);
3840
response.message = resp.message;
3941
setResponseCache(response);

src/main/java/com/creatubbles/api/request/auth/OAuthAccessTokenRequest.java

-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ public CreatubblesRequest<OAuthAccessTokenResponse> execute() {
4242
.request(MediaType.APPLICATION_FORM_URLENCODED)
4343
.accept(MediaType.APPLICATION_JSON);
4444

45-
if (getXSource() != null && !getXSource().isEmpty()) {
46-
invocationBuilder.header("X-Source", getXSource().toLowerCase());
47-
}
48-
4945
Form form = new Form() //
5046
.param("grant_type", "password") //
5147
.param("client_id", CLIENT_ID) //

src/main/java/com/creatubbles/api/request/creation/CreationsUploadsRequest.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,33 @@
55
import com.creatubbles.api.response.creation.CreationsUploadsResponse;
66
import com.creatubbles.api.util.EndPoints;
77
import com.creatubbles.api.util.HttpMethod;
8+
import com.creatubbles.api.util.HttpUtil;
89

910
@APIVersion(2)
1011
public class CreationsUploadsRequest extends CreatubblesRequest<CreationsUploadsResponse> {
1112

12-
public CreationsUploadsRequest(String creationId, String accessToken) {
13+
private String extension;
14+
15+
public CreationsUploadsRequest(String creationId, String extension, String accessToken) {
1316
super(String.format(EndPoints.CREATIONS_UPLOADS, creationId), HttpMethod.POST, accessToken);
17+
this.extension = extension;
18+
setUrlParameter("extension", extension);
1419
}
1520

1621
@Override
1722
public Class<? extends CreationsUploadsResponse> getResponseClass() {
1823
return CreationsUploadsResponse.class;
1924
}
25+
26+
@Override
27+
public CreatubblesRequest<CreationsUploadsResponse> execute() {
28+
if (extension == null || !HttpUtil.allowedFileTypes.contains(extension)) {
29+
resetResponse();
30+
CreationsUploadsResponse response = new CreationsUploadsResponse();
31+
response.message = String.format("Invalid file with type %s", extension);
32+
setResponseCache(response);
33+
return this;
34+
}
35+
return super.execute();
36+
}
2037
}

src/main/java/com/creatubbles/api/request/creation/LandingURLRequest.java

-19
This file was deleted.

src/main/java/com/creatubbles/api/request/creation/PingCreationsUploadsRequest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
@APIVersion(2)
1313
public class PingCreationsUploadsRequest extends CreatubblesRequest<PingCreationsUploadsResponse> {
1414

15-
public PingCreationsUploadsRequest(int uploadId, String accessToken) {
16-
super(String.format(EndPoints.PING_CREATIONS_UPLOADS, uploadId), HttpMethod.PUT, accessToken);
15+
public PingCreationsUploadsRequest(String url, String accessToken) {
16+
super(url, HttpMethod.PUT, accessToken);
1717
}
1818

1919
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.creatubbles.api.request.landingurls;
2+
3+
import com.creatubbles.api.core.CreatubblesRequest;
4+
import com.creatubbles.api.response.landingurls.GetCreationLandingUrlResponse;
5+
import com.creatubbles.api.util.EndPoints;
6+
import com.creatubbles.api.util.HttpMethod;
7+
8+
9+
public class GetCreationLandingUrlRequest extends CreatubblesRequest<GetCreationLandingUrlResponse> {
10+
11+
public GetCreationLandingUrlRequest(String creationId, String accessToken) {
12+
super(String.format(EndPoints.CREATION_LANDING_URL, creationId), HttpMethod.GET, accessToken);
13+
}
14+
15+
@Override
16+
public Class<? extends GetCreationLandingUrlResponse> getResponseClass() {
17+
return GetCreationLandingUrlResponse.class;
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.creatubbles.api.request.landingurls;
2+
3+
import com.creatubbles.api.APIVersion;
4+
import com.creatubbles.api.core.CreatubblesRequest;
5+
import com.creatubbles.api.response.landingurls.GetLandingUrlsResponse;
6+
import com.creatubbles.api.util.HttpMethod;
7+
8+
import static com.creatubbles.api.util.EndPoints.LANDING_URLS;
9+
10+
/**
11+
* Created by Jevgeni on 09.03.2016.
12+
*/
13+
@APIVersion(2)
14+
public class GetLandingUrlsRequest extends CreatubblesRequest<GetLandingUrlsResponse> {
15+
16+
public GetLandingUrlsRequest(String accessToken) {
17+
super(LANDING_URLS, HttpMethod.GET, accessToken);
18+
}
19+
20+
@Override
21+
public Class<? extends GetLandingUrlsResponse> getResponseClass() {
22+
return GetLandingUrlsResponse.class;
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.creatubbles.api.request.landingurls;
2+
3+
import com.creatubbles.api.APIVersion;
4+
import com.creatubbles.api.core.CreatubblesRequest;
5+
import com.creatubbles.api.core.LandingUrl;
6+
import com.creatubbles.api.response.landingurls.GetSpecificLandingUrlResponse;
7+
import com.creatubbles.api.util.HttpMethod;
8+
9+
import static com.creatubbles.api.util.EndPoints.SPECIFIC_LANDING_URL;
10+
11+
/**
12+
* Created by Jevgeni on 09.03.2016.
13+
*/
14+
@APIVersion(2)
15+
public class GetSpecificLandingUrlRequest extends CreatubblesRequest<GetSpecificLandingUrlResponse> {
16+
17+
public GetSpecificLandingUrlRequest(String accessToken, LandingUrl.LandingUrlType type) {
18+
super(String.format(SPECIFIC_LANDING_URL, type), HttpMethod.GET, accessToken);
19+
}
20+
21+
@Override
22+
public Class<? extends GetSpecificLandingUrlResponse> getResponseClass() {
23+
return GetSpecificLandingUrlResponse.class;
24+
}
25+
}

0 commit comments

Comments
 (0)