Skip to content

Commit 5154bba

Browse files
🪴 clean structure
1 parent d40c237 commit 5154bba

File tree

9 files changed

+337
-307
lines changed

9 files changed

+337
-307
lines changed

cms.iml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
</content>
1212
<orderEntry type="inheritedJdk" />
1313
<orderEntry type="sourceFolder" forTests="false" />
14-
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.9" level="project" />
15-
<orderEntry type="library" name="Maven: io.reactivex.rxjava3:rxjava:3.1.3" level="project" />
14+
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.9.0" level="project" />
15+
<orderEntry type="library" name="Maven: io.reactivex.rxjava3:rxjava:3.1.4" level="project" />
1616
<orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.3" level="project" />
1717
<orderEntry type="library" name="Maven: com.squareup.retrofit2:retrofit:2.9.0" level="project" />
1818
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.14.9" level="project" />

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
8181
<maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
8282
<dotenv-source.version>5.2.2</dotenv-source.version>
83-
<rxjava-source.version>3.1.3</rxjava-source.version>
83+
<rxjava-source.version>3.1.4</rxjava-source.version>
8484
<retrofit-source.version>2.9.0</retrofit-source.version>
8585
<converter-gson-version>2.9.0</converter-gson-version>
8686
<loggin.version>4.9.3</loggin.version>
@@ -89,7 +89,7 @@
8989
<junit-jupiter.version>5.8.2</junit-jupiter.version>
9090
<junit-jupiter-engine.version>5.8.0-M1</junit-jupiter-engine.version>
9191
<junit-vintage-engine.version>5.8.2</junit-vintage-engine.version>
92-
<gson.version>2.8.9</gson.version>
92+
<gson.version>2.9.0</gson.version>
9393
<maven-site-plugin.version>3.3</maven-site-plugin.version>
9494
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
9595
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>

src/main/java/com/contentstack/cms/Contentstack.java

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public class Contentstack {
4242
protected User user;
4343

4444
/**
45-
* All accounts registered with Contentstack are known as Users. A stack can
46-
* have many users with varying
45+
* All accounts registered with Contentstack are known as Users. A stack can have many users with varying
4746
* permissions and roles
4847
* <p>
4948
* To perform User operations first get User instance like below.
@@ -75,14 +74,12 @@ public User user() {
7574

7675
/**
7776
* <b>[Note]:</b> Before executing any calls, retrieve the authtoken by
78-
* authenticating yourself via the Log in call of User Session. The authtoken is
79-
* returned to the 'Response' body of
77+
* authenticating yourself via the Log in call of User Session. The authtoken is returned to the 'Response' body of
8078
* the Log in call and is mandatory in all the calls.
8179
* <p>
8280
* <b>Example:</b>
8381
* <p>
84-
* All accounts registered with Contentstack are known as Users. A stack can
85-
* have many users with varying
82+
* All accounts registered with Contentstack are known as Users. A stack can have many users with varying
8683
* permissions and roles
8784
* <p>
8885
* To perform User operations first get User instance like below.
@@ -106,12 +103,12 @@ public User user() {
106103
* <p>
107104
*
108105
* @param emailId
109-
* the email id
106+
* the email id
110107
* @param password
111-
* the password
108+
* the password
112109
* @return response the Response type of @{@link LoginDetails}
113110
* @throws IOException
114-
* the io exception
111+
* the io exception
115112
*/
116113
public Response<LoginDetails> login(String emailId, String password) throws IOException {
117114
if (this.authtoken != null)
@@ -124,14 +121,12 @@ public Response<LoginDetails> login(String emailId, String password) throws IOEx
124121

125122
/**
126123
* <b>[Note]:</b> Before executing any calls, retrieve the authtoken by
127-
* authenticating yourself via the Log in call of User Session. The authtoken is
128-
* returned to the 'Response' body of
124+
* authenticating yourself via the Log in call of User Session. The authtoken is returned to the 'Response' body of
129125
* the Log in call and is mandatory in all the calls.
130126
* <p>
131127
* <b>Example:</b>
132128
* <p>
133-
* All accounts registered with Contentstack are known as Users. A stack can
134-
* have many users with varying
129+
* All accounts registered with Contentstack are known as Users. A stack can have many users with varying
135130
* permissions and roles
136131
* <p>
137132
* To perform User operations first get User instance like below.
@@ -155,15 +150,14 @@ public Response<LoginDetails> login(String emailId, String password) throws IOEx
155150
* <p>
156151
*
157152
* @param emailId
158-
* the email id
153+
* the email id
159154
* @param password
160-
* the password
155+
* the password
161156
* @param tfaToken
162-
* the tfa token
163-
* @return response the Response type of @{@link LoginDetails} throws
164-
* {@link IOException}
157+
* the tfa token
158+
* @return response the Response type of @{@link LoginDetails} throws {@link IOException}
165159
* @throws IOException
166-
* the io exception
160+
* the io exception
167161
*/
168162
public Response<LoginDetails> login(String emailId, String password, String tfaToken) throws IOException {
169163
if (this.authtoken != null)
@@ -189,8 +183,7 @@ private void setupLoginCredentials(Response<LoginDetails> loginResponse) throws
189183
}
190184

191185
/**
192-
* The Log out of your account call is used to sign out the user of Contentstack
193-
* account
186+
* The Log out of your account call is used to sign out the user of Contentstack account
194187
*
195188
* <b> Example </b>
196189
*
@@ -202,16 +195,15 @@ private void setupLoginCredentials(Response<LoginDetails> loginResponse) throws
202195
*
203196
* @return the response
204197
* @throws IOException
205-
* the io exception
198+
* the io exception
206199
*/
207200
Response<ResponseBody> logout() throws IOException {
208201
user = new User(this.instance);
209202
return user.logoutWithAuthtoken(this.authtoken).execute();
210203
}
211204

212205
/**
213-
* The Log out of your account using authtoken is used to sign out the user of
214-
* Contentstack account
206+
* The Log out of your account using authtoken is used to sign out the user of Contentstack account
215207
*
216208
* <b> Example </b>
217209
*
@@ -222,10 +214,10 @@ Response<ResponseBody> logout() throws IOException {
222214
* <p>
223215
*
224216
* @param authtoken
225-
* the authtoken
217+
* the authtoken
226218
* @return the response
227219
* @throws IOException
228-
* the io exception
220+
* the io exception
229221
*/
230222
Response<ResponseBody> logoutWithAuthtoken(String authtoken) throws IOException {
231223
user = new User(this.instance);
@@ -237,10 +229,8 @@ Response<ResponseBody> logoutWithAuthtoken(String authtoken) throws IOException
237229
}
238230

239231
/**
240-
* Organization is the top-level entity in the hierarchy of Contentstack,
241-
* consisting of stacks and stack resources,
242-
* and users. Organization allows easy management of projects as well as users
243-
* within the Organization.
232+
* Organization is the top-level entity in the hierarchy of Contentstack, consisting of stacks and stack resources,
233+
* and users. Organization allows easy management of projects as well as users within the Organization.
244234
*
245235
* <b> Example </b>
246236
*
@@ -286,8 +276,10 @@ public Stack stack() {
286276
* <b> Example </b>
287277
*
288278
* <pre>
279+
* ```
289280
* Contentstack client = new Contentstack.Builder().build();
290281
* Stack org = client.stack();
282+
* ```
291283
* </pre>
292284
*
293285
* @param header
@@ -345,7 +337,7 @@ public Stack stack(@NotNull String apiKey, @NotNull String managementToken) {
345337
* @param apiKey
346338
* the apiKey for the stack
347339
* @param branch
348-
* the branch that include branching in the response
340+
* the branch that include branching in the response
349341
* @return the stack instance
350342
*/
351343
public Stack stack(@NotNull String apiKey, @NotNull String managementToken, @NotNull String branch) {
@@ -399,20 +391,17 @@ public static class Builder {
399391
* Instantiates a new Builder.
400392
*/
401393
public Builder() {
402-
// Builder constructor initialises the Builder class.
403394
}
404395

405396
/**
406-
* Sets proxy. (Setting proxy to the OkHttpClient) Proxy proxy = new
407-
* Proxy(Proxy.Type.HTTP, new
397+
* Sets proxy. (Setting proxy to the OkHttpClient) Proxy proxy = new Proxy(Proxy.Type.HTTP, new
408398
* InetSocketAddress(proxyHost, proxyPort));
409399
* <p>
410-
* Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname",
411-
* 433)); Contentstack contentstack =
400+
* Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 433)); Contentstack contentstack =
412401
* new Contentstack.Builder().setProxy(proxy).build();
413402
*
414403
* @param proxy
415-
* the proxy
404+
* the proxy
416405
* @return the Builder instance
417406
*/
418407
public Builder setProxy(@NotNull Proxy proxy) {
@@ -424,7 +413,7 @@ public Builder setProxy(@NotNull Proxy proxy) {
424413
* Sets retry on failure.
425414
*
426415
* @param retry
427-
* if retry is true
416+
* if retry is true
428417
* @return the retry on failure
429418
*/
430419
public Builder setRetry(@NotNull Boolean retry) {
@@ -436,7 +425,7 @@ public Builder setRetry(@NotNull Boolean retry) {
436425
* Set host for client instance
437426
*
438427
* @param hostname
439-
* host for the Contentstack Client
428+
* host for the Contentstack Client
440429
* @return Client host
441430
*/
442431
public Builder setHost(@NotNull String hostname) {
@@ -448,7 +437,7 @@ public Builder setHost(@NotNull String hostname) {
448437
* Set port for client instance
449438
*
450439
* @param port
451-
* - port for the Contentstack Client
440+
* - port for the Contentstack Client
452441
* @return Client port
453442
*/
454443
public Builder setPort(@NotNull String port) {
@@ -460,7 +449,7 @@ public Builder setPort(@NotNull String port) {
460449
* Set version for client instance
461450
*
462451
* @param version
463-
* for the Contentstack Client
452+
* for the Contentstack Client
464453
* @return Client version
465454
*/
466455
public Builder setVersion(@NotNull String version) {
@@ -472,7 +461,7 @@ public Builder setVersion(@NotNull String version) {
472461
* Set timeout for client instance
473462
*
474463
* @param timeout
475-
* for the Contentstack Client
464+
* for the Contentstack Client
476465
* @return Client timeout
477466
*/
478467
public Builder setTimeout(int timeout) {
@@ -484,7 +473,7 @@ public Builder setTimeout(int timeout) {
484473
* Sets authtoken for the client
485474
*
486475
* @param authtoken
487-
* for the client
476+
* for the client
488477
* @return Contentstack authtoken
489478
*/
490479
public Builder setAuthtoken(String authtoken) {
@@ -514,17 +503,18 @@ private void validateClient(Contentstack contentstack) {
514503

515504
private OkHttpClient httpClient(Contentstack contentstack, Boolean retryOnFailure) {
516505
this.authInterceptor = contentstack.interceptor = new AuthInterceptor();
506+
HttpLoggingInterceptor level = new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY);
517507
return new OkHttpClient.Builder()
518508
.addInterceptor(this.authInterceptor)
519-
.addInterceptor(logger())
509+
.addInterceptor(level)
520510
.proxy(this.proxy)
521511
.retryOnConnectionFailure(retryOnFailure)
522512
.build();
523513
}
524514

525-
private HttpLoggingInterceptor logger() {
526-
return new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.NONE);
527-
}
515+
// private HttpLoggingInterceptor setLoggerLevel(HttpLoggingInterceptor.Level level) {
516+
// return new HttpLoggingInterceptor().setLevel(level);
517+
// }
528518

529519
}
530520
}

src/main/java/com/contentstack/cms/core/CSResponse.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.contentstack.cms.core;
22

33
import com.google.gson.Gson;
4+
import okhttp3.Call;
5+
import okhttp3.Request;
46
import okhttp3.ResponseBody;
57
import retrofit2.Response;
68

@@ -50,4 +52,8 @@ public <T> T toModel(Class<T> tClass, Response<ResponseBody> response) throws IO
5052
return new Gson().fromJson(body, tClass);
5153
}
5254

55+
public Request requestBody(Call callInstance){
56+
return callInstance.request();
57+
}
58+
5359
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.contentstack.cms.core;
2+
3+
import retrofit2.Call;
4+
import okhttp3.ResponseBody;
5+
import retrofit2.Response;
6+
7+
import java.io.IOException;
8+
9+
10+
/**
11+
* The ContentstackResponse is the response when we execute the API Response, ContentstackResponse contains different
12+
* response type
13+
* <p>
14+
* Since: 1.0.0
15+
*/
16+
public class ContentstackResponse<T> {
17+
18+
Call<ResponseBody> response;
19+
20+
21+
public Response<ResponseBody> fetch(Call<ResponseBody> response) {
22+
try {
23+
return response.execute();
24+
} catch (IOException e) {
25+
throw new RuntimeException(e);
26+
}
27+
}
28+
29+
/**
30+
* @return Response
31+
*/
32+
Response<T> getResponse() {
33+
return null;
34+
}
35+
36+
/**
37+
* @return ResponseBody
38+
*/
39+
ResponseBody getResponseBody() {
40+
return null;
41+
}
42+
43+
// Synchronously send the request and return its response
44+
45+
}

src/main/java/com/contentstack/cms/core/RetryCallback.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public abstract class RetryCallback<T> implements Callback<T> {
1919
private int retryCount = 0;
2020

2121
/**
22+
*
2223
* Instantiates a new Callback with retry.
2324
*
2425
* @param call the call

0 commit comments

Comments
 (0)