Skip to content

Commit 0a72b5d

Browse files
updated constructors - v0.1.0-alpha
1 parent 03bf4ea commit 0a72b5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2540
-2381
lines changed

pom.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<artifactId>cms</artifactId>
77
<packaging>jar</packaging>
88
<name>contentstack-management-java</name>
9-
<version>1.0.0-a1-SNAPSHOT</version>
9+
<version>0.1.0-alpha-SNAPSHOT</version>
1010
<description>Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an
1111
API-first approach
1212
</description>
@@ -164,12 +164,10 @@
164164
<version>1.1.1</version>
165165
<scope>compile</scope>
166166
</dependency>
167-
168167
</dependencies>
169168

170169
<build>
171170
<plugins>
172-
173171
<!--mvn clean install -U -Dmaven.test.failure.ignore=true-->
174172
<plugin>
175173
<groupId>org.apache.maven.plugins</groupId>

src/main/java/com/contentstack/cms/Contentstack.java

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
public class Contentstack {
3636

37-
public static final Logger logger = Logger.getLogger(Contentstack.class.getName());
37+
public final Logger logger = Logger.getLogger(Contentstack.class.getName());
3838
protected final String host;
3939
protected final String port;
4040
protected final String version;
@@ -55,16 +55,16 @@ public class Contentstack {
5555
* <b>Example:</b>
5656
*
5757
* <pre>
58-
* Contentstack client = new Contentstack.Builder().setAuthtoken("authtoken").build();
59-
* User userInstance = client.user();
58+
* Contentstack contentstack = new Contentstack.Builder().setAuthtoken("authtoken").build();
59+
* User userInstance = contentstack.user();
6060
* </pre>
6161
*
6262
* <br>
6363
* <b>OR: </b>
6464
*
6565
* <pre>
66-
* Client client = new Client.Builder().build();
67-
* User userInstance = client.user();
66+
* Contentstack contentstack = new Contentstack.Builder().setAuthtoken("authtoken").build();
67+
* User user = contentstack.user();
6868
* </pre>
6969
* <br>
7070
*
@@ -106,8 +106,8 @@ public User user() {
106106
* <b>OR</b>
107107
*
108108
* <pre>
109-
* Contentstack client = new Contentstack.Builder().build();
110-
* Response login = client.login("emailId", "password");
109+
* Contentstack contentstack = new Contentstack.Builder().build();
110+
* Response login = contentstack.login("emailId", "password");
111111
* </pre>
112112
* <br>
113113
*
@@ -156,8 +156,8 @@ public Response<LoginDetails> login(String emailId, String password) throws IOEx
156156
* <b>OR: </b>
157157
*
158158
* <pre>
159-
* Contentstack client = new Contentstack.Builder().build();
160-
* Response login = client.login("emailId", "password");
159+
* Contentstack contentstack = new Contentstack.Builder().build();
160+
* Response login = contentstack.login("emailId", "password");
161161
* </pre>
162162
* <br>
163163
*
@@ -184,6 +184,7 @@ public Response<LoginDetails> login(String emailId, String password, String tfaT
184184
user = new User(this.instance);
185185
Response<LoginDetails> response = user.login(emailId, password, tfaToken).execute();
186186
setupLoginCredentials(response);
187+
user = new User(this.instance);
187188
return response;
188189
}
189190

@@ -194,9 +195,9 @@ private void setupLoginCredentials(Response<LoginDetails> loginResponse) throws
194195
this.authtoken = loginResponse.body().getUser().getAuthtoken();
195196
this.interceptor.setAuthtoken(this.authtoken);
196197
} else {
197-
logger.info("logging failed");
198198
assert loginResponse.errorBody() != null;
199199
String errorJsonString = loginResponse.errorBody().string();
200+
logger.info(errorJsonString);
200201
new Gson().fromJson(errorJsonString, Error.class);
201202
}
202203
}
@@ -207,8 +208,8 @@ private void setupLoginCredentials(Response<LoginDetails> loginResponse) throws
207208
* <b> Example </b>
208209
*
209210
* <pre>
210-
* Contentstack client = new Contentstack.Builder().build();
211-
* User userInstance = client.logout();
211+
* Contentstack contentstack = new Contentstack.Builder().build();
212+
* User user = contentstack.logout();
212213
* </pre>
213214
* <p>
214215
*
@@ -227,8 +228,8 @@ Response<ResponseBody> logout() throws IOException {
227228
* <b> Example </b>
228229
*
229230
* <pre>
230-
* Contentstack client = new Contentstack.Builder().build();
231-
* User userInstance = client.logoutWithAuthtoken("authtoken");
231+
* Contentstack contentstack = new Contentstack.Builder().build();
232+
* User userInstance = contentstack.logoutWithAuthtoken("authtoken");
232233
* </pre>
233234
* <p>
234235
*
@@ -254,16 +255,41 @@ Response<ResponseBody> logoutWithAuthtoken(String authtoken) throws IOException
254255
* <b> Example </b>
255256
*
256257
* <pre>
257-
* Contentstack client = new Contentstack.Builder().build();
258-
* Organization org = client.organization();
258+
* Contentstack contentstack = new Contentstack.Builder().build();
259+
* Organization org = contentstack.organization();
259260
* </pre>
260261
*
261262
* @return the organization
262263
*/
263264
public Organization organization() {
264265
if (this.authtoken == null)
265266
throw new IllegalStateException("Please Login to access user instance");
266-
return new Organization(this.instance, this.authtoken);
267+
return new Organization(this.instance);
268+
}
269+
270+
271+
/**
272+
* Organization is the top-level entity in the hierarchy of Contentstack, consisting of stacks and stack resources,
273+
* and users. Organization allows easy management of projects as well as users within the Organization.
274+
*
275+
* <b> Example </b>
276+
*
277+
* @param organizationUid
278+
* The UID of the organization that you want to retrieve
279+
* @return the organization
280+
* <br>
281+
* <b>Example</b>
282+
* <pre>
283+
* Contentstack contentstack = new Contentstack.Builder().build();
284+
* Organization org = contentstack.organization();
285+
* </pre>
286+
*/
287+
public Organization organization(@NotNull String organizationUid) {
288+
if (this.authtoken == null)
289+
throw new IllegalStateException("Please Login to access user instance");
290+
if (organizationUid.isEmpty())
291+
throw new IllegalStateException("organizationUid can not be empty");
292+
return new Organization(this.instance, organizationUid);
267293
}
268294

269295
/**
@@ -518,17 +544,15 @@ public Contentstack build() {
518544

519545
private void validateClient(Contentstack contentstack) {
520546
String baseUrl = Util.PROTOCOL + "://" + this.hostname + "/" + version + "/";
521-
this.instance = new Retrofit.Builder()
522-
.baseUrl(baseUrl)
547+
this.instance = new Retrofit.Builder().baseUrl(baseUrl)
523548
.addConverterFactory(GsonConverterFactory.create())
524549
.client(httpClient(contentstack, this.retry)).build();
525550
contentstack.instance = this.instance;
526551
}
527552

528553
private OkHttpClient httpClient(Contentstack contentstack, Boolean retryOnFailure) {
529554
this.authInterceptor = contentstack.interceptor = new AuthInterceptor();
530-
return new OkHttpClient.Builder()
531-
.addInterceptor(this.authInterceptor)
555+
return new OkHttpClient.Builder().addInterceptor(this.authInterceptor)
532556
.addInterceptor(logger())
533557
.proxy(this.proxy)
534558
.retryOnConnectionFailure(retryOnFailure)

0 commit comments

Comments
 (0)