-
Notifications
You must be signed in to change notification settings - Fork 133
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
Add email-templates endpoints #117
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a1ca7e3
add email templates endpoints
lbalmaceda dc62efe
Add missing email templates entity getter
lbalmaceda b38b10b
add tests and update email-templates entity
lbalmaceda 640ab12
(: codavaj xif
lbalmaceda 2f3555f
fix class level javadoc
lbalmaceda 36a220c
fix test
lbalmaceda 26f0cea
change default for syntax. add json tests
lbalmaceda 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 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
97 changes: 97 additions & 0 deletions
97
src/main/java/com/auth0/client/mgmt/EmailTemplatesEntity.java
This file contains 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,97 @@ | ||
package com.auth0.client.mgmt; | ||
|
||
import com.auth0.json.mgmt.EmailTemplate; | ||
import com.auth0.net.CustomRequest; | ||
import com.auth0.net.Request; | ||
import com.auth0.utils.Asserts; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import okhttp3.HttpUrl; | ||
import okhttp3.OkHttpClient; | ||
|
||
/** | ||
* Class that provides an implementation of the Email Templates methods of the Management API as defined in https://auth0.com/docs/api/management/v2#!/Email_Templates | ||
*/ | ||
@SuppressWarnings({"WeakerAccess", "unused"}) | ||
public class EmailTemplatesEntity extends BaseManagementEntity { | ||
|
||
public static final String TEMPLATE_VERIFY_EMAIL = "verify_email"; | ||
public static final String TEMPLATE_RESET_EMAIL = "reset_email"; | ||
public static final String TEMPLATE_WELCOME_EMAIL = "welcome_email"; | ||
public static final String TEMPLATE_BLOCKED_ACCOUNT = "blocked_account"; | ||
public static final String TEMPLATE_STOLEN_CREDENTIALS = "stolen_credentials"; | ||
public static final String TEMPLATE_ENROLLMENT_EMAIL = "enrollment_email"; | ||
public static final String TEMPLATE_CHANGE_PASSWORD = "change_password"; | ||
public static final String TEMPLATE_PASSWORD_RESET = "password_reset"; | ||
public static final String TEMPLATE_MFA_OOB_CODE = "mfa_oob_code"; | ||
|
||
EmailTemplatesEntity(OkHttpClient client, HttpUrl baseUrl, String apiToken) { | ||
super(client, baseUrl, apiToken); | ||
} | ||
|
||
/** | ||
* Request the Email Templates. A token with scope read:email_templates is needed. | ||
* See https://auth0.com/docs/api/management/v2#!/Email_Templates/get_email_templates_by_templateName | ||
* | ||
* @param templateName the template name to request. You can use any of the constants defined in {@link EmailTemplatesEntity} | ||
* @return a Request to execute. | ||
*/ | ||
public Request<EmailTemplate> get(String templateName) { | ||
Asserts.assertNotNull(templateName, "template name"); | ||
HttpUrl.Builder builder = baseUrl | ||
.newBuilder() | ||
.addPathSegments("api/v2/email-templates") | ||
.addPathSegment(templateName); | ||
String url = builder.build().toString(); | ||
CustomRequest<EmailTemplate> request = new CustomRequest<>(client, url, "GET", new TypeReference<EmailTemplate>() { | ||
}); | ||
request.addHeader("Authorization", "Bearer " + apiToken); | ||
return request; | ||
} | ||
|
||
/** | ||
* Create an Email Template. A token with scope create:email_templates is needed. | ||
* See https://auth0.com/docs/api/management/v2#!/Email_Templates/post_email_templates | ||
* | ||
* @param template the template data to set | ||
* @return a Request to execute. | ||
*/ | ||
public Request<EmailTemplate> create(EmailTemplate template) { | ||
Asserts.assertNotNull(template, "template"); | ||
|
||
String url = baseUrl | ||
.newBuilder() | ||
.addPathSegments("api/v2/email-templates") | ||
.build() | ||
.toString(); | ||
CustomRequest<EmailTemplate> request = new CustomRequest<>(this.client, url, "POST", new TypeReference<EmailTemplate>() { | ||
}); | ||
request.addHeader("Authorization", "Bearer " + apiToken); | ||
request.setBody(template); | ||
return request; | ||
} | ||
|
||
/** | ||
* Patches the existing Email Template. A token with scope update:email_templates is needed. | ||
* See https://auth0.com/docs/api/management/v2#!/Email_Templates/patch_email_templates_by_templateName | ||
* | ||
* @param templateName the name of the template to update. You can use any of the constants defined in {@link EmailTemplatesEntity} | ||
* @param template the email template data to set. | ||
* @return a Request to execute. | ||
*/ | ||
public Request<EmailTemplate> update(String templateName, EmailTemplate template) { | ||
Asserts.assertNotNull(templateName, "template name"); | ||
Asserts.assertNotNull(template, "template"); | ||
|
||
String url = baseUrl | ||
.newBuilder() | ||
.addPathSegments("api/v2/email-templates") | ||
.addPathSegment(templateName) | ||
.build() | ||
.toString(); | ||
CustomRequest<EmailTemplate> request = new CustomRequest<>(this.client, url, "PATCH", new TypeReference<EmailTemplate>() { | ||
}); | ||
request.addHeader("Authorization", "Bearer " + apiToken); | ||
request.setBody(template); | ||
return request; | ||
} | ||
} |
This file contains 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 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,196 @@ | ||
package com.auth0.json.mgmt; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* Class that represents an Email Template object. Related to the {@link com.auth0.client.mgmt.EmailTemplatesEntity} entity. | ||
*/ | ||
@SuppressWarnings({"unused", "WeakerAccess"}) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class EmailTemplate { | ||
|
||
@JsonProperty("template") | ||
private String name; | ||
@JsonProperty("body") | ||
private String body; | ||
@JsonProperty("from") | ||
private String from; | ||
@JsonProperty("resultUrl") | ||
private String resultUrl; | ||
@JsonProperty("subject") | ||
private String subject; | ||
@JsonProperty("syntax") | ||
private String syntax; | ||
@JsonProperty("urlLifetimeInSeconds") | ||
private Integer urlLifetimeInSeconds; | ||
@JsonProperty("enabled") | ||
private Boolean enabled; | ||
|
||
public EmailTemplate() { | ||
//Only here to set the syntax default value | ||
this.syntax = "liquid"; | ||
} | ||
|
||
/** | ||
* Getter for the name of the template. | ||
* | ||
* @return the name. | ||
*/ | ||
@JsonProperty("template") | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* Sets the name of the template. | ||
*/ | ||
@JsonProperty("template") | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* Getter for the template code. | ||
* | ||
* @return the template code. | ||
*/ | ||
@JsonProperty("body") | ||
public String getBody() { | ||
return body; | ||
} | ||
|
||
/** | ||
* Sets the template code | ||
* | ||
* @param body the code this template will have | ||
*/ | ||
@JsonProperty("body") | ||
public void setBody(String body) { | ||
this.body = body; | ||
} | ||
|
||
/** | ||
* Getter for the sender of the email | ||
* | ||
* @return the sender of the email | ||
*/ | ||
@JsonProperty("from") | ||
public String getFrom() { | ||
return from; | ||
} | ||
|
||
/** | ||
* Sets the sender of the email | ||
* | ||
* @param from the sender of the email | ||
*/ | ||
@JsonProperty("from") | ||
public void setFrom(String from) { | ||
this.from = from; | ||
} | ||
|
||
/** | ||
* Getter the URL to redirect the user to after a successful action. | ||
* | ||
* @return the URL to redirect the user to after a successful action. | ||
*/ | ||
@JsonProperty("resultUrl") | ||
public String getResultUrl() { | ||
return resultUrl; | ||
} | ||
|
||
/** | ||
* Sets the URL to redirect the user to after a successful action. | ||
* | ||
* @param resultUrl the URL to redirect the user to after a successful action. | ||
*/ | ||
@JsonProperty("resultUrl") | ||
public void setResultUrl(String resultUrl) { | ||
this.resultUrl = resultUrl; | ||
} | ||
|
||
/** | ||
* Getter for the subject of the email. | ||
* | ||
* @return the subject of the email. | ||
*/ | ||
@JsonProperty("subject") | ||
public String getSubject() { | ||
return subject; | ||
} | ||
|
||
/** | ||
* Sets the subject of the email. | ||
* | ||
* @param subject the subject of the email. | ||
*/ | ||
@JsonProperty("subject") | ||
public void setSubject(String subject) { | ||
this.subject = subject; | ||
} | ||
|
||
/** | ||
* Getter for the syntax used in the template's code. | ||
* | ||
* @return the syntax used in the template's code. | ||
*/ | ||
@JsonProperty("syntax") | ||
public String getSyntax() { | ||
return syntax; | ||
} | ||
|
||
/** | ||
* Sets for the syntax to be used in the template's code. | ||
* Default value is 'liquid' | ||
* | ||
* @param syntax the syntax to be used in the template's code. | ||
*/ | ||
@JsonProperty("syntax") | ||
public void setSyntax(String syntax) { | ||
this.syntax = syntax; | ||
} | ||
|
||
/** | ||
* Getter for the lifetime in seconds that the link within the email will be valid for. | ||
* | ||
* @return the lifetime in seconds that the link within the email will be valid for. | ||
*/ | ||
@JsonProperty("urlLifetimeInSeconds") | ||
public Integer getUrlLifetimeInSeconds() { | ||
return urlLifetimeInSeconds; | ||
} | ||
|
||
/** | ||
* Sets the lifetime in seconds that the link within the email will be valid for. | ||
* | ||
* @param urlLifetimeInSeconds the lifetime in seconds that the link within the email will be valid for. | ||
*/ | ||
@JsonProperty("urlLifetimeInSeconds") | ||
public void setUrlLifetimeInSeconds(Integer urlLifetimeInSeconds) { | ||
this.urlLifetimeInSeconds = urlLifetimeInSeconds; | ||
} | ||
|
||
/** | ||
* Whether or not this template is enabled. | ||
* | ||
* @return true if this template is enabled, false otherwise. | ||
*/ | ||
@JsonProperty("enabled") | ||
public Boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
/** | ||
* Enables or disables this template. | ||
* | ||
* @param enabled whether this template is enabled or not. | ||
*/ | ||
@JsonProperty("enabled") | ||
public void setEnabled(Boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
} |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be an enum for additional validation? Although only supported value is
liquid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HMMM. I discussed this with the server guys. The only allowed value is
liquid
but they say the option is only there for backwards compatibility, so we shouldn't be hardcoding it toliquid
and lowering the param count for example. I don't think offering an enum/constant helps but I don't mind adding one. Would you prefer me to add it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you set the param default to
liquid
? Then they don't need to think about it but in the future if they need to, they can change.