-
Notifications
You must be signed in to change notification settings - Fork 215
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 template endpoints #251
Conversation
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.
It feels a little simple because the methods do nothing more than setting the http method, the "email-templates" path and the body (if applies). But I haven't seen the rest of the library, so can't compare. Anyway:
- I'd add in the "javadocs" the required scope to call that method. i.e.
create:email-templates
. You can get those from the api explorer docs. - Some methods require at least some parameters to be passed. i.e. for creating a new template you need to provide a name, for sure. Maybe it's worth to validate those cases locally before wasting time (and resources) in making a request we already know is going to fail.
- Template names are limited to a few options. Maybe it's worth to provide some constants so users find easier to type them or add some local name validation?
$builder->withHeaders($this->headers); | ||
|
||
if ( in_array( $method, [ 'patch', 'post', 'put' ] ) ) { | ||
$builder->withHeader( new ContentType('application/json') ); |
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.
I know this works for when you need to send a body
in the request, but probably would be good to check if all requests send the Accept
header so the server knows what you're expecting back in the response.
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.
I don't see an Accept
header used in any of the examples in the docs. I'm wary of just dropping that in if it's not documented.
* | ||
* @return array | ||
* | ||
* @throws \Exception - if a 200 response was not returned from the API. |
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.
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.
I checked before submitting, all are 200 but good eyes 👍
const EMAIL_TEMPLATE_NAME = 'enrollment_email'; | ||
|
||
/** | ||
* Management API token with scopes read:email_templates, create:email_templates, update:email_templates |
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.
while this is true for calling all endpoints, some of them can be called with only 1 of this scopes. So this is not exactly true
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.
This is in a test and for the tests here to run, it needs all three.
Thanks @lbalmaceda ... this is definitely more documentation than the other methods have but I'm trying to use it as a good template to go back through the others and fill it all out. Your suggestions are 👍 |
@lbalmaceda - Responses to your comment:
|
a314710
to
a0bf285
Compare
About local validation:
About template names, the alternative I proposed (even on my PR) is to pre-define a set of constants that users can use to easily type a template's name. i.e. |
For now but one could be added later and now the SDK is out of date. I'm just thinking about that as a pattern for the rest of the SDK. We're duplicating the validation that's happening on the server to save a handful of API calls at the cost of a lot of up-front and maintenance work. $0.02
Correct, those are already there. I could require a template name for |
a0bf285
to
3e612ad
Compare
False! If the server adds a new required parameter, the validation that now fails is the remote one and not the local. Yes, SDK is out of date and will need to be updated if you want the validation to detect that locally first. But that's not stopping people from calling this method. TBH I find this really useful! Otherwise every API/Entity would rely on a single generic class that receives a) the method, b) the path and c) the data/body. What's the point on having separate classes for them then? Would like to hear from someone else too (@cocojoe?).
But they are not being null-checked. Would it be fine if the request fires with a null template name? |
@@ -30,7 +30,7 @@ | |||
} | |||
}, | |||
"scripts": { | |||
"test": "vendor/bin/phpunit", | |||
"test": "SHELL_INTERACTIVE=1 vendor/bin/phpunit --colors=always --verbose ", |
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.
Allows for additional data after the command (like path to a specific test) and makes the output a little more useful
* @param array $data | ||
* An array of data to use for the new email, including a valid `template`. | ||
* See docs link below for required fields. | ||
* @param string $template - the template name to create |
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.
I'd add "You can add any of the constants defined in this file" or something like that.. suggesting the users an easy way to access those values.. BTW this applies to all methods on this entity
$data = [ | ||
'template' => (string) $template, | ||
'from' => (string) $from, | ||
'body' => (string) $body, |
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.
How does validation work here? And what happens since some of the params have a default value?
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.
Anything with a default value is not required by the API, only template
and from
. The object you POST needs to have those keys but they can be empty.
$template
and $from
are both required for the method (IOW: need to have something passed in) but nothing beyond that. Looking through the rest of the SDK, this is how validation is handled for other endpoints. I could check for empty()
but it's a bit of an edge case if someone sees that the param is required but passes in an empty string or null
or something.
If it was empty, I'd have to throw
and exception of some kind. Since this is a new method, I could do that even though none of the other ones do and make that a pattern to follow. If that template is empty, the HTTP client would throw an exception anyways so not a complete surprise.
I'm happy with this as-is but also open to more discussion.
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.
I'm looking at the schema definition right now.. You shouldn't be setting values in the SDK if they are missing just because "need to have something passed in". Of course you'll need to pass something, that's why it's required. But let it fail gracefully! If the parameters are required, make the user manually set them, even if they want to set an empty string. The only exception I find for this is the syntax
field which is there for backwards (read) compatibility and liquid
should be used always as value when creating new templates.
Think of receiving an email in your personal inbox which doesn't have a subject set or which doesn't have a body at all. Would that make sense to you as a user of that Application? Don't you want to make sure that users of this SDK use the API well?
9310228
to
b4d17c4
Compare
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.
LGTM
5749cc1
to
fac955b
Compare
…iClient method for ease of use
…ate, better tests
84df7f1
to
fefdf6e
Compare
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
GET
,PATCH
, andPOST
for email templates API