Skip to content

Commit

Permalink
Merge pull request #97 from contentstack/next
Browse files Browse the repository at this point in the history
Taxonomy and Early Access Header
  • Loading branch information
ishaileshmishra authored Dec 18, 2023
2 parents 3509899 + 336f7bd commit e263041
Show file tree
Hide file tree
Showing 14 changed files with 774 additions and 354 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# CHANGELOG

## v1.13.0

### Date: 17-Nov-2023

- Updated Latest version of Utils SDK to 1.2.6
- Snyk Issues fixed
- Updated dependencies
- Added support for early access feature

## v1.12.3

### Date: 28-SEP-2023
Expand Down
15 changes: 8 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.contentstack.sdk</groupId>
<artifactId>java</artifactId>
<version>1.12.3</version>
<version>1.13.0</version>
<packaging>jar</packaging>
<name>contentstack-java</name>
<description>Java SDK for Contentstack Content Delivery API</description>
Expand All @@ -25,18 +25,18 @@
<loggin.version>5.0.0-alpha.11</loggin.version>
<jococo-plugin.version>0.8.5</jococo-plugin.version>
<lombok-source.version>1.18.30</lombok-source.version>
<junit-jupiter.version>5.10.0</junit-jupiter.version>
<junit-jupiter.version>5.10.1</junit-jupiter.version>
<junit-jupiter-engine.version>5.8.0-M1</junit-jupiter-engine.version>
<gson.version>2.8.8</gson.version>
<json-simple-version>1.1.1</json-simple-version>
<maven-site-plugin.version>3.3</maven-site-plugin.version>
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
<json-version>20230618</json-version>
<json-version>20231013</json-version>
<jacoco-maven-plugin-version>0.8.7</jacoco-maven-plugin-version>
<maven-release-plugin-version>2.5.3</maven-release-plugin-version>
<contentstack-utils-version>1.2.4</contentstack-utils-version>
<contentstack-utils-version>1.2.6</contentstack-utils-version>
</properties>

<parent>
Expand Down Expand Up @@ -122,13 +122,14 @@
<scope>compile</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/io.github.cdimascio/java-dotenv -->
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-java</artifactId>
<version>${dotenv-source.version}</version>
<!--<scope>runtime</scope>-->
<artifactId>java-dotenv</artifactId>
<version>5.2.2</version>
</dependency>


<dependency>
<groupId>io.reactivex.rxjava3</groupId>
<artifactId>rxjava</artifactId>
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/contentstack/sdk/APIService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.HeaderMap;
import retrofit2.http.Query;
import retrofit2.http.Url;

import java.util.LinkedHashMap;
import java.util.Map;

/**
* @author Shailesh Mishra
Expand All @@ -15,5 +17,11 @@
*/
public interface APIService {
@GET
Call<ResponseBody> getRequest(@Url String url, @HeaderMap LinkedHashMap<String, Object> headers);
Call<ResponseBody> getRequest(
@Url String url, @HeaderMap LinkedHashMap<String, Object> headers);

@GET("v3/taxonomies/entries")
Call<ResponseBody> getTaxonomy(
@HeaderMap Map<String, Object> headers,
@Query("query") String query);
}
4 changes: 2 additions & 2 deletions src/main/java/com/contentstack/sdk/CSHttpConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ public void send() {
}

private void getService(String requestUrl) throws IOException {
this.headers.put(X_USER_AGENT_KEY, "contentstack-java/" + SDK_VERSION);

this.headers.put(X_USER_AGENT_KEY, "contentstack-delivery-java/" + SDK_VERSION);
this.headers.put(USER_AGENT_KEY, USER_AGENT);
this.headers.put(CONTENT_TYPE, APPLICATION_JSON);

Expand Down Expand Up @@ -260,7 +261,6 @@ void handleJSONObject(JSONArray arrayEntry, JSONObject jsonObj, int idx) {
}

void setError(String errResp) {
logger.info(errResp);
responseJSON = new JSONObject(errResp); // Parse error string to JSONObject
responseJSON.put(ERROR_MESSAGE, responseJSON.optString(ERROR_MESSAGE));
responseJSON.put(ERROR_CODE, responseJSON.optString(ERROR_CODE));
Expand Down
56 changes: 29 additions & 27 deletions src/main/java/com/contentstack/sdk/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,21 @@ public class Config {
protected String managementToken;
protected String branch;
protected Proxy proxy = null;
protected String[] earlyAccess = null;
protected ConnectionPool connectionPool = new ConnectionPool();

protected List<ContentstackPlugin> plugins = null;


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

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

public String getBranch() {
return branch;
}
Expand All @@ -43,17 +54,16 @@ public void setBranch(String branch) {
/**
* Proxy can be set like below.
*
* @param proxy
* Proxy setting, typically a type (http, socks) and a socket address. A Proxy is an immutable object
* <br>
* <br>
* <b>Example:</b><br>
* <br>
* <code>
* java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyHost", "proxyPort"));
* java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("sl.theproxyvpn.io", 80)); Config
* config = new Config(); config.setProxy(proxy);
* </code>
* @param proxy Proxy setting, typically a type (http, socks) and a socket address. A Proxy is an immutable object
* <br>
* <br>
* <b>Example:</b><br>
* <br>
* <code>
* java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyHost", "proxyPort"));
* java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("sl.theproxyvpn.io", 80)); Config
* config = new Config(); config.setProxy(proxy);
* </code>
*/
public void setProxy(Proxy proxy) {
this.proxy = proxy;
Expand All @@ -73,12 +83,9 @@ public Proxy getProxy() {
* {@link okhttp3.Address} may share a {@link okhttp3.Connection}. This class implements the policy * of which
* connections to keep open for future use.
*
* @param maxIdleConnections
* the maxIdleConnections default value is 5
* @param keepAliveDuration
* the keepAliveDuration default value is 5
* @param timeUnit
* the timeUnit default value is TimeUnit. MINUTES
* @param maxIdleConnections the maxIdleConnections default value is 5
* @param keepAliveDuration the keepAliveDuration default value is 5
* @param timeUnit the timeUnit default value is TimeUnit. MINUTES
* @return ConnectionPool
*/
public ConnectionPool connectionPool(int maxIdleConnections, long keepAliveDuration, TimeUnit timeUnit) {
Expand All @@ -98,8 +105,7 @@ public ContentstackRegion getRegion() {
/**
* Sets region.
*
* @param region
* the region
* @param region the region
* @return the region
*/
public ContentstackRegion setRegion(ContentstackRegion region) {
Expand Down Expand Up @@ -131,8 +137,7 @@ public String getHost() {
/**
* Sets host.
*
* @param hostName
* the host name
* @param hostName the host name
*/
public void setHost(String hostName) {
if (hostName != null && !hostName.isEmpty()) {
Expand All @@ -152,8 +157,7 @@ public String getVersion() {
/**
* Enable live preview config.
*
* @param enableLivePreview
* to enable live preview
* @param enableLivePreview to enable live preview
* @return the config
*/
public Config enableLivePreview(boolean enableLivePreview) {
Expand All @@ -164,8 +168,7 @@ public Config enableLivePreview(boolean enableLivePreview) {
/**
* Sets live preview host.
*
* @param livePreviewHost
* the live preview host
* @param livePreviewHost the live preview host
* @return the live preview host
*/
public Config setLivePreviewHost(@NotNull String livePreviewHost) {
Expand All @@ -181,8 +184,7 @@ protected Config setLivePreviewEntry(@NotNull JSONObject livePreviewEntry) {
/**
* Sets management token.
*
* @param managementToken
* the management token
* @param managementToken the management token
* @return the management token
*/
public Config setManagementToken(@NotNull String managementToken) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/contentstack/sdk/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class Constants {

private static final Logger logger = Logger.getLogger(Constants.class.getSimpleName());
protected static final String SDK_VERSION = "1.12.3";
protected static final String SDK_VERSION = "1.13.0";
protected static final String ENVIRONMENT = "environment";
protected static final String CONTENT_TYPE_UID = "content_type_uid";
protected static final String ENTRY_UID = "entry_uid";
Expand Down
41 changes: 18 additions & 23 deletions src/main/java/com/contentstack/sdk/Contentstack.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,23 @@ protected Contentstack() throws IllegalAccessException {
* key of your stack. <br>
* Find Your Stack Credentials from Contentstack .
*
* @param stackApiKey
* The API Key is a unique key assigned to each stack.
* @param deliveryToken
* The Delivery Token is a read-only credential that you
* @param stackApiKey The API Key is a unique key assigned to each stack.
* @param deliveryToken The Delivery Token is a read-only credential that you
* can create for different environments of your
* stack
* @param environment
* the environment for the stack
* @param environment the environment for the stack
* @return the stack
* @throws IllegalAccessException
* the illegal access exception
* @throws IllegalAccessException the illegal access exception
* <p>
* <b>Example</b>
*
* <pre>
* {
* &#64;Code
* Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
* }
* {
* &#64;Code
* Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
* }
*
* </pre>
* </pre>
*/
public static Stack stack(String stackApiKey, String deliveryToken, String environment)
throws IllegalAccessException {
Expand All @@ -66,19 +62,14 @@ public static Stack stack(String stackApiKey, String deliveryToken, String envir
* create content structures, content entries, users, etc. related to the
* project.
*
* @param stackApiKey
* The API Key is a unique key assigned to each stack.
* @param deliveryToken
* The Delivery Token is a read-only credential that you
* @param stackApiKey The API Key is a unique key assigned to each stack.
* @param deliveryToken The Delivery Token is a read-only credential that you
* can create for different environments of your
* stack
* @param environment
* the environment for the stack
* @param config
* the config
* @param environment the environment for the stack
* @param config the config
* @return the stack
* @throws IllegalAccessException
* the illegal access exception <b>Example</b>
* @throws IllegalAccessException the illegal access exception <b>Example</b>
* <p>
* { @Code Stack stack =
* contentstack.Stack("apiKey", "deliveryToken",
Expand Down Expand Up @@ -115,6 +106,10 @@ private static Stack initializeStack(String stackApiKey, String deliveryToken, S
if (config.getBranch() != null && !config.getBranch().isEmpty()) {
stack.setHeader("branch", config.getBranch());
}
if (config.getEarlyAccess() != null && config.getEarlyAccess().length > 0) {
String eaValues = String.join(",", config.earlyAccess).replace("\"", "");
stack.setHeader("x-header-ea", eaValues);
}
stack.setConfig(config);
return stack;
}
Expand Down
Loading

0 comments on commit e263041

Please sign in to comment.