5
5
import java .lang .reflect .Type ;
6
6
import java .nio .file .Files ;
7
7
8
- import com .google .gson .*;
9
-
10
8
import org .glassfish .jersey .client .ClientProperties ;
11
9
import org .glassfish .jersey .client .JerseyClient ;
12
10
import org .glassfish .jersey .client .JerseyClientBuilder ;
13
11
14
12
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 ;
16
15
import com .creatubbles .api .request .creation .CreateCreationRequest ;
17
16
import com .creatubbles .api .request .creation .CreationsUploadsRequest ;
18
17
import com .creatubbles .api .request .creation .PingCreationsUploadsRequest ;
18
+ import com .creatubbles .api .request .landingurls .GetLandingUrlsRequest ;
19
+ import com .creatubbles .api .request .landingurls .GetSpecificLandingUrlRequest ;
19
20
import com .creatubbles .api .response .auth .SignUpResponse ;
20
21
import com .creatubbles .api .response .creation .CreateCreationResponse ;
21
22
import com .creatubbles .api .response .creation .CreationsUploadsResponse ;
22
23
import com .creatubbles .api .response .creation .GetCreationsResponse ;
23
- import com .creatubbles .api .response .creation .LandingURLResponse ;
24
24
import com .creatubbles .api .response .creator .CreateCreatorResponse ;
25
25
import com .creatubbles .api .response .creator .GetCreatorsResponse ;
26
26
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 ;
27
30
import com .creatubbles .api .response .user .UserProfileResponse ;
28
31
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 ;
29
39
30
40
31
41
@ SuppressWarnings ("deprecation" )
@@ -41,7 +51,9 @@ public class CreatubblesAPI {
41
51
.registerTypeAdapter (GetCreationsResponse .class , new GetCreationsResponse ())
42
52
.registerTypeAdapter (CreateCreationResponse .class , new CreateCreationResponse ())
43
53
.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 ())
45
57
.registerTypeAdapter (String .class , new StringAdapter ())
46
58
.create ();
47
59
@@ -52,6 +64,9 @@ public class CreatubblesAPI {
52
64
.property (ClientProperties .SUPPRESS_HTTP_COMPLIANCE_VALIDATION , Boolean .TRUE );
53
65
54
66
public static String buildURL (final String endPoint ) {
67
+ if (endPoint .startsWith ("https://" )) {
68
+ return endPoint ;
69
+ }
55
70
String base = staging ? EndPoints .URL_BASE_STAGING : EndPoints .URL_BASE ;
56
71
return base .concat (endPoint );
57
72
}
@@ -64,25 +79,39 @@ public static void setStagingMode(boolean staging) {
64
79
65
80
public static void main (String [] args ) throws IOException {
66
81
// Additional examples can be found in the JUnit test files
67
-
82
+
68
83
CreatubblesAPI .setStagingMode (true );
69
84
String accessToken = "" ; // TODO commit tests AuthTests.getAuthToken();
70
85
71
86
CreateCreationRequest createCreation = new CreateCreationRequest (accessToken );
72
87
CreateCreationResponse createCreationResponse = createCreation .execute ().getResponse ();
73
88
System .out .println (createCreationResponse .creation .id );
74
89
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 );
76
94
CreationsUploadsResponse creationsUploadsResponse = creationsUploads .execute ().getResponse ();
77
95
System .out .println (creationsUploadsResponse .url );
78
96
System .out .println (creationsUploadsResponse .id );
79
97
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
+
81
108
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 );
83
111
uploadS3Image .execute ().getResponse ();
84
112
85
- PingCreationsUploadsRequest pingCreationsUploads = new PingCreationsUploadsRequest (creationsUploadsResponse .id , accessToken );
113
+ PingCreationsUploadsRequest pingCreationsUploads = new PingCreationsUploadsRequest (creationsUploadsResponse .ping_url , accessToken );
114
+ pingCreationsUploads .setData ("" );
86
115
pingCreationsUploads .execute ().getResponse ();
87
116
System .out .println ("-Finish-" );
88
117
}
0 commit comments