1
1
package com .creatubbles .api ;
2
2
3
- import java .io .File ;
4
- import java .io .IOException ;
5
- import java .lang .reflect .Type ;
6
- import java .nio .file .Files ;
7
-
8
- import com .google .gson .*;
9
- import org .glassfish .jersey .client .ClientProperties ;
10
- import org .glassfish .jersey .client .JerseyClient ;
11
- import org .glassfish .jersey .client .JerseyClientBuilder ;
12
-
13
3
import com .creatubbles .api .core .Gallery ;
14
- import com .creatubbles .api .request .amazon .UploadS3ImageRequest ;
4
+ import com .creatubbles .api .core .LandingUrl ;
5
+ import com .creatubbles .api .request .amazon .UploadS3FileRequest ;
15
6
import com .creatubbles .api .request .creation .CreateCreationRequest ;
16
7
import com .creatubbles .api .request .creation .CreationsUploadsRequest ;
17
8
import com .creatubbles .api .request .creation .PingCreationsUploadsRequest ;
9
+ import com .creatubbles .api .request .landingurls .GetLandingUrlsRequest ;
10
+ import com .creatubbles .api .request .landingurls .GetSpecificLandingUrlRequest ;
18
11
import com .creatubbles .api .response .auth .SignUpResponse ;
19
12
import com .creatubbles .api .response .creation .CreateCreationResponse ;
20
13
import com .creatubbles .api .response .creation .CreationsUploadsResponse ;
21
14
import com .creatubbles .api .response .creation .GetCreationsResponse ;
22
15
import com .creatubbles .api .response .creator .CreateCreatorResponse ;
23
16
import com .creatubbles .api .response .creator .GetCreatorsResponse ;
24
17
import com .creatubbles .api .response .gallery .CreateUserGalleryResponse ;
18
+ import com .creatubbles .api .response .landingurls .GetLandingUrlsResponse ;
19
+ import com .creatubbles .api .response .landingurls .GetSpecificLandingUrlResponse ;
25
20
import com .creatubbles .api .response .user .UserProfileResponse ;
26
21
import com .creatubbles .api .util .EndPoints ;
22
+ import com .creatubbles .api .util .HttpUtil ;
23
+ import com .google .gson .*;
24
+ import org .glassfish .jersey .client .ClientProperties ;
25
+ import org .glassfish .jersey .client .JerseyClient ;
26
+ import org .glassfish .jersey .client .JerseyClientBuilder ;
27
+
28
+ import java .io .File ;
29
+ import java .io .IOException ;
30
+ import java .lang .reflect .Type ;
31
+ import java .nio .file .Files ;
27
32
28
33
29
34
@ SuppressWarnings ("deprecation" )
@@ -39,6 +44,8 @@ public class CreatubblesAPI {
39
44
.registerTypeAdapter (GetCreationsResponse .class , new GetCreationsResponse ())
40
45
.registerTypeAdapter (CreateCreationResponse .class , new CreateCreationResponse ())
41
46
.registerTypeAdapter (CreationsUploadsResponse .class , new CreationsUploadsResponse ())
47
+ .registerTypeAdapter (GetLandingUrlsResponse .class , new GetLandingUrlsResponse ())
48
+ .registerTypeAdapter (GetSpecificLandingUrlResponse .class , new GetSpecificLandingUrlResponse ())
42
49
.registerTypeAdapter (String .class , new StringAdapter ())
43
50
.create ();
44
51
@@ -49,6 +56,9 @@ public class CreatubblesAPI {
49
56
.property (ClientProperties .SUPPRESS_HTTP_COMPLIANCE_VALIDATION , Boolean .TRUE );
50
57
51
58
public static String buildURL (final String endPoint ) {
59
+ if (endPoint .startsWith ("https://" )) {
60
+ return endPoint ;
61
+ }
52
62
String base = staging ? EndPoints .URL_BASE_STAGING : EndPoints .URL_BASE ;
53
63
return base .concat (endPoint );
54
64
}
@@ -61,25 +71,39 @@ public static void setStagingMode(boolean staging) {
61
71
62
72
public static void main (String [] args ) throws IOException {
63
73
// Additional examples can be found in the JUnit test files
64
-
74
+
65
75
CreatubblesAPI .setStagingMode (true );
66
76
String accessToken = "" ; // TODO commit tests AuthTests.getAuthToken();
67
77
68
78
CreateCreationRequest createCreation = new CreateCreationRequest (accessToken );
69
79
CreateCreationResponse createCreationResponse = createCreation .execute ().getResponse ();
70
80
System .out .println (createCreationResponse .creation .id );
71
81
72
- CreationsUploadsRequest creationsUploads = new CreationsUploadsRequest (createCreationResponse .creation .id , accessToken );
82
+ File file = new File ("C:/dev/1.png" );
83
+ String extension = HttpUtil .getExtension (file .getPath ());
84
+
85
+ CreationsUploadsRequest creationsUploads = new CreationsUploadsRequest (createCreationResponse .creation .id , extension , accessToken );
73
86
CreationsUploadsResponse creationsUploadsResponse = creationsUploads .execute ().getResponse ();
74
87
System .out .println (creationsUploadsResponse .url );
75
88
System .out .println (creationsUploadsResponse .id );
76
89
77
- File file = new File ("C:/dev/1.png" );
90
+ GetLandingUrlsRequest getLandingUrls = new GetLandingUrlsRequest (accessToken );
91
+ for (LandingUrl landingUrl : getLandingUrls .execute ().getResponse ().urls ) {
92
+ System .out .println (landingUrl .type + ":" + landingUrl .url );
93
+ }
94
+
95
+ GetSpecificLandingUrlRequest getSpecificLandingUrl = new GetSpecificLandingUrlRequest (accessToken , LandingUrl .LandingUrlType .CTB_USER_PROFILE );
96
+ GetSpecificLandingUrlResponse getSpecificLandingUrlResponse = getSpecificLandingUrl .execute ().getResponse ();
97
+ LandingUrl url = getSpecificLandingUrlResponse .url ;
98
+ System .out .println ("specific url - " + url .type + ":" + url .url );
99
+
78
100
byte [] data = Files .readAllBytes (file .toPath ());
79
- UploadS3ImageRequest uploadS3Image = new UploadS3ImageRequest (data , creationsUploadsResponse .url );
101
+
102
+ UploadS3FileRequest uploadS3Image = new UploadS3FileRequest (data , creationsUploadsResponse .url , creationsUploadsResponse .content_type );
80
103
uploadS3Image .execute ().getResponse ();
81
104
82
- PingCreationsUploadsRequest pingCreationsUploads = new PingCreationsUploadsRequest (creationsUploadsResponse .id , accessToken );
105
+ PingCreationsUploadsRequest pingCreationsUploads = new PingCreationsUploadsRequest (creationsUploadsResponse .ping_url , accessToken );
106
+ pingCreationsUploads .setData ("" );
83
107
pingCreationsUploads .execute ().getResponse ();
84
108
System .out .println ("-Finish-" );
85
109
}
0 commit comments