Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>cms</artifactId>
<packaging>jar</packaging>
<name>contentstack-management-java</name>
<version>1.0.0-SNAPSHOT</version>
<version>0.1.0-alpha-SNAPSHOT</version>
<description>Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an
API-first approach
</description>
Expand Down Expand Up @@ -164,12 +164,10 @@
<version>1.1.1</version>
<scope>compile</scope>
</dependency>

</dependencies>

<build>
<plugins>

<!--mvn clean install -U -Dmaven.test.failure.ignore=true-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
66 changes: 45 additions & 21 deletions src/main/java/com/contentstack/cms/Contentstack.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
public class Contentstack {

public static final Logger logger = Logger.getLogger(Contentstack.class.getName());
public final Logger logger = Logger.getLogger(Contentstack.class.getName());
protected final String host;
protected final String port;
protected final String version;
Expand All @@ -55,16 +55,16 @@ public class Contentstack {
* <b>Example:</b>
*
* <pre>
* Contentstack client = new Contentstack.Builder().setAuthtoken("authtoken").build();
* User userInstance = client.user();
* Contentstack contentstack = new Contentstack.Builder().setAuthtoken("authtoken").build();
* User userInstance = contentstack.user();
* </pre>
*
* <br>
* <b>OR: </b>
*
* <pre>
* Client client = new Client.Builder().build();
* User userInstance = client.user();
* Contentstack contentstack = new Contentstack.Builder().setAuthtoken("authtoken").build();
* User user = contentstack.user();
* </pre>
* <br>
*
Expand Down Expand Up @@ -106,8 +106,8 @@ public User user() {
* <b>OR</b>
*
* <pre>
* Contentstack client = new Contentstack.Builder().build();
* Response login = client.login("emailId", "password");
* Contentstack contentstack = new Contentstack.Builder().build();
* Response login = contentstack.login("emailId", "password");
* </pre>
* <br>
*
Expand Down Expand Up @@ -156,8 +156,8 @@ public Response<LoginDetails> login(String emailId, String password) throws IOEx
* <b>OR: </b>
*
* <pre>
* Contentstack client = new Contentstack.Builder().build();
* Response login = client.login("emailId", "password");
* Contentstack contentstack = new Contentstack.Builder().build();
* Response login = contentstack.login("emailId", "password");
* </pre>
* <br>
*
Expand All @@ -184,6 +184,7 @@ public Response<LoginDetails> login(String emailId, String password, String tfaT
user = new User(this.instance);
Response<LoginDetails> response = user.login(emailId, password, tfaToken).execute();
setupLoginCredentials(response);
user = new User(this.instance);
return response;
}

Expand All @@ -194,9 +195,9 @@ private void setupLoginCredentials(Response<LoginDetails> loginResponse) throws
this.authtoken = loginResponse.body().getUser().getAuthtoken();
this.interceptor.setAuthtoken(this.authtoken);
} else {
logger.info("logging failed");
assert loginResponse.errorBody() != null;
String errorJsonString = loginResponse.errorBody().string();
logger.info(errorJsonString);
new Gson().fromJson(errorJsonString, Error.class);
}
}
Expand All @@ -207,8 +208,8 @@ private void setupLoginCredentials(Response<LoginDetails> loginResponse) throws
* <b> Example </b>
*
* <pre>
* Contentstack client = new Contentstack.Builder().build();
* User userInstance = client.logout();
* Contentstack contentstack = new Contentstack.Builder().build();
* User user = contentstack.logout();
* </pre>
* <p>
*
Expand All @@ -227,8 +228,8 @@ Response<ResponseBody> logout() throws IOException {
* <b> Example </b>
*
* <pre>
* Contentstack client = new Contentstack.Builder().build();
* User userInstance = client.logoutWithAuthtoken("authtoken");
* Contentstack contentstack = new Contentstack.Builder().build();
* User userInstance = contentstack.logoutWithAuthtoken("authtoken");
* </pre>
* <p>
*
Expand All @@ -254,16 +255,41 @@ Response<ResponseBody> logoutWithAuthtoken(String authtoken) throws IOException
* <b> Example </b>
*
* <pre>
* Contentstack client = new Contentstack.Builder().build();
* Organization org = client.organization();
* Contentstack contentstack = new Contentstack.Builder().build();
* Organization org = contentstack.organization();
* </pre>
*
* @return the organization
*/
public Organization organization() {
if (this.authtoken == null)
throw new IllegalStateException("Please Login to access user instance");
return new Organization(this.instance, this.authtoken);
return new Organization(this.instance);
}


/**
* Organization is the top-level entity in the hierarchy of Contentstack, consisting of stacks and stack resources,
* and users. Organization allows easy management of projects as well as users within the Organization.
*
* <b> Example </b>
*
* @param organizationUid
* The UID of the organization that you want to retrieve
* @return the organization
* <br>
* <b>Example</b>
* <pre>
* Contentstack contentstack = new Contentstack.Builder().build();
* Organization org = contentstack.organization();
* </pre>
*/
public Organization organization(@NotNull String organizationUid) {
if (this.authtoken == null)
throw new IllegalStateException("Please Login to access user instance");
if (organizationUid.isEmpty())
throw new IllegalStateException("organizationUid can not be empty");
return new Organization(this.instance, organizationUid);
}

/**
Expand Down Expand Up @@ -518,17 +544,15 @@ public Contentstack build() {

private void validateClient(Contentstack contentstack) {
String baseUrl = Util.PROTOCOL + "://" + this.hostname + "/" + version + "/";
this.instance = new Retrofit.Builder()
.baseUrl(baseUrl)
this.instance = new Retrofit.Builder().baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient(contentstack, this.retry)).build();
contentstack.instance = this.instance;
}

private OkHttpClient httpClient(Contentstack contentstack, Boolean retryOnFailure) {
this.authInterceptor = contentstack.interceptor = new AuthInterceptor();
return new OkHttpClient.Builder()
.addInterceptor(this.authInterceptor)
return new OkHttpClient.Builder().addInterceptor(this.authInterceptor)
.addInterceptor(logger())
.proxy(this.proxy)
.retryOnConnectionFailure(retryOnFailure)
Expand Down
Loading