Skip to content

Commit

Permalink
Merge pull request #44 from contentstack/next
Browse files Browse the repository at this point in the history
CS-42937/feat-EAH-support
  • Loading branch information
ishaileshmishra authored Dec 18, 2023
2 parents d39ae72 + c5e5d90 commit 41bba57
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 43 deletions.
48 changes: 29 additions & 19 deletions src/main/java/com/contentstack/cms/Contentstack.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class Contentstack {
protected final Boolean retryOnFailure;
protected final Proxy proxy;
protected AuthInterceptor interceptor;
protected String[] earlyAccess;
protected User user;

/**
Expand Down Expand Up @@ -80,8 +81,8 @@ public class Contentstack {
* @return User
* @author ishaileshmishra
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
* @since 2022-05-19
*/
public User user() {
Expand Down Expand Up @@ -130,8 +131,8 @@ public User user() {
* @throws IOException the IOException
* @author ishaileshmishra
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
*/
public Response<LoginDetails> login(String emailId, String password) throws IOException {
if (this.authtoken != null)
Expand Down Expand Up @@ -183,10 +184,10 @@ public Response<LoginDetails> login(String emailId, String password) throws IOEx
* @throws IOException the IOException
* @author ishaileshmishra
* @see <a
* href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#log-in-to-your-account">Login
* your account
* </a>
* href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#log-in-to-your-account">Login
* your account
* </a>
*/
public Response<LoginDetails> login(String emailId, String password, String tfaToken) throws IOException {
if (this.authtoken != null)
Expand Down Expand Up @@ -287,11 +288,12 @@ public Organization organization() {
*
* @param organizationUid The UID of the organization that you want to retrieve
* @return the organization
* <br>
* <b>Example</b>
* <br>
* <b>Example</b>
*
* <pre>
* <pre>
* Contentstack contentstack = new Contentstack.Builder().build();
* <br>
* Organization org = contentstack.organization();
* </pre>
*/
Expand Down Expand Up @@ -447,6 +449,7 @@ public Contentstack(Builder builder) {
this.retryOnFailure = builder.retry;
this.proxy = builder.proxy;
this.interceptor = builder.authInterceptor;
this.earlyAccess = builder.earlyAccess;
}

/**
Expand All @@ -461,6 +464,7 @@ public static class Builder {
private AuthInterceptor authInterceptor;

private String authtoken; // authtoken for client
private String[] earlyAccess;
private Retrofit instance; // client instance
private String hostname = Util.HOST; // Default Host for Contentstack API (default: api.contentstack.io)
private String port = Util.PORT; // Default PORT for Contentstack API
Expand Down Expand Up @@ -488,14 +492,14 @@ public Builder() {
* <br>
* <p>
* {@code
*
<p>
*
* <p>
* Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 433));
* Contentstack contentstack = new Contentstack.Builder().setProxy(proxy).build();
*
<p>
*
* <p>
* }
*
*
* @param proxy the proxy
* @return the Builder instance
*/
Expand Down Expand Up @@ -578,9 +582,9 @@ public Builder setTimeout(int timeout) {
* unit of granularity and provides utility methods to
* convert across units
* @return instance of Builder
* <p>
* Example:
* {@code
* <p>
* Example:
* {@code
* Contentstack cs = new Contentstack.Builder()
* .setAuthtoken(AUTHTOKEN)
* .setConnectionPool(5, 400, TimeUnit.MILLISECONDS)
Expand All @@ -604,6 +608,12 @@ public Builder setAuthtoken(String authtoken) {
return this;
}


public Builder earlyAccess(String[] earlyAccess) {
this.earlyAccess = earlyAccess;
return this;
}

/**
* Build contentstack.
*
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/contentstack/cms/core/AuthInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class AuthInterceptor implements Interceptor {

protected String authtoken;
protected String[] earlyAccess;

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

public void setEarlyAccess(String[] earlyAccess) {
this.earlyAccess = earlyAccess;
}

/**
* This function intercepts a request and adds headers to it, including a user
* agent, content type, and
Expand All @@ -73,6 +78,10 @@ public Response intercept(Chain chain) throws IOException {
if (this.authtoken != null) {
request.addHeader(Util.AUTHTOKEN, this.authtoken);
}
if (this.earlyAccess!=null && this.earlyAccess.length > 0) {
String commaSeparated = String.join(", ", earlyAccess);
request.addHeader(Util.EARLY_ACCESS_HEADER, commaSeparated);
}
return chain.proceed(request.build());
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/contentstack/cms/core/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Util {
public static final String API_KEY = "api_key";
public static final String AUTHORIZATION = "authorization";
public static final String AUTHTOKEN = "authtoken";
public static final String EARLY_ACCESS_HEADER = "x-header-ea";
public static final String BRANCH = "branch";
public static final String X_USER_AGENT = "X-User-Agent";
public static final String USER_AGENT = "User-Agent";
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/contentstack/cms/stack/AliasService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

import java.util.Map;


/**
* The interface Alias service.
*/
public interface AliasService {

@GET("stacks/branch_aliases")
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/contentstack/cms/stack/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public Entry addHeaders(@NotNull HashMap<String, String> headers) {
* Set header for the request
*
* @param key Removes query param using key of request
* @return instance of {@link Entry}
*/
public Entry removeParam(@NotNull String key) {
this.params.remove(key);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/contentstack/cms/stack/Stack.java
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ public Taxonomy taxonomy() {
*
* @param taxonomyUid the taxonomy uid
* @return instance of Taxonomy
* <p></p>
* <br>
* <pre>
* {@code
* Stack stack = new Contentstack.Builder().setAuthtoken("authtoken").build().stack();
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/com/contentstack/cms/stack/Taxonomy.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@


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

Expand Down Expand Up @@ -147,7 +151,7 @@ public Taxonomy addParams(@NotNull HashMap<String, Object> params) {
* </li>
* </ul>
*
* @return the call <p></p> <b>Example</b> <pre> {@code
* @return the call <b>Example</b> <pre> {@code
* Response<ResponseBody> response = taxonomy.find().execute();
* } </pre>
*/
Expand All @@ -172,7 +176,7 @@ public Call<ResponseBody> find() {
* </ul>
*
* @param taxonomyId the taxonomy id
* @return the call <p></p> <b>Example</b> <pre> {@code
* @return the call <b>Example</b> <pre> {@code
* Response<ResponseBody> response = taxonomy.fetch("taxonomyId").execute();
* } </pre>
*/
Expand All @@ -184,7 +188,7 @@ public Call<ResponseBody> fetch(@NotNull String taxonomyId) {
* Create Taxonomy call.
*
* @param body the body
* @return the call <p></p> <b>Example</b> <pre> {@code
* @return the call <b>Example</b> <pre> {@code
* JSONObject body = new JSONObject
* Response<ResponseBody> response = taxonomy.create(body).execute();
* } </pre>
Expand All @@ -198,7 +202,7 @@ public Call<ResponseBody> create(@NotNull JSONObject body) {
*
* @param taxonomyId - The taxonomy for which we need to update the details
* @param body the body
* @return the call <p></p> <b>Example</b> <pre> {@code
* @return the call <b>Example</b> <pre> {@code
* JSONObject body = new JSONObject();
* JSONObject bodyContent = new JSONObject();
* bodyContent.put("name", "Taxonomy 1");
Expand All @@ -215,14 +219,15 @@ public Call<ResponseBody> update(@NotNull String taxonomyId, @NotNull JSONObject
* Delete Taxonomy call.
*
* @param taxonomyId - The taxonomy for which we need to update the details
* @return the call <p></p> <b>Example</b> <pre> {@code
* @return the call <b>Example</b> <pre> {@code
* Response<ResponseBody> response = taxonomy.delete("taxonomyId").execute();
* } </pre>
*/
public Call<ResponseBody> delete(@NotNull String taxonomyId) {
return this.taxonomyService.delete(this.headers, taxonomyId);
}


/**
* Clear params for internal uses only for testing
*/
Expand All @@ -233,12 +238,11 @@ protected void clearParams() {

/**
* Get terms information
* <p>
* <p>Examples</p>
* <pre>
* {@code
* Term terms = stack("authtoken").taxonomy("taxonomyId").term();
* }*
* }
* </pre>
*
* @return instance of {@link Terms}
Expand All @@ -247,5 +251,4 @@ public Terms terms() {
return new Terms(this.taxonomyService, this.headers, this.taxonomyId);
}


}
24 changes: 18 additions & 6 deletions src/main/java/com/contentstack/cms/stack/TaxonomyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
public interface TaxonomyService {

@GET("taxonomies")
Call<ResponseBody> find(@HeaderMap Map<String, Object> headers, @QueryMap Map<String, Object> params);
Call<ResponseBody> find(
@HeaderMap Map<String, Object> headers,
@QueryMap Map<String, Object> params);

@GET("taxonomies/{taxonomy_uid}")
Call<ResponseBody> fetch(@HeaderMap Map<String, Object> headers, @Path("taxonomy_uid") String uid, @QueryMap Map<String, Object> query);
Call<ResponseBody> fetch(
@HeaderMap Map<String, Object> headers,
@Path("taxonomy_uid") String uid,
@QueryMap Map<String, Object> query);

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

//--Terms--

// --Terms--
@POST("taxonomies/{taxonomy_uid}/terms")
Call<ResponseBody> createTerm(
@HeaderMap HashMap<String, Object> headers,
Expand Down Expand Up @@ -73,10 +79,16 @@ Call<ResponseBody> updateTerm(
@Path("term_id") String termId,
@Body JSONObject body);

@PUT("taxonomies/{taxonomy_uid}/terms/{term_id}/move")
Call<ResponseBody> reorder(
@HeaderMap HashMap<String, Object> headers,
@Path("taxonomy_uid") String taxonomyId,
@Path("term_id") String termId,
@QueryMap Map<String, Object> queryParams,
@Body JSONObject body);

@GET("taxonomies/all/terms")
@GET("taxonomies/$all/terms")
Call<ResponseBody> searchTerm(
@HeaderMap HashMap<String, Object> headers,
@Query("term") String termString
);
@Query("typeahead") String termString);
}
Loading

0 comments on commit 41bba57

Please sign in to comment.