2018-02-19 16:35:01 +01:00
|
|
|
package org.gcube.social_networking.social_networking_client_library;
|
2017-10-21 22:35:21 +02:00
|
|
|
|
2018-02-16 19:22:14 +01:00
|
|
|
import javax.ws.rs.core.GenericType;
|
|
|
|
|
2017-10-21 22:35:21 +02:00
|
|
|
import org.apache.commons.lang.Validate;
|
2018-02-19 16:35:01 +01:00
|
|
|
import org.gcube.social_networking.social_networking_client_library.utils.HttpClient;
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.beans.ApplicationId;
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.output.ResponseBean;
|
2017-10-21 22:35:21 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tokens client.
|
|
|
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
|
|
|
*/
|
2018-02-19 16:27:09 +01:00
|
|
|
public class TokenClient extends BaseClient{
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
private static final String SUB_SERVICE_PATH = "2/tokens/";
|
2018-02-19 16:27:09 +01:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(TokenClient.class);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
|
2018-02-19 16:27:09 +01:00
|
|
|
public TokenClient() throws Exception {
|
2017-10-21 22:35:21 +02:00
|
|
|
super(SUB_SERVICE_PATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate application token
|
|
|
|
* @return generated token
|
|
|
|
*/
|
|
|
|
public String generateApplicationToken(ApplicationId appId){
|
|
|
|
|
|
|
|
Validate.isTrue(appId != null, "application id cannot be null");
|
|
|
|
|
|
|
|
logger.debug("Request for writing new message");
|
|
|
|
String thisMethodSignature = "generate-application-token";
|
|
|
|
String request = getServiceEndpoint() + thisMethodSignature + "?";
|
2018-02-17 18:51:38 +01:00
|
|
|
return HttpClient.post(new GenericType<ResponseBean<String>>(){}, request, appId);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|