diff --git a/.gitignore b/.gitignore
index d15ac82..c0249fb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,6 +18,7 @@
.metadata
bin/
tmp/
+apidoc/
*.tmp
*.bak
*.swp
@@ -198,4 +199,5 @@ dependency-reduced-pom.xml
README.html
*.iml
.idea
-.exercism
\ No newline at end of file
+.exercism
+/apidoc/
diff --git a/README.md b/README.md
index 7566065..b9282ee 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ Before using the **Marketplace** SDK, ensure the following:
1. Java JDK 1.8 or above should be installed on your machine.
2. You have a valid Contentstack account with access to the Contentstack Marketplace.
-3. You have obtained the necessary credentials, including the organization UID, to interact with the Marketplace API.
+3. You have obtained the necessary credentials like **organization UID** and **authtoken**, to interact with the Marketplace API.
## Installation
@@ -16,16 +16,11 @@ To use the Marketplace SDK in your Java project, follow these steps:
1. Download the contentstack-java SDK and its dependencies from the Contentstack Maven repository. Add the following dependencies to your project's pom.xml file:
-```xml
-
-
-
- com.contentstack.sdk
- marketplace
- x.x.x
-
-
-```
+```xml
+
+
+ com.contentstack.sdk marketplace x.x.x
+```
2. Save the pom.xml file.
@@ -33,65 +28,53 @@ To use the Marketplace SDK in your Java project, follow these steps:
## How to Use
-1. Import the required packages:
+1. Initialize the Marketplace class with your organization UID:
-```java
+```java
import com.contentstack.sdk.marketplace.Marketplace;
-import com.contentstack.sdk.marketplace.apps.App;
-import com.contentstack.sdk.marketplace.auths.Auth;
-import com.contentstack.sdk.marketplace.installations.Installation;
-import com.contentstack.sdk.marketplace.request.AppRequest;
-import org.jetbrains.annotations.NotNull;
-import retrofit2.Retrofit;
-```
-
-2. Initialize the Marketplace class with your organization UID:
-
-```java
-// Replace 'YOUR_ORG_ID' with your Contentstack organization UID
-String organizationUid = "YOUR_ORG_ID";
-Marketplace marketplace = new Marketplace(organizationUid);
-```
+Marketplace marketplace = new Marketplace
+ .Builder(TestClient.ORGANIZATION_UID) // Required
+ .host(HOST) // Optional
+ .authtoken("test") // Optional
+ .login("test@email.com", "*********") // Optional
+ .region(Region.AZURE_EU) // Optional
+ .build();
+```
-3. Use the various methods available in the Marketplace class to interact with the Marketplace API:
+2. Use the various methods available in the Marketplace class to interact with the Marketplace API:
### Retrieve an instance of the App class:
-
-```java
-// Get an instance of the App class
-App app = marketplace.app();
-
-// Alternatively, you can pass the app UID to retrieve a specific app
-String appUid = "APP_UID";
-App specificApp = marketplace.app(appUid);
-```
+Get an instance of the App class
+```java
+import com.contentstack.sdk.marketplace.apps.App;
+App app = marketplace.app();
+// Alternatively, you can pass the app UID to retrieve a specific app
+App specificApp = marketplace.app("APP_UID");
+```
### Retrieve an instance of the Auth class:
```java
-// Get an instance of the Auth class
-Auth auth = marketplace.authorizations();
-```
+import com.contentstack.sdk.marketplace.auths.Auth;
+// Get an instance of the Auth class
+Auth auth = marketplace.authorizations();
+```
### Retrieve an instance of the Installation class:
-
+Get an instance of the Installation class
```java
-// Get an instance of the Installation class
-Installation installation = marketplace.installation();
-
-// Alternatively, you can pass the installation ID to retrieve a specific installation
-String installationId = "INSTALLATION_ID";
-Installation specificInstallation = marketplace.installation(installationId);
-```
+import com.contentstack.sdk.marketplace.installations.Installation;
+Installation installation = marketplace.installation();
+OR
+Installation specificInstallation = marketplace.installation("INSTALLATION_ID");
+```
### Create an instance of the AppRequest class:
-
+Get an instance of the AppRequest class
```java
-// Get an instance of the AppRequest class
-AppRequest appRequest = marketplace.request();
-```
-
-**Note:** Replace **YOUR_ORG_ID**, **APP_UID**, and **INSTALLATION_ID** with actual values from your Contentstack organization.
+import com.contentstack.sdk.marketplace.request.AppRequest;
+AppRequest appRequest = marketplace.request();
+```
## License
@@ -102,4 +85,4 @@ Copyright © 2012-2023 [Contentstack](https://www.contentstack.com/). All Rights
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-```
\ No newline at end of file
+```
diff --git a/pom.xml b/pom.xml
index 767912b..6ee6cdc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
4.0.0
com.contentstack.sdk
marketplace
- 1.0-SNAPSHOT
+ 1.0.0
Contentstack Java Management SDK for Content Management API
https://github.com/contentstack/contentstack-management-java/
@@ -14,25 +14,25 @@
9
9
UTF-8
- 2.22.0
- 2.2.1
+ 3.1.2
+ 3.3.0
3.0.0
5.2.2
3.1.6
- 2.7.0
+ 2.9.0
2.9.0
4.10.0
0.8.7
- 1.18.28
- 5.9.2
+ 1.18.30
+ 5.10.0
5.8.0-M1
- 5.9.2
+ 5.10.0
2.10.1
- 3.3
- 1.5
- 3.8.0
+ 4.0.0-M9
+ 3.1.0
+ 3.11.0
1.6.13
- 2.5.3
+ 3.0.1
diff --git a/src/main/java/com/contentstack/sdk/marketplace/Constants.java b/src/main/java/com/contentstack/sdk/marketplace/Constants.java
new file mode 100644
index 0000000..03ca63f
--- /dev/null
+++ b/src/main/java/com/contentstack/sdk/marketplace/Constants.java
@@ -0,0 +1,11 @@
+package com.contentstack.sdk.marketplace;
+
+public class Constants {
+ final public static String ERROR_NO_ORGANIZATION_UID = "Organization uid could not be empty";
+ final public static String DEFAULT_HOST = "developerhub-api.contentstack.com";
+ final public static String MISSING_ORG_ID = "organization uid is required";
+
+
+ final public static String ORGANIZATION_UID = "organization_uid";
+ final public static String AUTHTOKEN = "authtoken";
+}
diff --git a/src/main/java/com/contentstack/sdk/marketplace/Marketplace.java b/src/main/java/com/contentstack/sdk/marketplace/Marketplace.java
index 4129b6b..b1886ff 100644
--- a/src/main/java/com/contentstack/sdk/marketplace/Marketplace.java
+++ b/src/main/java/com/contentstack/sdk/marketplace/Marketplace.java
@@ -6,54 +6,48 @@
import com.contentstack.sdk.marketplace.apps.App;
import com.contentstack.sdk.marketplace.auths.Auth;
import com.contentstack.sdk.marketplace.installations.Installation;
+import com.contentstack.sdk.marketplace.login.LoginModel;
+import com.contentstack.sdk.marketplace.login.LoginService;
import com.contentstack.sdk.marketplace.request.AppRequest;
import org.jetbrains.annotations.NotNull;
+import org.json.simple.JSONObject;
+import retrofit2.Call;
+import retrofit2.Response;
import retrofit2.Retrofit;
+import retrofit2.converter.gson.GsonConverterFactory;
+
+import java.io.IOException;
+import java.util.HashMap;
public class Marketplace {
private final Retrofit client;
- /**
- * The organisation uid to perform operation on marketplace.
- */
protected final String orgId;
private final String host;
- private static final String DEFAULT_HOST = "developerhub-api.contentstack.com";
+ private final String authtoken;
- private Marketplace(String organizationUid, String host, Region region) {
+ private Marketplace(String authtoken, String organizationUid, String host, Region region) {
+ this.authtoken = authtoken;
this.orgId = organizationUid;
if (region != null) {
host = region.name().toLowerCase() + "-" + host;
}
- this.host = host.isEmpty() ? DEFAULT_HOST : host;
+ this.host = host.isEmpty() ? Constants.DEFAULT_HOST : host;
this.client = Client.getInstance(this.host);
}
- /**
- * The type Builder.
- */
-// Builder pattern to construct Marketplace objects
public static class Builder {
private final String orgId;
private String host;
private Region region = null;
+ private String authtoken;
+
- /**
- * Instantiates a new Builder.
- *
- * @param organizationUid The organization UID associated with your Contentstack organization
- *
- * Example
- *
- *
- * Marketplace marketplace = new Marketplace.Builder("ORGANIZATION_UID").build();
- *
- */
public Builder(@NotNull String organizationUid) {
if (organizationUid.isEmpty()) {
- throw new NullPointerException("The organization uid is required");
+ throw new NullPointerException("Empty fields are not allowed");
}
this.orgId = organizationUid;
}
@@ -94,6 +88,18 @@ public Builder region(Region stackRegion) {
return this;
}
+
+ /**
+ * Sets authtoken for marketplaces
+ *
+ * @param authtoken the authtoken
+ * @return the builder
+ */
+ public Builder authtoken(String authtoken) {
+ this.authtoken = authtoken;
+ return this;
+ }
+
/**
* Build marketplace.
*
@@ -107,13 +113,64 @@ public Builder region(Region stackRegion) {
*
*/
public Marketplace build() {
- return new Marketplace(this.orgId, this.host, this.region);
+ return new Marketplace(this.authtoken, this.orgId, this.host, this.region);
}
+
+
+ /**
+ * This method is to generate authtoken for Marketplace
+ *
+ * @param email the email address
+ * @param password the password
+ * @return instance of {@link Builder}
+ */
+ public Builder login(String email, String password) {
+ final String BASE_URL = "https://api.contentstack.io/v3/";
+
+ Retrofit.Builder builder
+ = new Retrofit.Builder()
+ .baseUrl(BASE_URL)
+ .addConverterFactory(GsonConverterFactory.create());
+
+ Retrofit retrofit = builder.build();
+ LoginService service = retrofit.create(LoginService.class);
+ HashMap> userSession = new HashMap<>();
+ userSession.put("user", setCredentials(email, password));
+ JSONObject userDetail = new JSONObject(userSession);
+ Call request = service.login(loginHeader(), userDetail);
+ try {
+ Response response = request.execute();
+ assert response.body() != null;
+ this.authtoken = response.body().getUser().authtoken;
+
+ } catch (IOException e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ return this;
+ }
+
+ private HashMap loginHeader() {
+ HashMap loginHeader = new HashMap<>();
+ loginHeader.put("Content-Type", "application/json");
+ return loginHeader;
+ }
+
+
+ private HashMap setCredentials(@NotNull String... arguments) {
+ HashMap credentials = new HashMap<>();
+ credentials.put("email", arguments[0]);
+ credentials.put("password", arguments[1]);
+ if (arguments.length > 2) {
+ credentials.put("tfa_token", arguments[2]);
+ }
+ return credentials;
+ }
+
}
/**
- * App app.
+ * It provides access of app instance
*
* @return the app instance
*
@@ -127,11 +184,11 @@ public Marketplace build() {
*
*/
public App app() {
- return new App(this.client, this.orgId);
+ return new App(this.client, this.authtoken, this.orgId);
}
/**
- * App app.
+ * It provides access of app instance
*
* @param uid the uid
* @return the app instance
@@ -146,11 +203,11 @@ public App app() {
*
*/
public App app(@NotNull String uid) {
- return new App(this.client, this.orgId, uid);
+ return new App(this.client, this.authtoken, this.orgId, uid);
}
/**
- * Authorizations auth.
+ * It provides access of Auth instance
*
* @return the auth instance
*
@@ -164,11 +221,11 @@ public App app(@NotNull String uid) {
*
*/
public Auth authorizations() {
- return new Auth(this.client, this.orgId);
+ return new Auth(this.client, this.authtoken, this.orgId);
}
/**
- * Installation installation.
+ * It provides access of Installation instance
*
* @return the installation instance
*
@@ -182,11 +239,11 @@ public Auth authorizations() {
*
*/
public Installation installation() {
- return new Installation(this.client, this.orgId);
+ return new Installation(this.client, this.authtoken, this.orgId);
}
/**
- * Installation installation.
+ * It provides access of Installation instance
*
* @param installationId the installation id
* @return the installation instance
@@ -200,11 +257,11 @@ public Installation installation() {
*
*/
public Installation installation(String installationId) {
- return new Installation(this.client, this.orgId, installationId);
+ return new Installation(this.client, this.authtoken, this.orgId, installationId);
}
/**
- * Request app request.
+ * It provides access of AppRequest instance
*
* @return the app request instance
*
@@ -217,6 +274,6 @@ public Installation installation(String installationId) {
*
*/
public AppRequest request() {
- return new AppRequest(this.client, this.orgId);
+ return new AppRequest(this.client, this.authtoken, this.orgId);
}
}
diff --git a/src/main/java/com/contentstack/sdk/marketplace/apps/App.java b/src/main/java/com/contentstack/sdk/marketplace/apps/App.java
index 603443b..8869216 100644
--- a/src/main/java/com/contentstack/sdk/marketplace/apps/App.java
+++ b/src/main/java/com/contentstack/sdk/marketplace/apps/App.java
@@ -1,6 +1,7 @@
package com.contentstack.sdk.marketplace.apps;
import com.contentstack.sdk.BaseImplementation;
+import com.contentstack.sdk.marketplace.Constants;
import com.contentstack.sdk.marketplace.apps.hosting.Hosting;
import com.contentstack.sdk.marketplace.apps.oauth.Oauth;
import okhttp3.ResponseBody;
@@ -12,6 +13,9 @@
import java.util.HashMap;
import java.util.Objects;
+import static com.contentstack.sdk.marketplace.Constants.ERROR_NO_ORGANIZATION_UID;
+
+
/**
* App/Manifest is used for creating/updating/deleting app in your Contentstack
* organization.
@@ -27,8 +31,6 @@ public class App implements BaseImplementation {
protected HashMap params;
private String appUid;
private final Retrofit client;
- private final static String ORGANIZATION_UID = "organization_uid";
- private final static String ERROR_NO_ORGANIZATION_UID = "Organization uid could not be empty";
/**
* Instantiates a new Organization.
@@ -46,12 +48,15 @@ public class App implements BaseImplementation {
* App app = marketplace.app();
*
*/
- public App(Retrofit client, @NotNull String organizationUid) {
+ public App(Retrofit client, String authtoken, @NotNull String organizationUid) {
this.client = client;
this.headers = new HashMap<>();
this.params = new HashMap<>();
- Objects.requireNonNull(organizationUid, ERROR_NO_ORGANIZATION_UID);
- this.headers.put(ORGANIZATION_UID, organizationUid);
+ Objects.requireNonNull(organizationUid, Constants.ERROR_NO_ORGANIZATION_UID);
+ this.headers.put(Constants.ORGANIZATION_UID, organizationUid);
+ if (authtoken != null) {
+ this.headers.put(Constants.AUTHTOKEN, authtoken);
+ }
this.service = client.create(AppService.class);
}
@@ -72,12 +77,15 @@ public App(Retrofit client, @NotNull String organizationUid) {
* App app = marketplace.app();
*
*/
- public App(Retrofit client, @NotNull String organizationUid, @NotNull String uid) {
+ public App(Retrofit client, String authtoken, @NotNull String organizationUid, @NotNull String uid) {
this.client = client;
this.headers = new HashMap<>();
this.params = new HashMap<>();
Objects.requireNonNull(organizationUid, ERROR_NO_ORGANIZATION_UID);
- this.headers.put(ORGANIZATION_UID, organizationUid);
+ this.headers.put(Constants.ORGANIZATION_UID, organizationUid);
+ if (authtoken != null) {
+ this.headers.put(Constants.AUTHTOKEN, authtoken);
+ }
Objects.requireNonNull(uid, "Manifest uid is required");
this.appUid = uid;
this.service = client.create(AppService.class);
@@ -401,7 +409,7 @@ public Call findAppRequests() {
*
*/
public Oauth oauth() {
- String orgId = this.headers.get(ORGANIZATION_UID);
+ String orgId = this.headers.get(Constants.ORGANIZATION_UID);
return new Oauth(this.client, orgId);
}
@@ -420,7 +428,7 @@ public Oauth oauth() {
*
*/
public Oauth oauth(@NotNull String id) {
- String orgId = this.headers.get(ORGANIZATION_UID);
+ String orgId = this.headers.get(Constants.ORGANIZATION_UID);
return new Oauth(this.client, orgId, id);
}
@@ -438,7 +446,7 @@ public Oauth oauth(@NotNull String id) {
*
*/
public Hosting hosting() {
- String orgId = this.headers.get(ORGANIZATION_UID);
+ String orgId = this.headers.get(Constants.ORGANIZATION_UID);
return new Hosting(this.client, orgId, this.appUid);
}
@@ -457,7 +465,7 @@ public Hosting hosting() {
*
*/
public Hosting hosting(@NotNull String appId) {
- String orgId = this.headers.get(ORGANIZATION_UID);
+ String orgId = this.headers.get(Constants.ORGANIZATION_UID);
return new Hosting(this.client, orgId, appId);
}
diff --git a/src/main/java/com/contentstack/sdk/marketplace/auths/Auth.java b/src/main/java/com/contentstack/sdk/marketplace/auths/Auth.java
index ca1e810..c65fff6 100644
--- a/src/main/java/com/contentstack/sdk/marketplace/auths/Auth.java
+++ b/src/main/java/com/contentstack/sdk/marketplace/auths/Auth.java
@@ -1,6 +1,7 @@
package com.contentstack.sdk.marketplace.auths;
import com.contentstack.sdk.BaseImplementation;
+import com.contentstack.sdk.marketplace.Constants;
import okhttp3.ResponseBody;
import org.jetbrains.annotations.NotNull;
import retrofit2.Call;
@@ -29,11 +30,14 @@ public class Auth implements BaseImplementation {
* @param clientInstance the client instance
* @param organizationUid the organization uid
*/
- public Auth(Retrofit clientInstance, String organizationUid) {
+ public Auth(Retrofit clientInstance, String authtoken, String organizationUid) {
this.headers = new HashMap<>();
this.params = new HashMap<>();
Objects.requireNonNull(organizationUid, "Organization uid could not be empty");
- this.headers.put("organization_uid", organizationUid);
+ this.headers.put(Constants.ORGANIZATION_UID, organizationUid);
+ if (authtoken != null) {
+ this.headers.put(Constants.AUTHTOKEN, authtoken);
+ }
this.service = clientInstance.create(AuthService.class);
}
diff --git a/src/main/java/com/contentstack/sdk/marketplace/installations/Installation.java b/src/main/java/com/contentstack/sdk/marketplace/installations/Installation.java
index 13c872f..bca68ed 100644
--- a/src/main/java/com/contentstack/sdk/marketplace/installations/Installation.java
+++ b/src/main/java/com/contentstack/sdk/marketplace/installations/Installation.java
@@ -1,6 +1,7 @@
package com.contentstack.sdk.marketplace.installations;
import com.contentstack.sdk.BaseImplementation;
+import com.contentstack.sdk.marketplace.Constants;
import com.contentstack.sdk.marketplace.installations.location.Location;
import com.contentstack.sdk.marketplace.installations.webhook.Webhook;
import okhttp3.ResponseBody;
@@ -19,7 +20,6 @@ public class Installation implements BaseImplementation {
/**
* The Missing org id.
*/
- public final String MISSING_ORG_ID = "organization uid is required";
private String installationId;
private String organisationId;
private InstallationService service;
@@ -45,9 +45,9 @@ public class Installation implements BaseImplementation {
// installationId)` is a constructor for the `Installation` class. It takes
// three parameters: `client`,
// `organisationId`, and `installationId`.
- public Installation(Retrofit client, @NotNull String organisationId, @NotNull String installationId) {
+ public Installation(Retrofit client, String authtoken, @NotNull String organisationId, @NotNull String installationId) {
checkOrganisationId(organisationId);
- init(client, organisationId, installationId);
+ init(client, authtoken, organisationId, installationId);
}
/**
@@ -58,7 +58,7 @@ public Installation(Retrofit client, @NotNull String organisationId, @NotNull St
*/
protected void checkOrganisationId(String organisationId) {
if (organisationId.isEmpty()) {
- throw new NullPointerException(MISSING_ORG_ID);
+ throw new NullPointerException(Constants.MISSING_ORG_ID);
}
}
@@ -87,9 +87,9 @@ protected void validateInstallationId(String installationId) {
* Installation installation = marketplace.installation();
*
*/
- public Installation(@NotNull Retrofit client, @NotNull String organisationId) {
+ public Installation(@NotNull Retrofit client, String authtoken, @NotNull String organisationId) {
checkOrganisationId(organisationId);
- init(client, organisationId, null);
+ init(client, authtoken, organisationId, null);
}
/**
@@ -107,13 +107,16 @@ public Installation(@NotNull Retrofit client, @NotNull String organisationId) {
* represents the unique identifier
* for an installation.
*/
- private void init(Retrofit client, @NotNull String organisationId, String installationId) {
+ private void init(Retrofit client, String authtoken, @NotNull String organisationId, String installationId) {
this.headers = new HashMap<>();
this.params = new HashMap<>();
this.installationId = installationId;
this.organisationId = organisationId;
this.client = client;
- this.headers.put("organization_uid", organisationId);
+ this.headers.put(Constants.ORGANIZATION_UID, organisationId);
+ if (authtoken != null) {
+ this.headers.put(Constants.AUTHTOKEN, authtoken);
+ }
this.service = this.client.create(InstallationService.class);
}
diff --git a/src/main/java/com/contentstack/sdk/marketplace/installations/InstallationService.java b/src/main/java/com/contentstack/sdk/marketplace/installations/InstallationService.java
index 1859516..30a1ee7 100644
--- a/src/main/java/com/contentstack/sdk/marketplace/installations/InstallationService.java
+++ b/src/main/java/com/contentstack/sdk/marketplace/installations/InstallationService.java
@@ -20,9 +20,9 @@ public interface InstallationService {
* @return the call
*/
@GET("installations/view/apps")
- Call listInstalledApps(
- @HeaderMap Map headers,
- @QueryMap Map queryParams);
+ Call listInstalledApps(
+ @HeaderMap Map headers,
+ @QueryMap Map queryParams);
/**
* List installations call.
@@ -32,9 +32,9 @@ Call listInstalledApps(
* @return the call
*/
@GET("installations")
- Call listInstallations(
- @HeaderMap Map headers,
- @QueryMap Map queryParams);
+ Call listInstallations(
+ @HeaderMap Map headers,
+ @QueryMap Map queryParams);
/**
* Gets installations.
@@ -45,10 +45,10 @@ Call listInstallations(
* @return the installations
*/
@GET("installations/{id}")
- Call getInstallations(
- @HeaderMap Map headers,
- @Path("id") String id,
- @QueryMap Map queryParams);
+ Call getInstallations(
+ @HeaderMap Map headers,
+ @Path("id") String id,
+ @QueryMap Map queryParams);
/**
* Gets installation data.
@@ -59,10 +59,10 @@ Call getInstallations(
* @return the installation data
*/
@GET("installations/{id}/installationData")
- Call getInstallationData(
- @HeaderMap Map headers,
- @Path("id") String id,
- @QueryMap Map queryParams);
+ Call getInstallationData(
+ @HeaderMap Map headers,
+ @Path("id") String id,
+ @QueryMap Map queryParams);
/**
* Update installation call.
@@ -74,11 +74,11 @@ Call getInstallationData(
* @return the call
*/
@PUT("installations/{id}")
- Call updateInstallation(
- @HeaderMap Map headers,
- @Path("id") String id,
- @Body JSONObject requestBody,
- @QueryMap Map queryParams);
+ Call updateInstallation(
+ @HeaderMap Map headers,
+ @Path("id") String id,
+ @Body JSONObject requestBody,
+ @QueryMap Map queryParams);
/**
* List installed users call.
@@ -88,9 +88,9 @@ Call updateInstallation(
* @return the call
*/
@GET("installations/view/users")
- Call listInstalledUsers(
- @HeaderMap Map headers,
- @QueryMap Map queryParams);
+ Call listInstalledUsers(
+ @HeaderMap Map headers,
+ @QueryMap Map queryParams);
/**
* List installed stacks call.
@@ -100,9 +100,9 @@ Call listInstalledUsers(
* @return the call
*/
@GET("installations/view/stacks")
- Call listInstalledStacks(
- @HeaderMap Map headers,
- @QueryMap Map queryParams);
+ Call listInstalledStacks(
+ @HeaderMap Map headers,
+ @QueryMap Map queryParams);
/**
* Uninstall call.
@@ -112,9 +112,9 @@ Call listInstalledStacks(
* @return the call
*/
@DELETE("installations/{id}")
- Call uninstall(
- @HeaderMap Map headers,
- @Path("id") String id);
+ Call uninstall(
+ @HeaderMap Map headers,
+ @Path("id") String id);
/**
* Gets app configuration.
@@ -125,10 +125,10 @@ Call uninstall(
* @return the app configuration
*/
@GET("installations/{id}/configuration")
- Call getAppConfiguration(
- @HeaderMap Map headers,
- @Path("id") String id,
- @QueryMap Map queryParams);
+ Call getAppConfiguration(
+ @HeaderMap Map headers,
+ @Path("id") String id,
+ @QueryMap Map queryParams);
/**
* Gets server configuration.
@@ -139,10 +139,10 @@ Call getAppConfiguration(
* @return the server configuration
*/
@GET("installations/{id}/server-configuration")
- Call getServerConfiguration(
- @HeaderMap Map headers,
- @Path("id") String id,
- @QueryMap Map queryParams);
+ Call getServerConfiguration(
+ @HeaderMap Map headers,
+ @Path("id") String id,
+ @QueryMap Map queryParams);
/**
* Update server configuration call.
@@ -154,11 +154,11 @@ Call getServerConfiguration(
* @return the call
*/
@PUT("installations/{id}/server-configuration")
- Call updateServerConfiguration(
- @HeaderMap Map headers,
- @Path("id") String id,
- @Body JSONObject body,
- @QueryMap Map queryParams);
+ Call updateServerConfiguration(
+ @HeaderMap Map headers,
+ @Path("id") String id,
+ @Body JSONObject body,
+ @QueryMap Map queryParams);
/**
* Update stack configuration call.
@@ -170,11 +170,11 @@ Call updateServerConfiguration(
* @return the call
*/
@PUT("installations/{id}/configuration")
- Call updateStackConfiguration(
- @HeaderMap Map headers,
- @Path("id") String id,
- @Body JSONObject body,
- @QueryMap Map queryParams);
+ Call updateStackConfiguration(
+ @HeaderMap Map headers,
+ @Path("id") String id,
+ @Body JSONObject body,
+ @QueryMap Map queryParams);
/**
* Create installation token call.
@@ -185,9 +185,9 @@ Call updateStackConfiguration(
* @return the call
*/
@POST("installations/{id}/token")
- Call createInstallationToken(
- @HeaderMap Map headers,
- @Path("id") String id,
- @QueryMap Map queryParams);
+ Call createInstallationToken(
+ @HeaderMap Map headers,
+ @Path("id") String id,
+ @QueryMap Map queryParams);
}
diff --git a/src/main/java/com/contentstack/sdk/marketplace/installations/location/Location.java b/src/main/java/com/contentstack/sdk/marketplace/installations/location/Location.java
index 94d3589..2668070 100644
--- a/src/main/java/com/contentstack/sdk/marketplace/installations/location/Location.java
+++ b/src/main/java/com/contentstack/sdk/marketplace/installations/location/Location.java
@@ -9,9 +9,7 @@
import java.util.HashMap;
import java.util.Objects;
-/**
- * The type Location.
- */
+
public class Location implements BaseImplementation {
private final String installationId;
@@ -79,15 +77,15 @@ Call fetchConfigurationLocation() {
* @return a new {@link Location} object with the specified header added
* @throws NullPointerException if the key or value argument is null
*
- *
- * Example
- *
- *
- * Marketplace marketplace = new Marketplace.Builder("organizationId")
- * .host("api.contentstack.io").build();
- * Location location = marketplace.installation().location();
- * Location result = location.addParam("key", "value")
- *
+ *
+ * Example
+ *
+ *
+ * Marketplace marketplace = new Marketplace.Builder("organizationId")
+ * .host("api.contentstack.io").build();
+ * Location location = marketplace.installation().location();
+ * Location result = location.addParam("key", "value")
+ *
*/
@Override
public Location addParam(@NotNull String key, @NotNull Object value) {
@@ -104,15 +102,15 @@ public Location addParam(@NotNull String key, @NotNull Object value) {
* @return a new {@link Location} object with the specified header added
* @throws NullPointerException if the key or value argument is null
*
- *
- * Example
- *
- *
- * Marketplace marketplace = new Marketplace.Builder("organizationId")
- * .host("api.contentstack.io").build();
- * Location location = marketplace.installation().location();
- * Location result = location.addHeader("key", "value")
- *
+ *
+ * Example
+ *
+ *
+ * Marketplace marketplace = new Marketplace.Builder("organizationId")
+ * .host("api.contentstack.io").build();
+ * Location location = marketplace.installation().location();
+ * Location result = location.addHeader("key", "value")
+ *
*/
@Override
public Location addHeader(@NotNull String key, @NotNull String value) {
@@ -128,16 +126,16 @@ public Location addHeader(@NotNull String key, @NotNull String value) {
* @return a new {@link Location} object with the specified parameters added
* @throws NullPointerException if the params argument is null
*
- *
- * Example
- *
- *
- * Marketplace marketplace = new Marketplace.Builder("organizationId")
- * .host("api.contentstack.io").build();
- * Location location = marketplace.installation().location();
- * HashMap map = new HashMap();
- * Location result = location.addParams(map)
- *
+ *
+ * Example
+ *
+ *
+ * Marketplace marketplace = new Marketplace.Builder("organizationId")
+ * .host("api.contentstack.io").build();
+ * Location location = marketplace.installation().location();
+ * HashMap map = new HashMap();
+ * Location result = location.addParams(map)
+ *
*/
@Override
public Location addParams(@NotNull HashMap params) {
@@ -153,16 +151,16 @@ public Location addParams(@NotNull HashMap params) {
* @return a new {@link Location} object with the specified parameters added
* @throws NullPointerException if the params argument is null
*
- *
- * Example
- *
- *
- * Marketplace marketplace = new Marketplace.Builder("organizationId")
- * .host("api.contentstack.io").build();
- * Location location = marketplace.installation().location();
- * HashMap map = new HashMap();
- * Location result = location.addHeaders(map)
- *
+ *
+ * Example
+ *
+ *
+ * Marketplace marketplace = new Marketplace.Builder("organizationId")
+ * .host("api.contentstack.io").build();
+ * Location location = marketplace.installation().location();
+ * HashMap map = new HashMap();
+ * Location result = location.addHeaders(map)
+ *
*/
@Override
public Location addHeaders(@NotNull HashMap headers) {
diff --git a/src/main/java/com/contentstack/sdk/marketplace/installations/location/LocationService.java b/src/main/java/com/contentstack/sdk/marketplace/installations/location/LocationService.java
index 4ba89cd..f642039 100644
--- a/src/main/java/com/contentstack/sdk/marketplace/installations/location/LocationService.java
+++ b/src/main/java/com/contentstack/sdk/marketplace/installations/location/LocationService.java
@@ -9,9 +9,7 @@
import java.util.Map;
-/**
- * The interface Location service.
- */
+
public interface LocationService {
/**
diff --git a/src/main/java/com/contentstack/sdk/marketplace/installations/webhook/WebhookService.java b/src/main/java/com/contentstack/sdk/marketplace/installations/webhook/WebhookService.java
index 48d555e..af75117 100644
--- a/src/main/java/com/contentstack/sdk/marketplace/installations/webhook/WebhookService.java
+++ b/src/main/java/com/contentstack/sdk/marketplace/installations/webhook/WebhookService.java
@@ -21,11 +21,11 @@ public interface WebhookService {
* @return the call
*/
@GET("installations/{installationId}/webhooks/{webhookId}/executions")
- Call findExecutionLogs(
- @HeaderMap Map headers,
- @Path("installationId") String installationId,
- @Path("webhookId") String webhookId,
- @QueryMap Map queryParams);
+ Call findExecutionLogs(
+ @HeaderMap Map headers,
+ @Path("installationId") String installationId,
+ @Path("webhookId") String webhookId,
+ @QueryMap Map queryParams);
/**
* Fetch execution log call.
@@ -38,12 +38,12 @@ Call findExecutionLogs(
* @return the call
*/
@GET("/installations/{installationId}/webhooks/{webhookId}/executions/{executionId}")
- Call fetchExecutionLog(
- @HeaderMap Map headers,
- @Path("installationId") String installationId,
- @Path("webhookId") String webhookId,
- @Path("executionId") String executionId,
- @QueryMap Map queryParams);
+ Call fetchExecutionLog(
+ @HeaderMap Map headers,
+ @Path("installationId") String installationId,
+ @Path("webhookId") String webhookId,
+ @Path("executionId") String executionId,
+ @QueryMap Map queryParams);
/**
* Retry execution call.
@@ -56,10 +56,10 @@ Call fetchExecutionLog(
* @return the call
*/
@POST("/installations/{installationId}/webhooks/{webhookId}/executions/{executionId}/retry")
- Call retryExecution(
- @HeaderMap Map headers,
- @Path("installationId") String installationId,
- @Path("webhookId") String webhookId,
- @Path("executionId") String executionId,
- @QueryMap Map queryParams);
+ Call retryExecution(
+ @HeaderMap Map headers,
+ @Path("installationId") String installationId,
+ @Path("webhookId") String webhookId,
+ @Path("executionId") String executionId,
+ @QueryMap Map queryParams);
}
diff --git a/src/main/java/com/contentstack/sdk/marketplace/login/LoginModel.java b/src/main/java/com/contentstack/sdk/marketplace/login/LoginModel.java
new file mode 100644
index 0000000..ac168fe
--- /dev/null
+++ b/src/main/java/com/contentstack/sdk/marketplace/login/LoginModel.java
@@ -0,0 +1,19 @@
+package com.contentstack.sdk.marketplace.login;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@NoArgsConstructor
+@Getter
+@Setter
+public class LoginModel {
+
+ @SerializedName("notice")
+ public String notice;
+ @SerializedName("user")
+ public UserModel user;
+}
+
+
diff --git a/src/main/java/com/contentstack/sdk/marketplace/login/LoginService.java b/src/main/java/com/contentstack/sdk/marketplace/login/LoginService.java
new file mode 100644
index 0000000..2c48ac3
--- /dev/null
+++ b/src/main/java/com/contentstack/sdk/marketplace/login/LoginService.java
@@ -0,0 +1,15 @@
+package com.contentstack.sdk.marketplace.login;
+
+import org.json.simple.JSONObject;
+import retrofit2.Call;
+import retrofit2.http.Body;
+import retrofit2.http.HeaderMap;
+import retrofit2.http.POST;
+
+import java.util.Map;
+
+public interface LoginService {
+
+ @POST("user-session")
+ Call login(@HeaderMap Map headers, @Body JSONObject body);
+}
diff --git a/src/main/java/com/contentstack/sdk/marketplace/login/UserModel.java b/src/main/java/com/contentstack/sdk/marketplace/login/UserModel.java
new file mode 100644
index 0000000..52f61d3
--- /dev/null
+++ b/src/main/java/com/contentstack/sdk/marketplace/login/UserModel.java
@@ -0,0 +1,53 @@
+package com.contentstack.sdk.marketplace.login;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@NoArgsConstructor
+@Getter
+@Setter
+public class UserModel {
+
+ @SerializedName("uid")
+ public String uid;
+
+ @SerializedName("created_at")
+ public String createdAt;
+
+ @SerializedName("updated_at")
+ public String updatedAt;
+
+ @SerializedName("email")
+ public String email;
+
+ @SerializedName("username")
+ public String username;
+
+ @SerializedName("first_name")
+ public String firstName;
+
+ @SerializedName("last_name")
+ public String lastName;
+
+ @SerializedName("company")
+ public String company;
+
+ @SerializedName("org_uid")
+ public String[] orgUid;
+
+ @SerializedName("shared_org_uid")
+ public String[] sharedOrgUid;
+
+ @SerializedName("active")
+ public boolean active;
+
+ @SerializedName("authtoken")
+ public String authtoken;
+
+ @SerializedName("profile_type")
+ public String profileType;
+
+
+}
diff --git a/src/main/java/com/contentstack/sdk/marketplace/request/AppRequest.java b/src/main/java/com/contentstack/sdk/marketplace/request/AppRequest.java
index 7262e5f..09d590e 100644
--- a/src/main/java/com/contentstack/sdk/marketplace/request/AppRequest.java
+++ b/src/main/java/com/contentstack/sdk/marketplace/request/AppRequest.java
@@ -1,6 +1,7 @@
package com.contentstack.sdk.marketplace.request;
import com.contentstack.sdk.BaseImplementation;
+import com.contentstack.sdk.marketplace.Constants;
import okhttp3.ResponseBody;
import org.jetbrains.annotations.NotNull;
import org.json.simple.JSONObject;
@@ -25,10 +26,13 @@ public class AppRequest implements BaseImplementation {
* @param client the client
* @param orgId the org id
*/
- public AppRequest(@NotNull Retrofit client, @NotNull String orgId) {
+ public AppRequest(@NotNull Retrofit client, String authtoken, @NotNull String orgId) {
this.service = client.create(RequestService.class);
this.headers = new HashMap<>();
- this.headers.put("organization_uid", orgId);
+ this.headers.put(Constants.ORGANIZATION_UID, orgId);
+ if (authtoken != null) {
+ this.headers.put(Constants.AUTHTOKEN, authtoken);
+ }
this.params = new HashMap<>();
}
diff --git a/src/main/java/com/contentstack/sdk/marketplace/request/RequestService.java b/src/main/java/com/contentstack/sdk/marketplace/request/RequestService.java
index 225da55..8827bea 100644
--- a/src/main/java/com/contentstack/sdk/marketplace/request/RequestService.java
+++ b/src/main/java/com/contentstack/sdk/marketplace/request/RequestService.java
@@ -20,9 +20,9 @@ public interface RequestService {
* @return the call
*/
@POST("requests")
- Call create(
- @HeaderMap Map headers,
- @Body JSONObject body);
+ Call create(
+ @HeaderMap Map headers,
+ @Body JSONObject body);
/**
* List requests call.
@@ -32,9 +32,9 @@ Call create(
* @return the call
*/
@GET("requests")
- Call listRequests(
- @HeaderMap Map headers,
- @QueryMap Map parameters);
+ Call listRequests(
+ @HeaderMap Map headers,
+ @QueryMap Map parameters);
/**
* List requested stacks call.
@@ -44,9 +44,9 @@ Call listRequests(
* @return the call
*/
@GET("requests/view/stacks")
- Call listRequestedStacks(
- @HeaderMap Map headers,
- @QueryMap Map parameters);
+ Call listRequestedStacks(
+ @HeaderMap Map headers,
+ @QueryMap Map parameters);
/**
* Delete request call.
@@ -56,7 +56,7 @@ Call listRequestedStacks(
* @return the call
*/
@DELETE("requests/{uid}")
- Call deleteRequest(
- @HeaderMap Map headers,
- @Path("uid") String uid);
+ Call deleteRequest(
+ @HeaderMap Map headers,
+ @Path("uid") String uid);
}
diff --git a/src/test/java/com/contentstack/sdk/TestClient.java b/src/test/java/com/contentstack/sdk/TestClient.java
index f158324..760b619 100644
--- a/src/test/java/com/contentstack/sdk/TestClient.java
+++ b/src/test/java/com/contentstack/sdk/TestClient.java
@@ -47,5 +47,16 @@ public static Marketplace getMarketplaceAzureEu() {
.build();
}
+
+ public static Marketplace getMarketplaceWithLogin() {
+ return new Marketplace
+ .Builder(TestClient.ORGANIZATION_UID)
+ .host(HOST)
+ .authtoken("test")
+ .login("test@email.com", "************")
+ .region(Region.AZURE_EU)
+ .build();
+ }
+
}
diff --git a/src/test/java/com/contentstack/sdk/marketplace/MarketplaceTest.java b/src/test/java/com/contentstack/sdk/marketplace/MarketplaceTest.java
index aaabe59..dd1c499 100644
--- a/src/test/java/com/contentstack/sdk/marketplace/MarketplaceTest.java
+++ b/src/test/java/com/contentstack/sdk/marketplace/MarketplaceTest.java
@@ -23,13 +23,20 @@ static void setUp() {
}
+// @Test
+// void loginTest() {
+// Marketplace resp = TestClient.getMarketplaceWithLogin();
+// resp.app("login");
+// System.out.println(resp);
+// }
+
@Test
void testConstructorWithNullOrganizationUidAndWithValidHost() {
// Arrange
//String organizationUid = "nullOrganizationUid123";
String organizationUid = null;
String host = "developerhub-api.contentstack.com";
- assertThrows(NullPointerException.class, () -> new Marketplace.Builder(organizationUid)
+ assertThrows(IllegalArgumentException.class, () -> new Marketplace.Builder(organizationUid)
.host(host)
.build());
}
@@ -39,7 +46,7 @@ void testConstructorWithNullOrganizationUidAndWithBlankString() {
// Arrange
String organizationUid = "";
String host = "example.com"; // Provide a valid host or default host for this test
- assertThrows(NullPointerException.class, () -> new Marketplace.Builder(organizationUid)
+ assertThrows(NullPointerException.class, () -> new Marketplace.Builder(organizationUid)
.host(host)
.build());
}
@@ -48,7 +55,7 @@ void testConstructorWithNullOrganizationUidAndWithBlankString() {
void testConstructorWithNullOrganizationUid() {
// Arrange
String organizationUid = "";
- assertThrows(NullPointerException.class, () -> new Marketplace.Builder(organizationUid)
+ assertThrows(NullPointerException.class, () -> new Marketplace.Builder(organizationUid)
.build());
}
@@ -56,7 +63,7 @@ void testConstructorWithNullOrganizationUid() {
void testConstructorWithNullOrganizationUidNullCheck() {
// Arrange
String organizationUid = null;
- assertThrows(NullPointerException.class, () -> new Marketplace.Builder(organizationUid)
+ assertThrows(IllegalArgumentException.class, () -> new Marketplace.Builder(organizationUid)
.build());
}
@@ -99,4 +106,13 @@ void testRegion() {
.build();
Assertions.assertNotNull(marketplace);
}
+
+ @Test
+ void testMarketplaceLogin() {
+ Marketplace marketplace = new Marketplace.Builder("organizationId")
+ .host("api.contentstack.com").region(Region.AZURE_NA)
+ .build();
+ Assertions.assertNotNull(marketplace);
+ }
+
}