Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package in.ashwanthkumar.slack.webhook.service;
 
import static in.ashwanthkumar.slack.webhook.util.StringUtils.isNotEmpty;
import static in.ashwanthkumar.slack.webhook.util.StringUtils.startsWith;
public class SlackService {
    private final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
    public void push(String webHookUrlSlackMessage textString usernameString imageOrIconString destinationthrows IOException {
        Map<StringStringpayload = new HashMap<StringString>();
        if (isNotEmpty(username)) {
            payload.put("username"username);
        }
        if (startsWith(imageOrIcon"http")) {
            payload.put("icon_url"imageOrIcon);
        } else if (isNotEmpty(imageOrIcon)) {
            payload.put("icon_emoji"imageOrIcon);
        }
        if (isNotEmpty(destination)) {
            payload.put("channel"destination);
        }
        payload.put("text"text.toString());
        execute(webHookUrlpayload);
    }
    public void execute(String webHookUrlMap<StringStringpayloadthrows IOException {
        HttpRequest httpRequest = .buildPostRequest(new GenericUrl(webHookUrl), new JsonHttpContent(new GsonFactory(), payload));
        httpRequest.execute();
    }
New to GrepCode? Check out our FAQ X