Skip to content

Commit b05d752

Browse files
Merge pull request #44 from contentstack/next
CS-42937/feat-EAH-support
2 parents 25fa3e4 + d433787 commit b05d752

File tree

10 files changed

+141
-43
lines changed

10 files changed

+141
-43
lines changed

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

+29-19
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class Contentstack {
5151
protected final Boolean retryOnFailure;
5252
protected final Proxy proxy;
5353
protected AuthInterceptor interceptor;
54+
protected String[] earlyAccess;
5455
protected User user;
5556

5657
/**
@@ -80,8 +81,8 @@ public class Contentstack {
8081
* @return User
8182
* @author ***REMOVED***
8283
* @see <a href=
83-
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
84-
* </a>
84+
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
85+
* </a>
8586
* @since 2022-05-19
8687
*/
8788
public User user() {
@@ -130,8 +131,8 @@ public User user() {
130131
* @throws IOException the IOException
131132
* @author ***REMOVED***
132133
* @see <a href=
133-
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
134-
* </a>
134+
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
135+
* </a>
135136
*/
136137
public Response<LoginDetails> login(String emailId, String password) throws IOException {
137138
if (this.authtoken != null)
@@ -183,10 +184,10 @@ public Response<LoginDetails> login(String emailId, String password) throws IOEx
183184
* @throws IOException the IOException
184185
* @author ***REMOVED***
185186
* @see <a
186-
* href=
187-
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#log-in-to-your-account">Login
188-
* your account
189-
* </a>
187+
* href=
188+
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#log-in-to-your-account">Login
189+
* your account
190+
* </a>
190191
*/
191192
public Response<LoginDetails> login(String emailId, String password, String tfaToken) throws IOException {
192193
if (this.authtoken != null)
@@ -287,11 +288,12 @@ public Organization organization() {
287288
*
288289
* @param organizationUid The UID of the organization that you want to retrieve
289290
* @return the organization
290-
* <br>
291-
* <b>Example</b>
291+
* <br>
292+
* <b>Example</b>
292293
*
293-
* <pre>
294+
* <pre>
294295
* Contentstack contentstack = new Contentstack.Builder().build();
296+
* <br>
295297
* Organization org = contentstack.organization();
296298
* </pre>
297299
*/
@@ -447,6 +449,7 @@ public Contentstack(Builder builder) {
447449
this.retryOnFailure = builder.retry;
448450
this.proxy = builder.proxy;
449451
this.interceptor = builder.authInterceptor;
452+
this.earlyAccess = builder.earlyAccess;
450453
}
451454

452455
/**
@@ -461,6 +464,7 @@ public static class Builder {
461464
private AuthInterceptor authInterceptor;
462465

463466
private String authtoken; // authtoken for client
467+
private String[] earlyAccess;
464468
private Retrofit instance; // client instance
465469
private String hostname = Util.HOST; // Default Host for Contentstack API (default: api.contentstack.io)
466470
private String port = Util.PORT; // Default PORT for Contentstack API
@@ -488,14 +492,14 @@ public Builder() {
488492
* <br>
489493
* <p>
490494
* {@code
491-
*
492-
<p>
495+
*
496+
* <p>
493497
* Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 433));
494498
* Contentstack contentstack = new Contentstack.Builder().setProxy(proxy).build();
495-
*
496-
<p>
499+
*
500+
* <p>
497501
* }
498-
*
502+
*
499503
* @param proxy the proxy
500504
* @return the Builder instance
501505
*/
@@ -578,9 +582,9 @@ public Builder setTimeout(int timeout) {
578582
* unit of granularity and provides utility methods to
579583
* convert across units
580584
* @return instance of Builder
581-
* <p>
582-
* Example:
583-
* {@code
585+
* <p>
586+
* Example:
587+
* {@code
584588
* Contentstack cs = new Contentstack.Builder()
585589
* .setAuthtoken(AUTHTOKEN)
586590
* .setConnectionPool(5, 400, TimeUnit.MILLISECONDS)
@@ -604,6 +608,12 @@ public Builder setAuthtoken(String authtoken) {
604608
return this;
605609
}
606610

611+
612+
public Builder earlyAccess(String[] earlyAccess) {
613+
this.earlyAccess = earlyAccess;
614+
return this;
615+
}
616+
607617
/**
608618
* Build contentstack.
609619
*

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

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
public class AuthInterceptor implements Interceptor {
2626

2727
protected String authtoken;
28+
protected String[] earlyAccess;
2829

2930
// The `public AuthInterceptor() {}` is a default constructor for the
3031
// `AuthInterceptor` class. It is
@@ -51,6 +52,10 @@ public void setAuthtoken(String authtoken) {
5152
this.authtoken = authtoken;
5253
}
5354

55+
public void setEarlyAccess(String[] earlyAccess) {
56+
this.earlyAccess = earlyAccess;
57+
}
58+
5459
/**
5560
* This function intercepts a request and adds headers to it, including a user
5661
* agent, content type, and
@@ -73,6 +78,10 @@ public Response intercept(Chain chain) throws IOException {
7378
if (this.authtoken != null) {
7479
request.addHeader(Util.AUTHTOKEN, this.authtoken);
7580
}
81+
if (this.earlyAccess!=null && this.earlyAccess.length > 0) {
82+
String commaSeparated = String.join(", ", earlyAccess);
83+
request.addHeader(Util.EARLY_ACCESS_HEADER, commaSeparated);
84+
}
7685
return chain.proceed(request.build());
7786
}
7887

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

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class Util {
3838
public static final String API_KEY = "api_key";
3939
public static final String AUTHORIZATION = "authorization";
4040
public static final String AUTHTOKEN = "authtoken";
41+
public static final String EARLY_ACCESS_HEADER = "x-header-ea";
4142
public static final String BRANCH = "branch";
4243
public static final String X_USER_AGENT = "X-User-Agent";
4344
public static final String USER_AGENT = "User-Agent";

src/main/java/com/contentstack/cms/stack/AliasService.java

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
import java.util.Map;
99

10+
11+
/**
12+
* The interface Alias service.
13+
*/
1014
public interface AliasService {
1115

1216
@GET("stacks/branch_aliases")

src/main/java/com/contentstack/cms/stack/Entry.java

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public Entry addHeaders(@NotNull HashMap<String, String> headers) {
104104
* Set header for the request
105105
*
106106
* @param key Removes query param using key of request
107+
* @return instance of {@link Entry}
107108
*/
108109
public Entry removeParam(@NotNull String key) {
109110
this.params.remove(key);

src/main/java/com/contentstack/cms/stack/Stack.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ public Taxonomy taxonomy() {
845845
*
846846
* @param taxonomyUid the taxonomy uid
847847
* @return instance of Taxonomy
848-
* <p></p>
848+
* <br>
849849
* <pre>
850850
* {@code
851851
* Stack stack = new Contentstack.Builder().setAuthtoken("authtoken").build().stack();

src/main/java/com/contentstack/cms/stack/Taxonomy.java

+12-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111

1212

1313
/**
14-
* The type Taxonomy.
14+
* Taxonomy is a system that classifies and organizes content in your collection or system.
15+
* It simplifies finding and retrieving information by categorizing items based on specific
16+
* criteria like their purpose, audience, or other relevant factors.
17+
* <p>
18+
* This hierarchical organization streamlines navigation and search processes.
1519
*/
1620
public class Taxonomy implements BaseImplementation<Taxonomy> {
1721

@@ -147,7 +151,7 @@ public Taxonomy addParams(@NotNull HashMap<String, Object> params) {
147151
* </li>
148152
* </ul>
149153
*
150-
* @return the call <p></p> <b>Example</b> <pre> {@code
154+
* @return the call <b>Example</b> <pre> {@code
151155
* Response<ResponseBody> response = taxonomy.find().execute();
152156
* } </pre>
153157
*/
@@ -172,7 +176,7 @@ public Call<ResponseBody> find() {
172176
* </ul>
173177
*
174178
* @param taxonomyId the taxonomy id
175-
* @return the call <p></p> <b>Example</b> <pre> {@code
179+
* @return the call <b>Example</b> <pre> {@code
176180
* Response<ResponseBody> response = taxonomy.fetch("taxonomyId").execute();
177181
* } </pre>
178182
*/
@@ -184,7 +188,7 @@ public Call<ResponseBody> fetch(@NotNull String taxonomyId) {
184188
* Create Taxonomy call.
185189
*
186190
* @param body the body
187-
* @return the call <p></p> <b>Example</b> <pre> {@code
191+
* @return the call <b>Example</b> <pre> {@code
188192
* JSONObject body = new JSONObject
189193
* Response<ResponseBody> response = taxonomy.create(body).execute();
190194
* } </pre>
@@ -198,7 +202,7 @@ public Call<ResponseBody> create(@NotNull JSONObject body) {
198202
*
199203
* @param taxonomyId - The taxonomy for which we need to update the details
200204
* @param body the body
201-
* @return the call <p></p> <b>Example</b> <pre> {@code
205+
* @return the call <b>Example</b> <pre> {@code
202206
* JSONObject body = new JSONObject();
203207
* JSONObject bodyContent = new JSONObject();
204208
* bodyContent.put("name", "Taxonomy 1");
@@ -215,14 +219,15 @@ public Call<ResponseBody> update(@NotNull String taxonomyId, @NotNull JSONObject
215219
* Delete Taxonomy call.
216220
*
217221
* @param taxonomyId - The taxonomy for which we need to update the details
218-
* @return the call <p></p> <b>Example</b> <pre> {@code
222+
* @return the call <b>Example</b> <pre> {@code
219223
* Response<ResponseBody> response = taxonomy.delete("taxonomyId").execute();
220224
* } </pre>
221225
*/
222226
public Call<ResponseBody> delete(@NotNull String taxonomyId) {
223227
return this.taxonomyService.delete(this.headers, taxonomyId);
224228
}
225229

230+
226231
/**
227232
* Clear params for internal uses only for testing
228233
*/
@@ -233,12 +238,11 @@ protected void clearParams() {
233238

234239
/**
235240
* Get terms information
236-
* <p>
237241
* <p>Examples</p>
238242
* <pre>
239243
* {@code
240244
* Term terms = stack("authtoken").taxonomy("taxonomyId").term();
241-
* }*
245+
* }
242246
* </pre>
243247
*
244248
* @return instance of {@link Terms}
@@ -247,5 +251,4 @@ public Terms terms() {
247251
return new Terms(this.taxonomyService, this.headers, this.taxonomyId);
248252
}
249253

250-
251254
}

src/main/java/com/contentstack/cms/stack/TaxonomyService.java

+18-6
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
1111
public interface TaxonomyService {
1212

1313
@GET("taxonomies")
14-
Call<ResponseBody> find(@HeaderMap Map<String, Object> headers, @QueryMap Map<String, Object> params);
14+
Call<ResponseBody> find(
15+
@HeaderMap Map<String, Object> headers,
16+
@QueryMap Map<String, Object> params);
1517

1618
@GET("taxonomies/{taxonomy_uid}")
17-
Call<ResponseBody> fetch(@HeaderMap Map<String, Object> headers, @Path("taxonomy_uid") String uid, @QueryMap Map<String, Object> query);
19+
Call<ResponseBody> fetch(
20+
@HeaderMap Map<String, Object> headers,
21+
@Path("taxonomy_uid") String uid,
22+
@QueryMap Map<String, Object> query);
1823

1924
@POST("taxonomies")
2025
Call<ResponseBody> create(
@@ -32,7 +37,8 @@ Call<ResponseBody> delete(
3237
@HeaderMap Map<String, Object> headers,
3338
@Path("taxonomy_uid") String uid);
3439

35-
//--Terms--
40+
41+
// --Terms--
3642
@POST("taxonomies/{taxonomy_uid}/terms")
3743
Call<ResponseBody> createTerm(
3844
@HeaderMap HashMap<String, Object> headers,
@@ -73,10 +79,16 @@ Call<ResponseBody> updateTerm(
7379
@Path("term_id") String termId,
7480
@Body JSONObject body);
7581

82+
@PUT("taxonomies/{taxonomy_uid}/terms/{term_id}/move")
83+
Call<ResponseBody> reorder(
84+
@HeaderMap HashMap<String, Object> headers,
85+
@Path("taxonomy_uid") String taxonomyId,
86+
@Path("term_id") String termId,
87+
@QueryMap Map<String, Object> queryParams,
88+
@Body JSONObject body);
7689

77-
@GET("taxonomies/all/terms")
90+
@GET("taxonomies/$all/terms")
7891
Call<ResponseBody> searchTerm(
7992
@HeaderMap HashMap<String, Object> headers,
80-
@Query("term") String termString
81-
);
93+
@Query("typeahead") String termString);
8294
}

0 commit comments

Comments
 (0)