Skip to content

Commit

Permalink
Slack Chat PR Code4SocialGood#37 review Changes
Browse files Browse the repository at this point in the history
Slack Chat - Whether User Joined Slack Room Code4SocialGood#24 Code4SocialGood#37
review changes
  • Loading branch information
arpitsrm committed Mar 21, 2017
1 parent c6c5c94 commit 5c71df4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
21 changes: 11 additions & 10 deletions src/main/java/org/c4sg/constant/slack/SlackWebApiConstants.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package org.c4sg.constant.slack;

public interface SlackWebApiConstants {
public enum SlackWebApiConstants {

String SLACK_WEB_API_URL = "https://slack.com/api";
String SLACK_WEB_API_DOCUMENT_URL = "https://api.slack.com/methods";
String SLACK_AUTH_TOKEN = "xoxp-157046850982-155658879760-157047222166-ef8e3bfdcd68c01c0bcab801296f112d";
USERS_LIST("users.list");

int DEFAULT_TIMEOUT = 5000;
int DEFAULT_COUNT = 100;
int DEFAULT_PAGE = 1;

// users
String USERS_LIST = "users.list";
private String value;

SlackWebApiConstants(String value) {
this.value=value;
}

public String getValue() {
return value;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.apache.http.HttpEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.c4sg.constant.slack.Problem;
import org.c4sg.constant.slack.SlackWebApiConstants;
import org.c4sg.dao.UserDAO;
import org.c4sg.dto.slack.Profile;
import org.c4sg.dto.slack.User;
Expand All @@ -22,6 +21,7 @@
import org.c4sg.service.slack.method.UserListMethod;
import org.c4sg.util.slack.SlackUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.type.TypeReference;
Expand All @@ -30,8 +30,19 @@

@Service
public class SlackClientServiceImpl implements SlackClientService {

private String token;

@Value("${slack.auth.token}")
private String slackAuthToken;

@Value("${slack.webapi.url}")
private String slackApiUrl;

@Value("${slack.webapi.document.url}")
private String slackApiDocUrl;

@Value("${slack.default.timeout}")
private String slackDefaultTimeOut;

private ObjectMapper mapper;
private CloseableHttpClient httpClient;

Expand All @@ -56,8 +67,8 @@ public List<User> getUserList() {

@Override
public Boolean isJoinedChat(String email){
token=SlackWebApiConstants.SLACK_AUTH_TOKEN;
httpClient = SlackUtils.createHttpClient(1000000);
//token=SlackWebApiConstants.SLACK_AUTH_TOKEN;
httpClient = SlackUtils.createHttpClient(Integer.parseInt(slackDefaultTimeOut));
mapper = new ObjectMapper();
try {
org.c4sg.entity.User user = userDAO.findByEmail(email);
Expand Down Expand Up @@ -140,10 +151,10 @@ protected JsonNode call(SlackMethod method, InputStream is) {

Map<String, String> parameters = method.getParameters();
if (method.isRequiredToken()) {
parameters.put("token", token);
parameters.put("token", slackAuthToken);
}

String apiUrl = SlackWebApiConstants.SLACK_WEB_API_URL + "/" + method.getMethodName();
String apiUrl = slackApiUrl + "/" + method.getMethodName();

HttpEntity httpEntity = null;
if (is == null) {
Expand All @@ -165,7 +176,7 @@ protected JsonNode call(SlackMethod method, InputStream is) {
if (!retOk) {
String error = retNode.findPath("error").asText();
throw new SlackResponseErrorException(error + ". check the link "
+ SlackWebApiConstants.SLACK_WEB_API_DOCUMENT_URL + "/" + method.getMethodName());
+ slackApiDocUrl + "/" + method.getMethodName());
}

return retNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void setPresence(String presence) {

@Override
public String getMethodName() {
return SlackWebApiConstants.USERS_LIST;
return SlackWebApiConstants.USERS_LIST.getValue();
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ spring.datasource.url = jdbc:mysql://localhost:3306/c4sg
# Username and secret
spring.datasource.username = root
spring.datasource.password = mysql

# slack related properties
slack.webapi.url = https://slack.com/api
slack.webapi.document.url = https://api.slack.com/methods
slack.auth.token = xoxp-157046850982-155658879760-157047222166-ef8e3bfdcd68c01c0bcab801296f112d
slack.default.timeout = 5000

6 changes: 6 additions & 0 deletions src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ spring.datasource.url = jdbc:${DATABASE_URL}
# Username and secret
spring.datasource.username = ${DATABASE_USERNAME}
spring.datasource.password = ${DATABASE_PASSWORD}

# slack related properties
slack.webapi.url = ${SLACK_WEB_API_URL}
slack.webapi.document.url = ${SLACK_WEB_API_DOCUMENT_URL}
slack.auth.token = ${SLACK_AUTH_TOKEN}
slack.default.timeout = ${SLACK_DEFAULT_TIMEOUT}

0 comments on commit 5c71df4

Please sign in to comment.