Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant comment

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.smartling.marketo.sdk;

import com.smartling.marketo.sdk.rest.MarketoTriggerCampaignClient;

public interface MarketoClientManager {
MarketoFolderClient getMarketoFolderClient();

Expand All @@ -18,4 +20,6 @@ public interface MarketoClientManager {
MarketoProgramClient getMarketoProgramClient();

MarketoTokenClient getMarketoTokenClient();

MarketoTriggerCampaignClient getMarketoTriggerCampaignClient();
Copy link
Contributor

@anastasiia-kryshtop anastasiia-kryshtop May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming convention of the Marketo and this sdk is not followed. I suggest to rename this client to SmartCampaignClient or CampaignClient. It will be able to be extended with other smart campaign endpoints.

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.smartling.marketo.sdk.domain.campaign;


import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@AllArgsConstructor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data lombok's annotation can be used instead of a combination of Getter,Setter,ToString

public class TriggerCampaignRequest {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, it is confusing with RequestTriggerCampaign

Copy link
Contributor

@anastasiia-kryshtop anastasiia-kryshtop May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request data (leads and tokens) should be moved to the appropriate command (RequestTriggerCampaignCommand)


private LeadId[] leads;
private Token[] tokens;

@Getter
@Setter
@ToString
@AllArgsConstructor
public static class LeadId {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


private int id;
}

@Getter
@Setter
@ToString
@AllArgsConstructor
public static class Token {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like in the previous comment it should be separate domain class Token


private String name;
private String value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.smartling.marketo.sdk.domain.campaign;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter @Setter @ToString
public class TriggerCampaignResult {
Copy link
Contributor

@anastasiia-kryshtop anastasiia-kryshtop May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Result of request trigger command should be Array of Campaign domain classes

private int id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public MarketoTokenClient getMarketoTokenClient() {
return new MarketoTokenRestClient(httpCommandExecutor);
}

@Override
public MarketoTriggerCampaignClient getMarketoTriggerCampaignClient() {
return new MarketoTriggerCampaignClient(httpCommandExecutor);
}

public final static class Builder {
private final String identityUrl;
private final String restUrl;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.smartling.marketo.sdk.rest;

import com.smartling.marketo.sdk.MarketoApiException;
import com.smartling.marketo.sdk.domain.campaign.TriggerCampaignRequest;
import com.smartling.marketo.sdk.domain.campaign.TriggerCampaignResult;
import com.smartling.marketo.sdk.rest.command.triggercampaign.ActivateSmartCampaign;
import com.smartling.marketo.sdk.rest.command.triggercampaign.RequestTriggerCampaign;

import java.util.List;

public class MarketoTriggerCampaignClient {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add some tests for the new client


private final HttpCommandExecutor httpCommandExecutor;

MarketoTriggerCampaignClient(HttpCommandExecutor httpCommandExecutor) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it isn't a public?
you can use @requiredargsconstructor lombok annotation

this.httpCommandExecutor = httpCommandExecutor;
}

public TriggerCampaignResult requestTriggerCampaign(int campaignId,
TriggerCampaignRequest.LeadId[] leadIds)
throws MarketoApiException {
return this.requestTriggerCampaign(campaignId, leadIds,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omit redundant 'this'

new TriggerCampaignRequest.Token[]{});
}

public TriggerCampaignResult requestTriggerCampaign(int campaignId,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have only one method:
TriggerCampaignResult requestTriggerCampaign(int campaignId, TriggerCampaignRequest triggerCampaignRequest)
and construct TriggerCampaignRequest outside client.

in your case, your split constructing TriggerCampaignRequest into 2 places, outside client your construct leadIds and tokens, inside client ( in RequestTriggerCampaign ) - wrap them in TriggerCampaignRequest

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, maybe it is just the bad model for TriggerCampaignRequest.
and you need something like:

public TriggerCampaignResult requestTriggerCampaign(
int campaignId, 
List<Integer> leadIds, 
List<TriggerCampaignToken> tokens)

TriggerCampaignRequest.LeadId[] leadIds, TriggerCampaignRequest.Token[] tokens)
throws MarketoApiException {
List<TriggerCampaignResult> triggerCampaignResults = httpCommandExecutor.execute(
new RequestTriggerCampaign(campaignId, leadIds, tokens));
return triggerCampaignResults.get(0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the context, but it is an unsafe call. check size isn't empty at least. the same in next method

}

public TriggerCampaignResult activateSmartCampaign(int campaignId)
throws MarketoApiException {
List<TriggerCampaignResult> triggerCampaignResults = httpCommandExecutor.execute(
new ActivateSmartCampaign(campaignId));
return triggerCampaignResults.get(0);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.smartling.marketo.sdk.rest.command.triggercampaign;

import com.smartling.marketo.sdk.domain.campaign.TriggerCampaignResult;
import com.smartling.marketo.sdk.rest.command.BaseMarketoCommand;

public class ActivateSmartCampaign extends BaseMarketoCommand<TriggerCampaignResult> {
private final int campaignId;

public ActivateSmartCampaign(int campaignId) {
super(TriggerCampaignResult.class);
this.campaignId = campaignId;
}

@Override
public String getPath() {
return "/asset/v1/smartCampaign/" + campaignId + "/activate.json";
}

@Override
public String getMethod() {
return "POST_BODY";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.smartling.marketo.sdk.rest.command.triggercampaign;

import com.google.common.collect.ImmutableMap;
import com.smartling.marketo.sdk.domain.campaign.TriggerCampaignRequest;
import com.smartling.marketo.sdk.domain.campaign.TriggerCampaignResult;
import com.smartling.marketo.sdk.rest.command.BaseMarketoCommand;

import java.util.Map;

public class RequestTriggerCampaign extends BaseMarketoCommand<TriggerCampaignResult> {

private final int campaignId;
private final TriggerCampaignRequest triggerCampaignRequest;

public RequestTriggerCampaign(int campaignId, TriggerCampaignRequest.LeadId[] leadIds,
TriggerCampaignRequest.Token[] tokens) {
super(TriggerCampaignResult.class);
this.campaignId = campaignId;
this.triggerCampaignRequest = new TriggerCampaignRequest(leadIds, tokens);
}

@Override
public String getPath() {
return "/v1/campaigns/" + campaignId + "/trigger.json";
}

@Override
public String getMethod() {
return "POST_BODY";
}

@Override
public Map<String, Object> getParameters() {
ImmutableMap.Builder<String, Object> builder = ImmutableMap.<String, Object>builder()
.put("input", this.triggerCampaignRequest);
return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ private <T> MarketoResponse<T> execute(Invocation.Builder invocationBuilder, Com
MultiPart multiPartEntity = toMultipart(processParameters(command.getParameters(), false));
Entity<?> entity = Entity.entity(multiPartEntity, multiPartEntity.getMediaType());
marketoResponse = invocationBuilder.post(entity, typeToken);
} else {
} else if ("POST_BODY".equalsIgnoreCase(command.getMethod())) {
Map<String, Object> body = processParameters(command.getParameters(), false);
Entity<?> entity = Entity.entity(body, MediaType.APPLICATION_JSON_TYPE.withCharset("UTF-8"));
marketoResponse = invocationBuilder.post(entity, typeToken);
}
else {
marketoResponse = invocationBuilder.method(command.getMethod(), typeToken);
}

Expand Down