README.md in notifications-ruby-client-2.0.0 vs README.md in notifications-ruby-client-2.1.0
- old
+ new
@@ -27,17 +27,19 @@
Text message:
```ruby
require 'notifications/client/response_notification'
-sms = client.send_sms(phone_number: number,
- template_id: template_id,
- personalisation: Hash[name: "name",
- year: "2016",
- ],
- reference: "your_reference_string"
- ) # => Notifications::Client::ResponseNotification
+sms = client.send_sms(
+ phone_number: number,
+ template_id: template_id,
+ personalisation: {
+ name: "name",
+ year: "2016",
+ }
+ reference: "your_reference_string"
+) # => Notifications::Client::ResponseNotification
```
<details>
<summary>
Response
@@ -116,17 +118,19 @@
Email:
```ruby
require 'notifications/client/response_notification'
-email = client.send_email(email_address: email_address,
- template: template_id,
- personalisation: Hash[name: "name",
- year: "2016"
- ],
- reference: "your_reference_string"
- ) # => Notifications::Client::ResponseNotification
+email = client.send_email(
+ email_address: email_address,
+ template_id: template_id,
+ personalisation: {
+ name: "name",
+ year: "2016"
+ },
+ reference: "your_reference_string"
+) # => Notifications::Client::ResponseNotification
```
<details>
<summary>
Response
@@ -137,11 +141,11 @@
```ruby
email => Notifications::Client::ResponseNotification
email.id # => uuid for the notification
email.reference # => Reference string you supplied in the request
-email.type # => sms
+email.type # => email
email.status # => status of the message "created|pending|sent|delivered|permanent-failure|temporary-failure"
email.content # => Hash containing body => the message sent to the recipient, with placeholders replaced.
# subject => subject of the message sent to the recipient, with placeholders replaced.
# from_email => the from email of your service found **Settings** page
email.template # => Hash containing id => id of the template
@@ -220,14 +224,14 @@
#### `personalisation`
If the template has placeholders you need to provide their values as a Hash, for example:
```ruby
- personalisation=Hash[
- 'first_name': 'Amala',
- 'reference_number': '300241',
- ]
+ personalisation: {
+ 'first_name' => 'Amala',
+ 'reference_number' => '300241',
+ }
```
You can omit this argument if the template does not contain placeholders.
### Get the status of one message
@@ -304,29 +308,30 @@
</details>
### Get the status of all messages
```ruby
# See section below for a description of the arguments.
-args = Hash[
- 'template_type', 'sms',
- 'status', 'failed',
- 'reference', 'your reference string'
- 'olderThanId', 'e194efd1-c34d-49c9-9915-e4267e01e92e' # => Notifications::Client::Notification
- ]
+args = {
+ 'template_type' => 'sms',
+ 'status' => 'failed',
+ 'reference' => 'your reference string'
+ 'olderThanId' => 'e194efd1-c34d-49c9-9915-e4267e01e92e' # => Notifications::Client::Notification
+}
notifications = client.get_notifications(args)
```
<details>
<summary>
Response
</summary>
If the request is successful a `Notifications::Client::NotificationsCollection` is returned.
```ruby
-notifications.links # => Hash containing current=>"/notifications?template_type=sms&status=delivered"
-next=>"/notifications?other_than=last_id_in_list&template_type=sms&status=delivered"}
+notifications.links # => Hash containing current => "/notifications?template_type=sms&status=delivered"
+ # next => "/notifications?other_than=last_id_in_list&template_type=sms&status=delivered"
notifications.collection # => [] (array of notification objects)
```
+
Otherwise the client will raise a `Notifications::Client::RequestError`:
<table>
<thead>
<tr>
<th>error.status_code</th>
@@ -339,11 +344,11 @@
<pre>400</pre>
</td>
<td>
<pre>
[{
- 'error': 'ValidationError',
+ 'error': 'ValidationError',
'message': 'bad status is not one of [created, sending, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure]'
}]
</pre>
</td>
</tr>
@@ -397,5 +402,235 @@
#### `olderThanId`
You can get the notifications older than a given `Notification.id`.
You can omit this argument to ignore this filter.
+
+
+## Get a template by ID
+This will return the latest version of the template. Use [getTemplateVersion](#get-a-template-by-id-and-version) to retrieve a specific template version.
+
+```ruby
+template = client.get_template_by_id(template_id)
+```
+
+<details>
+<summary>
+Response
+</summary>
+
+```Ruby
+template.id # => uuid for the template
+template.type # => type of template one of email|sms|letter
+template.created_at # => date and time the template was created
+template.updated_at # => date and time the template was last updated, may be null if version 1
+template.created_by # => email address of the person that created the template
+template.version # => version of the template
+template.body # => content of the template
+template.subject # => subject for email templates, will be empty for other template types
+```
+
+Otherwise the client will raise a `Notifications::Client::RequestError`.
+
+<table>
+<thead>
+<tr>
+<th>message</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
+<pre>
+Status code: 404 {
+"errors":
+[{
+ "error": "NoResultFound",
+ "message": "No result found"
+}]
+}
+</pre>
+<pre>
+Status code: 400 {
+"errors":
+[{
+ "error": "ValidationError",
+ "message": "id is not a valid UUID"
+}]
+}
+</pre>
+</tbody>
+</table>
+</details>
+
+### Arguments
+
+#### `templateId`
+The template id is visible on the template page in the application.
+
+
+## Get a template by ID and version
+This will return the template for the given id and version.
+
+```ruby
+Template template = client.get_template_version(template_id template_id, version)
+```
+
+<details>
+<summary>
+Response
+</summary>
+
+```Ruby
+template.id # => uuid for the template
+template.type # => type of template one of email|sms|letter
+template.created_at # => date and time the template was created
+template.updated_at # => date and time the template was last updated, may be null if version 1
+template.created_by # => email address of the person that created the template
+template.version # => version of the template
+template.body # => content of the template
+template.subject # => subject for email templates, will be empty for other template types
+```
+
+Otherwise the client will raise a `Notifications::Client::RequestError`.
+
+<table>
+<thead>
+<tr>
+<th>message</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
+<pre>
+Status code: 404 {
+"errors":
+[{
+ "error": "NoResultFound",
+ "message": "No result found"
+}]
+}
+</pre>
+<pre>
+Status code: 400 {
+"errors":
+[{
+ "error": "ValidationError",
+ "message": "id is not a valid UUID"
+}]
+}
+</pre>
+</tbody>
+</table>
+</details>
+
+### Arguments
+
+#### `templateId`
+The template id is visible on the template page in the application.
+
+#### `version`
+A history of the template is kept. There is a link to `See previous versions` on the template page in the application.
+
+## Get all templates
+This will return the latest version of each template for your service.
+
+```ruby
+args = {
+ 'template_type' => 'sms'
+}
+templates = client.get_all_templates(args)
+```
+
+<details>
+<summary>
+Response
+</summary>
+
+```ruby
+ TemplateCollection templates;
+```
+If the response is successful, a TemplateCollection is returned.
+
+If no templates exist for a template type or there no templates for a service, the templates list will be empty.
+
+Otherwise the client will raise a `Notifications::Client::RequestError`.
+
+
+</details>
+
+### Arguments
+
+#### `templateType`
+You can filter the templates by the following options:
+
+* `email`
+* `sms`
+* `letter`
+You can omit this argument to ignore this filter.
+
+
+## Generate a preview template
+This will return the contents of a template with the placeholders replaced with the given personalisation.
+```ruby
+templatePreview = client.generate_template_preview(template_id: template_id,
+ personalisation: {
+ name: "name",
+ year: "2016",
+ })
+```
+
+<details>
+<summary>
+Response
+</summary>
+
+
+```Ruby
+template.id # => uuid for the template
+template.version # => version of the template
+template.body # => content of the template
+template.subject # => subject for email templates, will be empty for other template types
+```
+
+
+Otherwise a `Notifications::Client::RequestError` is thrown.
+<table>
+<thead>
+<tr>
+<th>message</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
+<pre>
+Status code: 404 {
+"errors":
+[{
+ "error": "NoResultFound",
+ "message": "No result found"
+}]
+}
+</pre>
+<pre>
+Status code: 400 {
+"errors":
+[{
+ "error": "ValidationError",
+ "message": "id is not a valid UUID"
+}]
+}
+</pre>
+</tbody>
+</table>
+
+</details>
+
+### Arguments
+
+#### `templateId`
+The template id is visible on the template page in the application.
+
+#### `personalisation`
+If a template has placeholders, you need to provide their values. `personalisation` can be an empty or null in which case no placeholders are provided for the notification.