-
Notifications
You must be signed in to change notification settings - Fork 61
Add card block support #456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
slack-base/src/main/java/com/hubspot/slack/client/models/blocks/CardIF.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| package com.hubspot.slack.client.models.blocks; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.hubspot.immutables.style.HubSpotStyle; | ||
| import com.hubspot.slack.client.models.blocks.elements.BlockElement; | ||
| import com.hubspot.slack.client.models.blocks.elements.Image; | ||
| import com.hubspot.slack.client.models.blocks.objects.SlackIconObject; | ||
| import com.hubspot.slack.client.models.blocks.objects.Text; | ||
| import java.util.Optional; | ||
| import org.immutables.value.Value; | ||
| import org.immutables.value.Value.Check; | ||
| import org.immutables.value.Value.Immutable; | ||
|
|
||
| @Immutable | ||
| @HubSpotStyle | ||
| @JsonNaming(SnakeCaseStrategy.class) | ||
| @JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
| public interface CardIF extends Block { | ||
| String TYPE = "card"; | ||
|
|
||
| @Override | ||
| @Value.Derived | ||
| default String getType() { | ||
| return TYPE; | ||
| } | ||
|
|
||
| Optional<Image> getHeroImage(); | ||
|
|
||
| Optional<Image> getIcon(); | ||
|
|
||
| Optional<Text> getTitle(); | ||
|
|
||
| Optional<Text> getSubtitle(); | ||
|
|
||
| Optional<Text> getBody(); | ||
|
|
||
| Optional<Text> getSubtext(); | ||
|
|
||
| ImmutableList<BlockElement> getActions(); | ||
|
|
||
| Optional<SlackIconObject> getSlackIcon(); | ||
|
|
||
| @Check | ||
| default void check() { | ||
| Preconditions.checkState( | ||
| getHeroImage().isPresent() || | ||
| getTitle().isPresent() || | ||
| !getActions().isEmpty() || | ||
| getBody().isPresent(), | ||
| "A card block must have at least one of: hero_image, title, actions, or body" | ||
| ); | ||
| Preconditions.checkState( | ||
| !(getIcon().isPresent() && getSlackIcon().isPresent()), | ||
| "A card block cannot have both icon and slack_icon" | ||
| ); | ||
| getTitle() | ||
| .ifPresent(title -> | ||
| Preconditions.checkState( | ||
| title.getText().length() <= | ||
| BlockElementLengthLimits.MAX_CARD_TITLE_LENGTH.getLimit(), | ||
| "title cannot exceed %s characters", | ||
| BlockElementLengthLimits.MAX_CARD_TITLE_LENGTH.getLimit() | ||
| ) | ||
| ); | ||
| getSubtitle() | ||
| .ifPresent(subtitle -> | ||
| Preconditions.checkState( | ||
| subtitle.getText().length() <= | ||
| BlockElementLengthLimits.MAX_CARD_TITLE_LENGTH.getLimit(), | ||
| "subtitle cannot exceed %s characters", | ||
| BlockElementLengthLimits.MAX_CARD_TITLE_LENGTH.getLimit() | ||
| ) | ||
| ); | ||
| getBody() | ||
| .ifPresent(body -> | ||
| Preconditions.checkState( | ||
| body.getText().length() <= | ||
| BlockElementLengthLimits.MAX_CARD_BODY_LENGTH.getLimit(), | ||
| "body cannot exceed %s characters", | ||
| BlockElementLengthLimits.MAX_CARD_BODY_LENGTH.getLimit() | ||
| ) | ||
| ); | ||
| getSubtext() | ||
| .ifPresent(subtext -> | ||
| Preconditions.checkState( | ||
| subtext.getText().length() <= | ||
| BlockElementLengthLimits.MAX_CARD_BODY_LENGTH.getLimit(), | ||
| "subtext cannot exceed %s characters", | ||
| BlockElementLengthLimits.MAX_CARD_BODY_LENGTH.getLimit() | ||
| ) | ||
| ); | ||
| Preconditions.checkState( | ||
| getActions().size() <= BlockElementLengthLimits.MAX_CARD_ACTIONS_COUNT.getLimit(), | ||
| "A card block cannot have more than %s actions", | ||
| BlockElementLengthLimits.MAX_CARD_ACTIONS_COUNT.getLimit() | ||
| ); | ||
| getBlockId() | ||
| .ifPresent(blockId -> | ||
| Preconditions.checkState( | ||
| blockId.length() <= | ||
| BlockElementLengthLimits.MAX_CARD_BLOCK_ID_LENGTH.getLimit(), | ||
| "block_id cannot exceed %s characters", | ||
| BlockElementLengthLimits.MAX_CARD_BLOCK_ID_LENGTH.getLimit() | ||
| ) | ||
| ); | ||
| } | ||
| } | ||
74 changes: 74 additions & 0 deletions
74
slack-base/src/main/java/com/hubspot/slack/client/models/blocks/objects/SlackIconName.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package com.hubspot.slack.client.models.blocks.objects; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonValue; | ||
|
|
||
| /** | ||
| * Icon names derived from @<a href="https://docs.slack.dev/reference/block-kit/composition-objects/slack-icon-object">slack docs</a> | ||
| */ | ||
| public enum SlackIconName { | ||
| ARCHIVE("archive"), | ||
| BOOK("book"), | ||
| BOOKMARK("bookmark"), | ||
| BOT("bot"), | ||
| BUG("bug"), | ||
| CALENDAR("calendar"), | ||
| CALL("call"), | ||
| CARET_LEFT("caret-left"), | ||
| CARET_RIGHT("caret-right"), | ||
| CHECK("check"), | ||
| CLIPBOARD("clipboard"), | ||
| CODE("code"), | ||
| COMMENT("comment"), | ||
| COMPASS("compass"), | ||
| COPY("copy"), | ||
| CUBE("cube"), | ||
| DOWNLOAD("download"), | ||
| EDIT("edit"), | ||
| EMAIL("email"), | ||
| EYE_CLOSED("eye-closed"), | ||
| EYE_OPEN("eye-open"), | ||
| FILE("file"), | ||
| FLAG("flag"), | ||
| FOLDER("folder"), | ||
| GEAR("gear"), | ||
| GLOBE("globe"), | ||
| HEART("heart"), | ||
| HELP("help"), | ||
| IMAGE("image"), | ||
| INFO("info"), | ||
| KEY("key"), | ||
| LIGHTBULB("lightbulb"), | ||
| LINK("link"), | ||
| MAP("map"), | ||
| MOBILE("mobile"), | ||
| NEW_WINDOW("new-window"), | ||
| PIN("pin"), | ||
| PLUS("plus"), | ||
| REFINE("refine"), | ||
| REFRESH("refresh"), | ||
| ROCKET("rocket"), | ||
| SAVE("save"), | ||
| SCREEN("screen"), | ||
| SHARE("share"), | ||
| SPARKLE("sparkle"), | ||
| STAR("star"), | ||
| STAR_FILLED("star-filled"), | ||
| TAG("tag"), | ||
| THUMBS_DOWN("thumbs-down"), | ||
| THUMBS_UP("thumbs-up"), | ||
| TRASH("trash"), | ||
| UPLOAD("upload"), | ||
| USER("user"), | ||
| WARNING("warning"); | ||
|
|
||
| private final String value; | ||
|
|
||
| SlackIconName(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| @JsonValue | ||
| public String getValue() { | ||
| return value; | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
...-base/src/main/java/com/hubspot/slack/client/models/blocks/objects/SlackIconObjectIF.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.hubspot.slack.client.models.blocks.objects; | ||
|
|
||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| import com.hubspot.immutables.style.HubSpotStyle; | ||
| import org.immutables.value.Value; | ||
| import org.immutables.value.Value.Immutable; | ||
|
|
||
| @Immutable | ||
| @HubSpotStyle | ||
| @JsonNaming(SnakeCaseStrategy.class) | ||
| public interface SlackIconObjectIF extends CompositionObject { | ||
| String TYPE = "icon"; | ||
|
|
||
| @Value.Derived | ||
| default String getType() { | ||
| return TYPE; | ||
| } | ||
|
|
||
| @Value.Parameter | ||
| SlackIconName getName(); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.