Skip to content

Commit 1a8508f

Browse files
Detailed API Docs added
1 parent 85f7a18 commit 1a8508f

File tree

13 files changed

+511
-264
lines changed

13 files changed

+511
-264
lines changed
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
package com.contentstack.cms.stack;
2+
3+
import okhttp3.ResponseBody;
4+
import org.jetbrains.annotations.NotNull;
5+
import org.json.simple.JSONObject;
6+
import retrofit2.Call;
7+
import retrofit2.Retrofit;
8+
9+
import java.util.HashMap;
10+
11+
12+
/**
13+
* <b>Delivery tokens:</b>Delivery tokens provide read-only access to the associated environments, while management
14+
* tokens provide read-write access to the content of your stack. Use these tokens along with the stack API key to make
15+
* authorized API requests.
16+
* <br>
17+
* <b>Management tokens: </b> To authenticate Content Management API (CMA) requests over your stack content, you can
18+
* use Management Tokens
19+
* <br>
20+
*
21+
* @author ***REMOVED***
22+
* @version 1.0.0
23+
* @since 2022-05-19
24+
*/
25+
public class DeliveryToken {
26+
27+
protected final TokenService service;
28+
protected HashMap<String, Object> headers;
29+
protected HashMap<String, Object> params;
30+
31+
protected DeliveryToken(TokenService tokenService, HashMap<String, Object> stack) {
32+
this.headers = new HashMap<>();
33+
this.params = new HashMap<>();
34+
this.headers.putAll(stack);
35+
this.service = tokenService;
36+
}
37+
38+
39+
/**
40+
* Sets header for the request
41+
*
42+
* @param key
43+
* header key for the request
44+
* @param value
45+
* header value for the request
46+
*/
47+
public void addHeader(@NotNull String key, @NotNull Object value) {
48+
this.headers.put(key, value);
49+
}
50+
51+
/**
52+
* Sets header for the request
53+
*
54+
* @param key
55+
* query param key for the request
56+
* @param value
57+
* query param value for the request
58+
*/
59+
public void addParam(@NotNull String key, @NotNull Object value) {
60+
this.params.put(key, value);
61+
}
62+
63+
64+
/**
65+
* Set header for the request
66+
*
67+
* @param key
68+
* Removes query param using key of request
69+
*/
70+
public void removeParam(@NotNull String key) {
71+
this.params.remove(key);
72+
}
73+
74+
75+
/**
76+
* To clear all the query params
77+
*/
78+
protected void clearParams() {
79+
this.params.clear();
80+
}
81+
82+
83+
/**
84+
* The Get all delivery tokens request returns the details of all the delivery tokens created in a stack.
85+
*
86+
* @return Call
87+
* @see <a
88+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#get-all-delivery-tokens">Get all
89+
* Delivery Tokens
90+
* </a>
91+
* @see #addHeader(String, Object) to add headers
92+
* @see #addParam(String, Object) to add query parameters
93+
* @since 1.0.0
94+
*/
95+
public Call<ResponseBody> fetch() {
96+
return this.service.getDeliveryToken(this.headers);
97+
}
98+
99+
/**
100+
* The Get a single delivery token request returns the details of all the delivery tokens created in a stack.
101+
*
102+
* @param tokenUid
103+
* The UID of the token that you want to retrieve a delivery token
104+
* @return Call
105+
* @see <a
106+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#get-a-single-delivery-token">Get
107+
* a Single Delivery Token
108+
* </a>
109+
* @see #addHeader(String, Object) to add headers
110+
* @see #addParam(String, Object) to add query parameters
111+
* @since 1.0.0
112+
*/
113+
public Call<ResponseBody> single(@NotNull String tokenUid) {
114+
return this.service.getDeliveryToken(this.headers, tokenUid);
115+
}
116+
117+
/**
118+
* The Create delivery token request is used to create a delivery token in the stack.
119+
* <p>
120+
* In the Request Body, you need to pass the details of the delivery token in JSON format. The details include the
121+
* name, description, and the environment of the delivery token.
122+
*
123+
* @param requestBody
124+
* The request body to create a delivery token
125+
* @return Call
126+
* @see <a
127+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#create-delivery-token">Create
128+
* Delivery Token
129+
* </a>
130+
* @see #addHeader(String, Object) to add headers
131+
* @see #addParam(String, Object) to add query parameters
132+
* @since 1.0.0
133+
*/
134+
public Call<ResponseBody> create(@NotNull JSONObject requestBody) {
135+
return this.service.createDeliveryToken(this.headers, requestBody);
136+
}
137+
138+
/**
139+
* The Update delivery token request lets you update the details of a delivery token.
140+
* <p>
141+
* In the Request Body, you need to pass the updated details of the delivery token in JSON format. The details
142+
* include the updated name, description, and/or the environment of the delivery token.
143+
* <p>
144+
* You need to specify the branch and alias scope for your delivery token through the following schema in the
145+
* request body:
146+
*
147+
* @param tokenUid
148+
* The UID of the token that you want to update
149+
* @param requestBody
150+
* the body should be of @{@link JSONObject} type
151+
* @return Call
152+
* @see <a
153+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#update-delivery-token">Update
154+
* Delivery Token
155+
* </a>
156+
* @see #addHeader(String, Object) to add headers
157+
* @see #addParam(String, Object) to add query parameters
158+
* @since 1.0.0
159+
*/
160+
public Call<ResponseBody> update(@NotNull String tokenUid, @NotNull JSONObject requestBody) {
161+
return this.service.updateDeliveryToken(this.headers, tokenUid, requestBody);
162+
}
163+
164+
/**
165+
* The Delete delivery token request deletes a specific delivery token
166+
*
167+
* @param tokenUid
168+
* The UID of the token that you want to delete
169+
* @return Call
170+
* @see <a
171+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-delivery-token">Delete
172+
* Delivery Token
173+
* </a>
174+
* @see #addHeader(String, Object) to add headers
175+
* @see #addParam(String, Object) to add query parameters
176+
* @since 1.0.0
177+
*/
178+
public Call<ResponseBody> delete(@NotNull String tokenUid) {
179+
return this.service.deleteDeliveryToken(this.headers, tokenUid, false);
180+
}
181+
182+
/**
183+
* The Delete delivery token request deletes a specific delivery token.
184+
*
185+
* @param tokenUid
186+
* The UID of the token that you want to delete
187+
* @param isForce
188+
* provide ‘true’ to force delete a delivery token
189+
* @return Call
190+
* @see <a
191+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-delivery-token">Delete
192+
* Delivery Token
193+
* </a>
194+
* @see #addHeader(String, Object) to add headers
195+
* @see #addParam(String, Object) to add query parameters
196+
* @since 1.0.0
197+
*/
198+
public Call<ResponseBody> delete(@NotNull String tokenUid, @NotNull Boolean isForce) {
199+
return this.service.deleteDeliveryToken(this.headers, tokenUid, isForce);
200+
}
201+
202+
203+
}
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
package com.contentstack.cms.stack;
2+
3+
import okhttp3.ResponseBody;
4+
import org.jetbrains.annotations.NotNull;
5+
import org.json.simple.JSONObject;
6+
import retrofit2.Call;
7+
8+
import java.util.HashMap;
9+
10+
11+
/**
12+
* <b>Management tokens: </b> <br>To authenticate Content Management API (CMA) requests over your stack content, you
13+
* can
14+
* use Management Tokens
15+
* <br>
16+
*
17+
* @author ***REMOVED***
18+
* @version 1.0.0
19+
* @since 2022-05-19
20+
*/
21+
public class ManagementToken {
22+
23+
protected final TokenService service;
24+
protected HashMap<String, Object> headers;
25+
protected HashMap<String, Object> params;
26+
27+
protected ManagementToken(TokenService tokenService, HashMap<String, Object> stackHeaders) {
28+
this.headers = new HashMap<>();
29+
this.params = new HashMap<>();
30+
this.headers.putAll(stackHeaders);
31+
this.service = tokenService;
32+
}
33+
34+
35+
/**
36+
* Sets header for the request
37+
*
38+
* @param key
39+
* header key for the request
40+
* @param value
41+
* header value for the request
42+
*/
43+
public void addHeader(@NotNull String key, @NotNull Object value) {
44+
this.headers.put(key, value);
45+
}
46+
47+
/**
48+
* Sets header for the request
49+
*
50+
* @param key
51+
* query param key for the request
52+
* @param value
53+
* query param value for the request
54+
*/
55+
public void addParam(@NotNull String key, @NotNull Object value) {
56+
this.params.put(key, value);
57+
}
58+
59+
60+
/**
61+
* Set header for the request
62+
*
63+
* @param key
64+
* Removes query param using key of request
65+
*/
66+
public void removeParam(@NotNull String key) {
67+
this.params.remove(key);
68+
}
69+
70+
71+
/**
72+
* To clear all the query params
73+
*/
74+
protected void clearParams() {
75+
this.params.clear();
76+
}
77+
78+
79+
/**
80+
* Sets header for the request
81+
*
82+
* @param key
83+
* header key for the request
84+
* @param value
85+
* header value for the request
86+
* @return Tokens
87+
*/
88+
public ManagementToken addHeader(@NotNull String key, @NotNull String value) {
89+
this.headers.put(key, value);
90+
return this;
91+
}
92+
93+
94+
/**
95+
* The Get all management tokens request returns the details of all the management tokens generated in a stack and
96+
* NOT the actual management tokens.
97+
*
98+
* @return Call
99+
* @see <a
100+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#get-all-management-tokens">Get
101+
* all Management Tokens
102+
* </a>
103+
* @see #addHeader(String, Object) to add headers
104+
* @see #addParam(String, Object) to add query parameters
105+
* @since 1.0.0
106+
*/
107+
public Call<ResponseBody> fetch() {
108+
return this.service.fetchManagementToken(this.headers, this.params);
109+
}
110+
111+
/**
112+
* The Get a single management token request returns the details of a specific management token generated in a stack
113+
* and NOT the actual management token.
114+
*
115+
* @param tokenUid
116+
* the UID of the token that you want to retrieve
117+
* @return Call
118+
* @see <a
119+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#get-a-single-management-token">Get
120+
* a single management token
121+
* </a>
122+
* @see #addHeader(String, Object) to add headers
123+
* @since 1.0.0
124+
*/
125+
public Call<ResponseBody> single(@NotNull String tokenUid) {
126+
return this.service.getSingleManagementToken(this.headers, tokenUid);
127+
}
128+
129+
/**
130+
* The Create management token request is used to create a management token in a stack. This token provides you with
131+
* read-write access to the content of your stack.
132+
*
133+
* @param requestBody
134+
* details of the management token in @{@link JSONObject} format
135+
* @return Call
136+
* @see <a
137+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#create-management-token">Create a
138+
* management token
139+
* </a>
140+
* @see #addHeader(String, Object) to add headers
141+
* @since 1.0.0
142+
*/
143+
public Call<ResponseBody> create(@NotNull JSONObject requestBody) {
144+
return this.service.createManagementToken(this.headers, requestBody);
145+
}
146+
147+
/**
148+
* The Update management token request lets you update the details of a management token. You can change the name
149+
* and description of the token; update the stack-level permissions assigned to the token; and change the expiry
150+
* date of the token (if set).
151+
* <p>
152+
* In the Request Body, you need to pass the updated details of the management token in JSON format.
153+
* <p>
154+
* To specify the updated branch and alias scope for your management token, use the following schema in the request
155+
* body:
156+
*
157+
* @param tokenUid
158+
* the UID of the token that you want to retrieve
159+
* @param requestBody
160+
* details of the management token in @{@link JSONObject} format
161+
* @return Call
162+
* @see <a
163+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#update-management-token">Update
164+
* management token
165+
* </a>
166+
* @see #addHeader(String, Object) to add headers
167+
* @since 1.0.0
168+
*/
169+
public Call<ResponseBody> update(@NotNull String tokenUid, @NotNull JSONObject requestBody) {
170+
return this.service.updateManagementToken(this.headers, tokenUid, requestBody);
171+
}
172+
173+
/**
174+
* The Delete management token request deletes a specific management token
175+
*
176+
* @param tokenUid
177+
* the UID of the token that you want to retrieve
178+
* @return Call
179+
* @see <a
180+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-management-token">Delete
181+
* management token
182+
* </a>
183+
* @see #addHeader(String, Object) to add headers
184+
* @since 1.0.0
185+
*/
186+
public Call<ResponseBody> delete(@NotNull String tokenUid) {
187+
return this.service.deleteManagementToken(this.headers, tokenUid);
188+
}
189+
190+
}

0 commit comments

Comments
 (0)