-
Notifications
You must be signed in to change notification settings - Fork 3
feat: typed builder #99
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 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0e28f66
feat: update automations module with API changes
kewynakshlley 4e2a126
feat: update javadocs
kewynakshlley e7a45ca
feat: add typed builders to avoid using maps and improve DX
kewynakshlley 3ecc4a2
fix: small fixes
kewynakshlley f0ce7c4
Merge main into feat/typed-builder
kewynakshlley 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
69 changes: 69 additions & 0 deletions
69
src/main/java/com/resend/services/automations/model/AbstractStepBuilder.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,69 @@ | ||
| package com.resend.services.automations.model; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Abstract base class for automation step builders. | ||
| * | ||
| * @param <T> The concrete builder type for fluent method chaining. | ||
| */ | ||
| public abstract class AbstractStepBuilder<T extends AbstractStepBuilder<T>> { | ||
|
|
||
| /** The step key identifier. */ | ||
| protected final String key; | ||
|
|
||
| /** The step configuration map. */ | ||
| protected final Map<String, Object> config = new HashMap<>(); | ||
|
|
||
| /** | ||
| * Constructs an AbstractStepBuilder with the specified key. | ||
| * | ||
| * @param key The step key identifier. | ||
| */ | ||
| protected AbstractStepBuilder(String key) { | ||
| this.key = key; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the step type for this builder. | ||
| * | ||
| * @return The step type. | ||
| */ | ||
| protected abstract StepType getType(); | ||
|
|
||
| /** | ||
| * Returns this builder instance for fluent chaining. | ||
| * | ||
| * @return This builder instance. | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| protected T self() { | ||
| return (T) this; | ||
| } | ||
|
|
||
| /** | ||
| * Adds a configuration entry. | ||
| * | ||
| * @param name The configuration key. | ||
| * @param value The configuration value. | ||
| * @return This builder instance. | ||
| */ | ||
| protected T addConfig(String name, Object value) { | ||
| config.put(name, value); | ||
| return self(); | ||
| } | ||
|
|
||
| /** | ||
| * Builds a new AutomationStep instance. | ||
| * | ||
| * @return A new AutomationStep. | ||
| */ | ||
| public AutomationStep build() { | ||
| return AutomationStep.builder() | ||
| .key(key) | ||
| .type(getType()) | ||
| .config(config) | ||
| .build(); | ||
| } | ||
| } | ||
31 changes: 31 additions & 0 deletions
31
src/main/java/com/resend/services/automations/model/AddToSegmentStepBuilder.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,31 @@ | ||
| package com.resend.services.automations.model; | ||
|
|
||
| /** | ||
| * Builder for creating add_to_segment automation steps. | ||
| */ | ||
| public class AddToSegmentStepBuilder extends AbstractStepBuilder<AddToSegmentStepBuilder> { | ||
|
|
||
| /** | ||
| * Constructs an AddToSegmentStepBuilder with the specified key. | ||
| * | ||
| * @param key The step key. | ||
| */ | ||
| public AddToSegmentStepBuilder(String key) { | ||
| super(key); | ||
| } | ||
|
|
||
| @Override | ||
| protected StepType getType() { | ||
| return StepType.ADD_TO_SEGMENT; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the segment ID to add the contact to. | ||
| * | ||
| * @param segmentId The segment ID. | ||
| * @return The builder instance. | ||
| */ | ||
| public AddToSegmentStepBuilder segmentId(String segmentId) { | ||
| return addConfig("segment_id", segmentId); | ||
| } | ||
| } |
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
142 changes: 142 additions & 0 deletions
142
src/main/java/com/resend/services/automations/model/AutomationConnection.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,142 @@ | ||
| package com.resend.services.automations.model; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| /** | ||
| * Represents a connection between steps in an automation workflow. | ||
| */ | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public class AutomationConnection { | ||
|
|
||
| @JsonProperty("from") | ||
| private String from; | ||
|
|
||
| @JsonProperty("to") | ||
| private String to; | ||
|
|
||
| @JsonProperty("type") | ||
| private ConnectionType type; | ||
|
|
||
| /** | ||
| * Default constructor for deserialization. | ||
| */ | ||
| public AutomationConnection() { | ||
| } | ||
|
|
||
| /** | ||
| * Constructs an AutomationConnection using the provided builder. | ||
| * | ||
| * @param builder The builder to construct the connection. | ||
| */ | ||
| public AutomationConnection(Builder builder) { | ||
| this.from = builder.from; | ||
| this.to = builder.to; | ||
| this.type = builder.type; | ||
| } | ||
|
|
||
| /** | ||
| * Constructs an AutomationConnection with specified values. | ||
| * | ||
| * @param from The source step key. | ||
| * @param to The target step key. | ||
| * @param type The connection type. | ||
| */ | ||
| public AutomationConnection(String from, String to, ConnectionType type) { | ||
| this.from = from; | ||
| this.to = to; | ||
| this.type = type; | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the source step key. | ||
| * | ||
| * @return The source step key. | ||
| */ | ||
| public String getFrom() { | ||
| return from; | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the target step key. | ||
| * | ||
| * @return The target step key. | ||
| */ | ||
| public String getTo() { | ||
| return to; | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the connection type. | ||
| * | ||
| * @return The connection type. | ||
| */ | ||
| public ConnectionType getType() { | ||
| return type; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new builder instance for AutomationConnection. | ||
| * | ||
| * @return A new Builder instance. | ||
| */ | ||
| public static Builder builder() { | ||
| return new Builder(); | ||
| } | ||
|
|
||
| /** | ||
| * Builder class for constructing AutomationConnection objects. | ||
| */ | ||
| public static class Builder { | ||
| /** | ||
| * Constructs a new Builder instance. | ||
| */ | ||
| public Builder() {} | ||
|
|
||
| private String from; | ||
| private String to; | ||
| private ConnectionType type; | ||
|
|
||
| /** | ||
| * Sets the source step key. | ||
| * | ||
| * @param from The source step key. | ||
| * @return The builder instance. | ||
| */ | ||
| public Builder from(String from) { | ||
| this.from = from; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the target step key. | ||
| * | ||
| * @param to The target step key. | ||
| * @return The builder instance. | ||
| */ | ||
| public Builder to(String to) { | ||
| this.to = to; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the connection type. | ||
| * | ||
| * @param type The connection type. | ||
| * @return The builder instance. | ||
| */ | ||
| public Builder type(ConnectionType type) { | ||
| this.type = type; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Builds a new AutomationConnection instance. | ||
| * | ||
| * @return A new AutomationConnection. | ||
| */ | ||
| public AutomationConnection build() { | ||
| return new AutomationConnection(this); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.