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 );
0 commit comments