11package com .contentstack .cms ;
22
3- import com .contentstack .cms .assets .Asset ;
4- import com .contentstack .cms .contenttype .ContentType ;
53import com .contentstack .cms .core .AuthInterceptor ;
64import com .contentstack .cms .core .Error ;
75import com .contentstack .cms .core .Util ;
8- import com .contentstack .cms .entries .Entry ;
9- import com .contentstack .cms .global .GlobalField ;
106import com .contentstack .cms .models .LoginDetails ;
117import com .contentstack .cms .organization .Organization ;
128import com .contentstack .cms .stack .Stack ;
2218
2319import java .io .IOException ;
2420import java .net .Proxy ;
21+ import java .util .HashMap ;
22+ import java .util .Map ;
2523import java .util .logging .Logger ;
2624
25+ import static com .contentstack .cms .core .Util .*;
26+
2727/**
2828 * The type Contentstack.
2929 */
3030public class Contentstack {
3131
3232 public static final Logger logger = Logger .getLogger (Contentstack .class .getName ());
3333 protected final String host ;
34- /**
35- * The Port.
36- */
3734 protected final String port ;
38- /**
39- * The Version.
40- */
4135 protected final String version ;
42- /**
43- * The Timeout.
44- */
4536 protected final int timeout ;
46- /**
47- * The Authtoken.
48- */
4937 protected String authtoken ;
50- /**
51- * The Instance.
52- */
5338 protected Retrofit instance ;
54- /**
55- * The Retry on failure.
56- */
5739 protected final Boolean retryOnFailure ;
58- /**
59- * The Proxy.
60- */
6140 protected final Proxy proxy ;
62- /**
63- * The Interceptor.
64- */
6541 protected AuthInterceptor interceptor ;
66- /**
67- * The User.
68- */
6942 protected User user ;
7043
7144 /**
@@ -124,7 +97,7 @@ public User user() {
12497 * </pre>
12598 *
12699 * <br>
127- * <b>OR: </b>
100+ * <b>OR</b>
128101 *
129102 * <pre>
130103 * Contentstack client = new Contentstack.Builder().build();
@@ -285,11 +258,8 @@ public Organization organization() {
285258 }
286259
287260 /**
288- * <a href=
289- * "https://www.contentstack.com/docs/developers/apis/content-management-api/#stacks">stack</a>
290- * A stack is
291- * a space that stores the content of a project (a web or mobile property).
292- * Within a stack, you can create content
261+ * <a href= "https://www.contentstack.com/docs/developers/apis/content-management-api/#stacks">stack</a> A stack is
262+ * a space that stores the content of a project (a web or mobile property). Within a stack, you can create content
293263 * structures, content entries, users, etc. related to the project
294264 * <p>
295265 * <b> Example </b>
@@ -299,137 +269,101 @@ public Organization organization() {
299269 * Stack org = client.stack();
300270 * </pre>
301271 *
302- * @param apiKey
303- * the apiKey for the stack
304272 * @return the stack instance
305273 */
306- public Stack stack (@ NotNull String apiKey ) {
274+ public Stack stack () {
307275 if (this .authtoken == null )
308- throw new IllegalStateException ("Please Login to access stack instance" );
309- return new Stack (this .instance , apiKey );
276+ throw new IllegalStateException (ILLEGAL_USER );
277+ return new Stack (this .instance );
310278 }
311279
312- /**
313- * A Global field is a reusable field (or group of fields) that you can define
314- * once and reuse in any content type
315- * within your stack. This eliminates the need (and thereby time and efforts) to
316- * create the same set of fields
317- * repeatedly in multiple content types.
318- * <p>
319- * <b>Additional Resource:</b> You can create a dynamic and flexible Global
320- * field either by nesting Global field
321- * within the Modular Block or Group field within Global field
322- *
323- * @param apiKey
324- * the api key
325- * @param authorization
326- * the management token
327- * @return global field
328- */
329- public GlobalField globalField (@ NotNull String apiKey , @ NotNull String authorization ) {
330- if (this .authtoken == null )
331- throw new IllegalStateException ("Please Login to access GlobalField instance" );
332- return new GlobalField (this .instance , apiKey , authorization );
333- }
334280
335281 /**
336- * <b>Content type</b>
337- * <p>
338- * Content type defines the structure or schema of a page or a section of your
339- * web or mobile property. To create
340- * content for your application, you are required to first create a content
341- * type, and then create entries using the
342- * content type.
282+ * <a href= "https://www.contentstack.com/docs/developers/apis/content-management-api/#stacks">stack</a> A stack is
283+ * a space that stores the content of a project (a web or mobile property). Within a stack, you can create content
284+ * structures, content entries, users, etc. related to the project
343285 * <p>
286+ * <b> Example </b>
344287 *
345- * <b>Additional Resource</b>
346- * <p>
347- * To get an idea of building your content type as per webpage's layout, we
348- * recommend you to check out our Content
349- * Modeling guide
288+ * <pre>
289+ * Contentstack client = new Contentstack.Builder().build();
290+ * Stack org = client.stack();
291+ * </pre>
350292 *
351- * @param apiKey
352- * the api key
353- * @return the content type
293+ * @param header
294+ * the headers for the stack
295+ * @return the stack instance
354296 */
355- public ContentType contentType (@ NotNull String apiKey ) {
297+ public Stack stack (@ NotNull Map < String , Object > header ) {
356298 if (this .authtoken == null )
357- throw new IllegalStateException ("Please Login to access ContentType instance" );
358- return new ContentType (this .instance , apiKey , null );
299+ throw new IllegalStateException (PLEASE_LOGIN );
300+ return new Stack (this .instance , header );
359301 }
360302
303+
361304 /**
362- * <b>Content type</b>
363- * <p>
364- * Content type defines the structure or schema of a page or a section of your
365- * web or mobile property. To create
366- * content for your application, you are required to first create a content
367- * type, and then create entries using the
368- * content type.
305+ * <a href= "https://www.contentstack.com/docs/developers/apis/content-management-api/#stacks">stack</a> A stack is
306+ * a space that stores the content of a project (a web or mobile property). Within a stack, you can create content
307+ * structures, content entries, users, etc. related to the project
369308 * <p>
309+ * <b> Example </b>
370310 *
371- * <b>Additional Resource</b>
372- * <p>
373- * To get an idea of building your content type as per webpage's layout, we
374- * recommend you to check out our Content
375- * Modeling guide
311+ * <pre>
312+ * Contentstack client = new Contentstack.Builder().build();
313+ * Stack org = client.stack();
314+ * </pre>
376315 *
377- * @param apiKey
378- * the api key
379316 * @param managementToken
380- * the management token
381- * @return the content type
382- */
383- public ContentType contentType (
384- @ NotNull String apiKey ,
385- @ NotNull String managementToken ) {
386- if (this .authtoken == null )
387- throw new IllegalStateException ("Please Login to access ContentType instance" );
388- return new ContentType (this .instance , apiKey , managementToken );
389- }
390-
391- /**
392- * An entry is the actual piece of content created using one of the defined
393- * [content
394- * types](https://www.contentstack.com/docs/developers/create-content-types/about-content-types/).
395- *
317+ * the authorization for the stack
396318 * @param apiKey
397- * the api key
398- * @param managementToken
399- * the management token
400- * @return {@link Entry} Entry instance
319+ * the apiKey for the stack
320+ * @return the stack instance
401321 */
402- public Entry entry (@ NotNull String apiKey , @ NotNull String managementToken ) {
322+ public Stack stack (@ NotNull String apiKey , @ NotNull String managementToken ) {
403323 if (this .authtoken == null )
404- throw new IllegalStateException ("Please Login to access Entry instance" );
405- return new Entry (this .instance , apiKey , managementToken , "product" );
324+ throw new IllegalStateException (PLEASE_LOGIN );
325+ HashMap <String , Object > headers = new HashMap <>();
326+ headers .put (API_KEY , apiKey );
327+ headers .put (AUTHORIZATION , managementToken );
328+ return new Stack (this .instance , headers );
406329 }
407330
408331 /**
409- * <b>Assets</b><br>
410- * Assets refer to all the media files (images, videos, PDFs, audio files, and
411- * so on) uploaded in your Contentstack
412- * repository for future use.
332+ * <a href= "https://www.contentstack.com/docs/developers/apis/content-management-api/#stacks">stack</a> A stack is
333+ * a space that stores the content of a project (a web or mobile property). Within a stack, you can create content
334+ * structures, content entries, users, etc. related to the project
413335 * <p>
414- * These files can be attached and used in multiple entries.
336+ * <b> Example </b>
337+ *
338+ * <pre>
339+ * Contentstack client = new Contentstack.Builder().build();
340+ * Stack org = client.stack();
341+ * </pre>
415342 *
416- * @param apiKey
417- * the api key
418343 * @param managementToken
419- * the management token
420- * @return {@link com.contentstack.cms.assets.Asset} Asset instance
344+ * the authorization for the stack
345+ * @param apiKey
346+ * the apiKey for the stack
347+ * @param branch
348+ * the branch that include branching in the response
349+ * @return the stack instance
421350 */
422- public Asset asset (@ NotNull String apiKey , @ NotNull String managementToken ) {
351+ public Stack stack (@ NotNull String apiKey , @ NotNull String managementToken , @ NotNull String branch ) {
423352 if (this .authtoken == null )
424- throw new IllegalStateException ("Please Login to access Asset instance" );
425- return new Asset (this .instance , apiKey , managementToken );
353+ throw new IllegalStateException (PLEASE_LOGIN );
354+ HashMap <String , Object > headers = new HashMap <>();
355+ headers .put (API_KEY , apiKey );
356+ headers .put (AUTHORIZATION , managementToken );
357+ headers .put (BRANCH , branch );
358+ return new Stack (this .instance , headers );
426359 }
427360
361+
428362 /**
429363 * Instantiates a new Contentstack.
430364 *
431365 * @param builder
432- * the builder
366+ * the builder
433367 */
434368 public Contentstack (Builder builder ) {
435369 this .host = builder .hostname ;
0 commit comments