Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions src/main/java/com/resend/core/net/impl/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* An implementation of the {@link IHttpClient} interface for performing HTTP requests.
* This implementation utilizes the OkHttp library for handling HTTP communication.
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public class HttpClient implements IHttpClient<Response> {

/** The base URL for the API. */
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/resend/core/service/BaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* An abstract base class for service implementations, providing common functionality such as HTTP client,
* authentication provider, and mapper initialization.
*/
@SuppressWarnings("rawtypes")
public abstract class BaseService {

/**
Expand Down
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)
Comment thread
kewynakshlley marked this conversation as resolved.
Outdated
.build();
}
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,38 @@ public class Automation {
@JsonProperty("steps")
private List<AutomationStepResponse> steps;

@JsonProperty("edges")
private List<AutomationEdge> edges;
@JsonProperty("connections")
private List<AutomationConnection> connections;

/**
* Default constructor for deserialization.
*/
public Automation() {
}

/**
* Constructs an Automation with specified values.
*
* @param object The object type.
* @param id The automation ID.
* @param name The automation name.
* @param status The automation status.
* @param createdAt The creation timestamp.
* @param updatedAt The last update timestamp.
* @param steps The list of steps.
* @param connections The list of connections.
*/
public Automation(String object, String id, String name, AutomationStatus status,
String createdAt, String updatedAt,
List<AutomationStepResponse> steps, List<AutomationEdge> edges) {
List<AutomationStepResponse> steps, List<AutomationConnection> connections) {
this.object = object;
this.id = id;
this.name = name;
this.status = status;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.steps = steps;
this.edges = edges;
this.connections = connections;
}

/**
Expand Down Expand Up @@ -113,11 +128,11 @@ public List<AutomationStepResponse> getSteps() {
}

/**
* Retrieves the list of automation edges.
* Retrieves the list of automation connections.
*
* @return The list of edges.
* @return The list of connections.
*/
public List<AutomationEdge> getEdges() {
return edges;
public List<AutomationConnection> getConnections() {
return connections;
}
}
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);
}
}
}
Loading
Loading