io.sphere.sdk.customers.commands.CustomerCreateEmailTokenCommand Maven / Gradle / Ivy
package io.sphere.sdk.customers.commands;
import com.fasterxml.jackson.core.type.TypeReference;
import io.sphere.sdk.commands.CommandImpl;
import io.sphere.sdk.customers.Customer;
import io.sphere.sdk.customers.CustomerToken;
import io.sphere.sdk.http.HttpRequest;
import io.sphere.sdk.models.Versioned;
import io.sphere.sdk.utils.JsonUtils;
import static io.sphere.sdk.http.HttpMethod.POST;
/**
Creates a token for verifying the customer's email.
{@include.example io.sphere.sdk.customers.commands.CustomerCreateEmailTokenCommandTest#execution()}
*/
public class CustomerCreateEmailTokenCommand extends CommandImpl {
private final String id;
private final long version;
private final int ttlMinutes;
private CustomerCreateEmailTokenCommand(final String id, final long version, final int ttlMinutes) {
this.id = id;
this.version = version;
this.ttlMinutes = ttlMinutes;
}
public static CustomerCreateEmailTokenCommand of(final Versioned customer, final int timeToLiveInMinutes) {
return new CustomerCreateEmailTokenCommand(customer.getId(), customer.getVersion(), timeToLiveInMinutes);
}
public String getId() {
return id;
}
public long getVersion() {
return version;
}
public int getTtlMinutes() {
return ttlMinutes;
}
@Override
protected TypeReference typeReference() {
return CustomerToken.typeReference();
}
@Override
public HttpRequest httpRequest() {
return HttpRequest.of(POST, "/customers/email-token", JsonUtils.toJson(this));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy