@@ -37,7 +37,7 @@ public class GlobalField implements BaseImplementation<GlobalField> {
3737 protected HashMap <String , Object > headers ;
3838 protected HashMap <String , Object > params ;
3939 protected String globalFiledUid ;
40-
40+ protected String apiVersion ;
4141 protected GlobalField (Retrofit retrofit ,Map <String , Object > headers ) {
4242 this .headers = new HashMap <>();
4343 this .headers .putAll (headers );
@@ -85,7 +85,23 @@ public GlobalField addParam(@NotNull String key, @NotNull Object value) {
8585 */
8686 @ Override
8787 public GlobalField addHeader (@ NotNull String key , @ NotNull String value ) {
88- this .headers .put (key , value );
88+ if ("api_version" .equalsIgnoreCase (key )) {
89+ this .apiVersion = value ;
90+ } else {
91+ this .headers .put (key , value );
92+ }
93+ return this ;
94+ }
95+
96+ /**
97+ * @param key The key parameter is a string that represents the name or
98+ * identifier of the header.
99+ * It is used to specify the type of information being sent in the
100+ * header.
101+ * @return instance of the GlobalField object
102+ */
103+ public GlobalField removeHeader (@ NotNull String key ) {
104+ this .headers .remove (key );
89105 return this ;
90106 }
91107
@@ -110,6 +126,10 @@ public GlobalField addParams(@NotNull HashMap<String, Object> params) {
110126 */
111127 @ Override
112128 public GlobalField addHeaders (@ NotNull HashMap <String , String > headers ) {
129+ if (headers .containsKey ("api_version" )) {
130+ this .apiVersion = headers .get ("api_version" );
131+ headers .remove ("api_version" );
132+ }
113133 this .headers .putAll (headers );
114134 return this ;
115135 }
@@ -134,6 +154,21 @@ protected GlobalField clearParams() {
134154 this .params .clear ();
135155 return this ;
136156 }
157+ /*
158+ * For Nested Global Fields the api_version is set to 3.2 which needs
159+ * to removed from the headers inorder for other modules to function correctly
160+ */
161+
162+ /**
163+ * Returns a copy of the headers with api_version set if needed.
164+ */
165+ private Map <String , Object > getRequestHeaders () {
166+ Map <String , Object > requestHeaders = new HashMap <>(this .headers );
167+ if (this .apiVersion != null ) {
168+ requestHeaders .put ("api_version" , this .apiVersion );
169+ }
170+ return requestHeaders ;
171+ }
137172
138173 /**
139174 * <b>Get All Global Fields</b>
@@ -158,7 +193,7 @@ protected GlobalField clearParams() {
158193 * @since 0.1.0
159194 */
160195 public Call <ResponseBody > find () {
161- return this .service .fetch (this . headers , this .params );
196+ return this .service .fetch (getRequestHeaders () , this .params );
162197 }
163198
164199 /**
@@ -188,7 +223,7 @@ public Call<ResponseBody> find() {
188223 */
189224 public Call <ResponseBody > fetch () {
190225 validate ();
191- return this .service .single (this . headers , this .globalFiledUid , this .params );
226+ return this .service .single (getRequestHeaders () , this .globalFiledUid , this .params );
192227 }
193228
194229 /**
@@ -219,7 +254,7 @@ public Call<ResponseBody> fetch() {
219254 * @since 0.1.0
220255 */
221256 public Call <ResponseBody > create (@ NotNull JSONObject requestBody ) {
222- return this .service .create (this . headers , requestBody );
257+ return this .service .create (getRequestHeaders () , requestBody );
223258 }
224259
225260 /**
@@ -249,7 +284,7 @@ public Call<ResponseBody> create(@NotNull JSONObject requestBody) {
249284 */
250285 public Call <ResponseBody > update (@ NotNull JSONObject requestBody ) {
251286 validate ();
252- return this .service .update (this . headers , this .globalFiledUid , requestBody );
287+ return this .service .update (getRequestHeaders () , this .globalFiledUid , requestBody );
253288 }
254289
255290 /**
@@ -274,7 +309,7 @@ public Call<ResponseBody> update(@NotNull JSONObject requestBody) {
274309 */
275310 public Call <ResponseBody > delete () {
276311 validate ();
277- return this .service .delete (this . headers , this .globalFiledUid );
312+ return this .service .delete (getRequestHeaders () , this .globalFiledUid );
278313 }
279314
280315 /**
@@ -301,7 +336,7 @@ public Call<ResponseBody> delete() {
301336 * @since 0.1.0
302337 */
303338 public Call <ResponseBody > imports (@ NotNull JSONObject body ) {
304- return this .service .imports (this . headers , body );
339+ return this .service .imports (getRequestHeaders () , body );
305340 }
306341
307342 /**
@@ -322,6 +357,36 @@ public Call<ResponseBody> imports(@NotNull JSONObject body) {
322357 */
323358 public Call <ResponseBody > export () {
324359 validate ();
325- return this .service .export (this .headers , this .globalFiledUid );
360+ return this .service .export (getRequestHeaders (), this .globalFiledUid );
361+ }
362+
363+ /**
364+ * <b>Restore a global field </b>
365+ * <p>
366+ * The <b>Restore a global field</b> request allows you to restore the schema of
367+ * a deleted global field.
368+ * <p>
369+ * When executing the API call, in the <b>URI Parameters</b> section, provide
370+ * the unique ID of your global field.
371+ *
372+ * <b>Note:</b> You need to use either the stack's Management Token or the user
373+ * Authtoken (any one is mandatory), along with the stack API key, to make a
374+ * valid Content Management API request.
375+ * Read more about authentication.
376+ *
377+ * @param requestBody the request body
378+ * @return Call
379+ * @see <a href=
380+ * "https://www.contentstack.com/docs/developers/apis/content-management-api/#restore-a-global-field">Restore
381+ * a global
382+ * field
383+ *
384+ * </a>
385+ * @see #addHeader(String, String) to add headers
386+ * @since 0.1.0
387+ */
388+ public Call <ResponseBody > restore (@ NotNull JSONObject requestBody ) {
389+ validate ();
390+ return this .service .restore (getRequestHeaders (), this .globalFiledUid , requestBody );
326391 }
327392}
0 commit comments