Skip to content

Commit e003607

Browse files
v0.1.0
1 parent a3b0f44 commit e003607

40 files changed

+2755
-1846
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.configuration.updateBuildConfiguration": "automatic"
3+
}

changelog.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
# Changelog
2+
3+
## v0.1.0
4+
5+
### 20-OCT-2022
16

2-
## v1.0.0
3-
#### 03-SEP-2021
47
Initial release for Contentstack CMA base Java management SDK

pom.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
43
<modelVersion>4.0.0</modelVersion>
54
<groupId>com.contentstack.sdk</groupId>
65
<artifactId>cms</artifactId>
@@ -77,7 +76,7 @@
7776
</distributionManagement>
7877

7978
<properties>
80-
<sdk.version>1.0.0-SNAPSHOT</sdk.version>
79+
<sdk.version>0.1.0-SNAPSHOT</sdk.version>
8180
<sdk.version.snapshot>${sdk.version}-SNAPSHOT</sdk.version.snapshot>
8281
<maven.compiler.target>1.8</maven.compiler.target>
8382
<maven.compiler.source>1.8</maven.compiler.source>
@@ -337,7 +336,7 @@
337336
</goals>
338337
</pluginExecutionFilter>
339338
<action>
340-
<ignore/>
339+
<ignore />
341340
</action>
342341
</pluginExecution>
343342
</pluginExecutions>

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
/**
2828
* <b>Contentstack Java Management SDK</b>
2929
* <br>
30-
* <b>Contentstack Java Management SDK</b> interact with the Content Management APIs and allow you to create, update,
31-
* delete, and fetch content from your Contentstack account. They are read-write in nature.
30+
* <b>Java Management SDK</b> Interact with the Content Management APIs and allow you to create, update,
31+
* delete, and fetch content from your Contentstack account. (They are read-write in nature.)
3232
* <br>
3333
* You can use them to build your own apps and manage your content from Contentstack.
3434
*/
@@ -330,7 +330,7 @@ public Stack stack() {
330330
* @return the stack instance
331331
*/
332332
public Stack stack(@NotNull Map<String, Object> header) {
333-
if (this.authtoken == null && header.size() == 0)
333+
if (this.authtoken == null && !header.containsKey(AUTHORIZATION) && header.get(AUTHORIZATION) == null)
334334
throw new IllegalStateException(PLEASE_LOGIN);
335335
return new Stack(this.instance, header);
336336
}
@@ -355,14 +355,41 @@ public Stack stack(@NotNull Map<String, Object> header) {
355355
* @return the stack instance
356356
*/
357357
public Stack stack(@NotNull String apiKey, @NotNull String managementToken) {
358-
if (this.authtoken == null)
359-
throw new IllegalStateException(PLEASE_LOGIN);
360358
HashMap<String, Object> headers = new HashMap<>();
361359
headers.put(API_KEY, apiKey);
362360
headers.put(AUTHORIZATION, managementToken);
363361
return new Stack(this.instance, headers);
364362
}
365363

364+
365+
/**
366+
* <a href= "https://www.contentstack.com/docs/developers/apis/content-management-api/#stacks">stack</a> A stack is
367+
* a space that stores the content of a project (a web or mobile property). Within a stack, you can create content
368+
* structures, content entries, users, etc. related to the project
369+
* <p>
370+
* <b> Example </b>
371+
*
372+
* <pre>
373+
* Contentstack client = new Contentstack.Builder().build();
374+
* Stack org = client.stack();
375+
* </pre>
376+
*
377+
* @param key
378+
* You can provide apiKey of the stack or branchKey
379+
* @return the stack instance
380+
*/
381+
public Stack stack(@NotNull String key) {
382+
HashMap<String, Object> headers = new HashMap<>();
383+
if (key.startsWith("blt")) {
384+
// In the case of API_Key provided
385+
headers.put(API_KEY, key);
386+
} else {
387+
// In case of branch provided
388+
headers.put(BRANCH, key);
389+
}
390+
return new Stack(this.instance, headers);
391+
}
392+
366393
/**
367394
* <a href= "https://www.contentstack.com/docs/developers/apis/content-management-api/#stacks">stack</a> A stack is
368395
* a space that stores the content of a project (a web or mobile property). Within a stack, you can create content
@@ -384,8 +411,6 @@ public Stack stack(@NotNull String apiKey, @NotNull String managementToken) {
384411
* @return the stack instance
385412
*/
386413
public Stack stack(@NotNull String apiKey, @NotNull String managementToken, @NotNull String branch) {
387-
if (this.authtoken == null)
388-
throw new IllegalStateException(PLEASE_LOGIN);
389414
HashMap<String, Object> headers = new HashMap<>();
390415
headers.put(API_KEY, apiKey);
391416
headers.put(AUTHORIZATION, managementToken);

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
/**
1111
* <b>The type Header interceptor that extends Interceptor</b>
1212
* <p>
13-
* Interceptors are a powerful way to customize requests with Retrofit. A common use-case where you want to intercept
14-
* the actual request is to observe, modifies, and potentially short-circuits requests going out and the corresponding
15-
* responses coming back in. Typically, interceptors add, remove, or transform headers on the request. Depending on the
16-
* API implementation, you'll want to pass the auth token as the value for the Authorization header.
13+
* Interceptors are a powerful way to customize requests with Retrofit. A common
14+
* use-case where you want to intercept
15+
* the actual request is to observe, modifies, and potentially short-circuits
16+
* requests going out and the corresponding
17+
* responses coming back in. Typically, interceptors add, remove, or transform
18+
* headers on the request. Depending on the
19+
* API implementation, you'll want to pass the auth token as the value for the
20+
* Authorization header.
1721
*
1822
* @author ***REMOVED***
19-
* @version 1.0.0
20-
* @since 2022-05-19
23+
* @since v0.1.0
2124
*/
2225
public class AuthInterceptor implements Interceptor {
2326

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* The Contentstack Logger
99
*
1010
* @author ***REMOVED***
11-
* @version 1.0.0
12-
* @since 2022-05-19
11+
* @version v0.1.0
12+
* @since 2022-10-20
1313
*/
1414
public class CMALogger {
1515

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
* Contentstack Response:
1414
*
1515
* @author ***REMOVED***
16-
* @version 1.0.0
17-
* @since 2022-05-19
16+
* @version v0.1.0
17+
* @since 2022-10-20
1818
*/
1919

2020
public class CMAResponseConvertor {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
* CMARuntimeException that extends Exception class
55
*
66
* @author ***REMOVED***
7-
* @version 1.0.0
8-
* @since 2022-05-19
7+
* @version v0.1.0
8+
* @since 2022-10-20
99
*/
10-
public class CMARuntimeException extends Exception { public CMARuntimeException(String message) {
10+
public class CMARuntimeException extends Exception {
11+
public CMARuntimeException(String message) {
1112
super(message);
12-
}}
13+
}
14+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
import java.io.IOException;
88

9-
109
/**
11-
* The ContentstackResponse is the response when we execute the API Response, ContentstackResponse contains different
10+
* The ContentstackResponse is the response when we execute the API Response,
11+
* ContentstackResponse contains different
1212
* response type
1313
*
1414
* @author ***REMOVED***
15-
* @version 1.0.0
16-
* @since 2022-05-19
15+
* @version v0.1.0
16+
* @since 2022-10-20
1717
*/
1818
class ContentstackResponse<T> {
1919

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.contentstack.cms.core;
2+
3+
public class NullKeyException extends Exception {
4+
5+
public NullKeyException() {
6+
super();
7+
}
8+
9+
/**
10+
* Constructs a new exception with the specified detail message. The
11+
* cause is not initialized, and may subsequently be initialized by
12+
* a call to {@link #initCause}.
13+
*
14+
* @param message the detail message. The detail message is saved for
15+
* later retrieval by the {@link #getMessage()} method.
16+
*/
17+
public NullKeyException(String message) {
18+
super(message);
19+
}
20+
21+
}

0 commit comments

Comments
 (0)