Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Fix SlackAction: change SlackAction "value" to "url" #43

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
<email>[email protected]</email>
<url>https://github.com/galimru/</url>
</contributor>
<contributor>
<name>Desmond Vehar</name>
<email>[email protected]</email>
<url>https://github.com/dvehar/</url>
</contributor>
</contributors>

<distributionManagement>
Expand All @@ -67,6 +72,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.5</java.version>
<gson.version>2.3.1</gson.version>
<junit.version>4.8.1</junit.version>
</properties>

<build>
Expand Down Expand Up @@ -162,5 +168,11 @@
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.gpedro.integrations.slack;

import com.google.gson.JsonObject;

public interface JsonSerializable {
JsonObject toJson();
}
92 changes: 0 additions & 92 deletions src/main/java/net/gpedro/integrations/slack/SlackAction.java

This file was deleted.

18 changes: 0 additions & 18 deletions src/main/java/net/gpedro/integrations/slack/SlackActionStyle.java

This file was deleted.

19 changes: 0 additions & 19 deletions src/main/java/net/gpedro/integrations/slack/SlackActionType.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import net.gpedro.integrations.slack.attachment.action.SlackAction;

/**
* Represents an attachment in a slack webhook JSON message.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.gpedro.integrations.slack.attachment.action;

import com.google.gson.JsonObject;

/**
* @author Desmond Vehar
*/
public class BasicButtonSlackAction extends ButtonSlackAction {

private static final String URL = "url";

private String url;

public BasicButtonSlackAction(String name, String text, String url) {
super(name, text, Type.BUTTON);

checkArgForNull(URL, url);
this.url = url;
}

public JsonObject toJson() {
final JsonObject data = super.toJson();

data.addProperty(URL, url);

return data;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.gpedro.integrations.slack.attachment.action;

import com.google.gson.JsonObject;
import net.gpedro.integrations.slack.JsonSerializable;

/**
* @author Desmond Vehar
*/
public abstract class ButtonSlackAction extends SlackAction {
private static final String STYLE = "style";

private Style style;

ButtonSlackAction(String name, String text, Type type) {
super(name, text, type);
}

public void setStyle(Style style) {
this.style = style;
}

public JsonObject toJson() {
final JsonObject data = super.toJson();

if (style != null) {
data.addProperty(STYLE, style.getCode());
}

return data;
}

enum Style {
DEFAULT("default"), PRIMARY("primary"), DANGER("danger");

private String code;

Style(String code) {
this.code = code;
}

public String getCode() {
return code;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package net.gpedro.integrations.slack.attachment.action;

import com.google.gson.JsonObject;
import net.gpedro.integrations.slack.JsonSerializable;

/**
* @author Desmond Vehar
*/
public class InteractiveButtonSlackAction extends ButtonSlackAction {

private static final String VALUE = "value";
private static final String CONFIRM = "confirm";

private String value;
private Confirm confirm;

public InteractiveButtonSlackAction(String name, String text, String value) {
super(name, text, Type.BUTTON);

checkArgForNull(VALUE, value);
this.value = value;
}

public void setConfirm(Confirm confirm) {
this.confirm = confirm;
}

public JsonObject toJson() {
final JsonObject data = super.toJson();

data.addProperty(VALUE, value);

if (confirm != null) {
data.add(CONFIRM, confirm.toJson());
}

return data;
}

public static class Confirm implements JsonSerializable {
private String title;
private String text;
private String ok_text;
private String dismiss_text;

public Confirm(String title, String text, String ok_text, String dismiss_text) {
this.title = title;
this.text = text;
this.ok_text = ok_text;
this.dismiss_text = dismiss_text;
}

public JsonObject toJson() {
JsonObject data = new JsonObject();
data.addProperty("title", title);
data.addProperty("text", text);
data.addProperty("ok_text", ok_text);
data.addProperty("dismiss_text", dismiss_text);
return data;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package net.gpedro.integrations.slack.attachment.action;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.gpedro.integrations.slack.JsonSerializable;

import java.util.ArrayList;
import java.util.List;

/**
* @author Desmond Vehar
*/
public class InteractiveSelectSlackAction extends SlackAction {

private static final String OPTIONS = "options";

private List<Option> options;

public InteractiveSelectSlackAction(String name, String text) {
super(name, text, Type.SELECT);

this.options = new ArrayList<Option>();
}

public InteractiveSelectSlackAction(String name, String text, List<Option> options) {
super(name, text, Type.SELECT);

checkArgForNull(OPTIONS, options);
this.options = options;
}

public JsonObject toJson() {
final JsonObject data = super.toJson();

JsonArray array = new JsonArray();
for (Option option : options) {
JsonObject obj = new JsonObject();
obj.addProperty("text", option.text);
obj.addProperty("value", option.value);
array.add(obj);
}
data.add(OPTIONS, array);

return data;
}

public static class Option implements JsonSerializable {
private String text;
private String value;

public Option(String text, String value) {
this.text = text;
this.value = value;
}

public JsonObject toJson() {
return new JsonObject();
}
}
}
Loading