1010import java .util .HashMap ;
1111
1212/**
13- * App/Manifest is used for creating/updating/deleting app in your Contentstack organization.
13+ * App/Manifest is used for creating/updating/deleting app in your Contentstack organization.
1414 *
1515 * @author ishaileshmishra
1616 * @version v1.0.0
@@ -22,11 +22,12 @@ public class App {
2222 protected HashMap <String , String > headers ;
2323 protected HashMap <String , Object > params ;
2424 private String appUid ;
25- private Retrofit client ;
25+ private final Retrofit client ;
2626 /**
2727 * Error message for internal uses
2828 */
29- private final String ErrorMessage = "App/Manifest uid is required" ;
29+ private static final String ERROR_MESSAGE = "App/Manifest uid is required" ;
30+ private static final String ORGANIZATION_UID = "organization_uid" ;
3031
3132 /**
3233 * Instantiates a new Organization.
@@ -40,7 +41,7 @@ public App(Retrofit client, @NotNull String organizationUid) {
4041 if (organizationUid .isEmpty ()) {
4142 throw new IllegalArgumentException ("Organization uid could not be empty" );
4243 }
43- this .headers .put ("organization_uid" , organizationUid );
44+ this .headers .put (ORGANIZATION_UID , organizationUid );
4445 this .client = client ;
4546 this .service = this .client .create (AppService .class );
4647 }
@@ -60,7 +61,7 @@ public App(Retrofit client, @NotNull String organizationUid, @NotNull String uid
6061 if (organizationUid .isEmpty ()) {
6162 throw new IllegalArgumentException ("Organization uid could not be empty" );
6263 }
63- this .headers .put ("organization_uid" , organizationUid );
64+ this .headers .put (ORGANIZATION_UID , organizationUid );
6465 this .appUid = uid ;
6566 this .params = new HashMap <>();
6667 this .client = client ;
@@ -69,19 +70,26 @@ public App(Retrofit client, @NotNull String organizationUid, @NotNull String uid
6970
7071 public Installation installation () {
7172 if (this .appUid == null || this .appUid .isEmpty ()) {
72- throw new BadArgumentException (ErrorMessage );
73+ throw new BadArgumentException (ERROR_MESSAGE );
7374 }
74- return new Installation (this .client , this .headers .get ("organization_uid" ), this .appUid );
75+ return new Installation (this .client , this .headers .get (ORGANIZATION_UID ), this .appUid );
76+ }
77+
78+ public Installation installation (@ NotNull String installationId ) {
79+ if (this .appUid == null || this .appUid .isEmpty ()) {
80+ throw new BadArgumentException (ERROR_MESSAGE );
81+ }
82+ return new Installation (this .client , this .headers .get (ORGANIZATION_UID ), this .appUid , installationId );
7583 }
7684
7785 /**
7886 * HTTP header parameters are key-value pairs that are included in the header to provide additional information
7987 * about the request or response:
8088 *
8189 * @param key
82- * header key are being sent in the request
90+ * header key is being sent in the request
8391 * @param value
84- * header value are being sent in the request against to the header key
92+ * header value is being sent in the request against to the header key
8593 */
8694 public App addHeader (@ NotNull String key , @ NotNull String value ) {
8795 this .headers .put (key , value );
@@ -153,7 +161,7 @@ public Call<ResponseBody> fetch(@NotNull String manifestUid) {
153161 }
154162
155163 private void validate () {
156- if (!this .headers .containsKey ("organization_uid" ))
164+ if (!this .headers .containsKey (ORGANIZATION_UID ))
157165 throw new IllegalStateException ("Organization uid can not be null or empty" );
158166 }
159167
@@ -170,7 +178,7 @@ private void isValidJSON(JSONObject body) {
170178 }
171179
172180 /**
173- * The create manifest call is used for creating a new app/manifest in your Contentstack
181+ * To create a new app/manifest in your Contentstack
174182 *
175183 * @param body
176184 * <b>The request body, should contain params like</b>
@@ -216,7 +224,7 @@ public Call<ResponseBody> update(JSONObject body) {
216224 validate ();
217225 isValidJSON (body );
218226 if (this .appUid == null || this .appUid .isEmpty ()) {
219- throw new BadArgumentException (ErrorMessage );
227+ throw new BadArgumentException (ERROR_MESSAGE );
220228 }
221229 return service .updateById (this .headers , this .appUid , body );
222230 }
@@ -237,7 +245,7 @@ public Call<ResponseBody> update(@NotNull String id, JSONObject body) {
237245 public Call <ResponseBody > delete () {
238246 validate ();
239247 if (this .appUid == null || this .appUid .isEmpty ()) {
240- throw new BadArgumentException (ErrorMessage );
248+ throw new BadArgumentException (ERROR_MESSAGE );
241249 }
242250 return service .delete (this .headers , this .appUid );
243251 }
@@ -310,7 +318,7 @@ public Call<ResponseBody> updateOauth(@NotNull String uid, JSONObject body) {
310318 public Call <ResponseBody > updateOauth (JSONObject body ) {
311319 validate ();
312320 if (this .appUid == null || this .appUid .isEmpty ()) {
313- throw new BadArgumentException (ErrorMessage );
321+ throw new BadArgumentException (ERROR_MESSAGE );
314322 }
315323 return service .updateAuthConfiguration (this .headers , this .appUid , body );
316324 }
0 commit comments