Class: Anypost::Resources::Templates
- Defined in:
- lib/anypost/resources/templates.rb
Overview
Operations on the ‘/templates` endpoints, including the draft/publish flow.
Instance Method Summary collapse
-
#create(params) ⇒ Object
Create a template.
-
#delete(id) ⇒ Object
Permanently delete a template.
-
#delete_draft(id) ⇒ Object
Discard the template’s draft without touching published content.
-
#duplicate(id, params = {}) ⇒ Object
Copy a template.
-
#get(id) ⇒ Object
Retrieve a template, including its published content.
-
#get_draft(id) ⇒ Object
Retrieve the template’s unpublished draft.
-
#list(params = {}) ⇒ Object
List the team’s templates, newest-first.
-
#publish(id) ⇒ Object
Promote the draft into the published slot, consuming the draft.
-
#update(id, params) ⇒ Object
Update a template’s ‘name`.
-
#update_draft(id, params) ⇒ Object
Create or update the template’s draft.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Anypost::Resources::Base
Instance Method Details
#create(params) ⇒ Object
Create a template. It starts unpublished — publish it before sending.
13 14 15 |
# File 'lib/anypost/resources/templates.rb', line 13 def create(params) request_object(:post, "/templates", body: params) end |
#delete(id) ⇒ Object
Permanently delete a template.
28 29 30 31 |
# File 'lib/anypost/resources/templates.rb', line 28 def delete(id) @http.request(:delete, "/templates/#{encode(id)}") nil end |
#delete_draft(id) ⇒ Object
Discard the template’s draft without touching published content.
51 52 53 54 |
# File 'lib/anypost/resources/templates.rb', line 51 def delete_draft(id) @http.request(:delete, "/templates/#{encode(id)}/draft") nil end |
#duplicate(id, params = {}) ⇒ Object
Copy a template. The copy starts unpublished with a draft seeded from the source’s current editable content, and must be published before sending.
35 36 37 38 |
# File 'lib/anypost/resources/templates.rb', line 35 def duplicate(id, params = {}) request_object(:post, "/templates/#{encode(id)}/duplicate", body: params.empty? ? nil : params) end |
#get(id) ⇒ Object
Retrieve a template, including its published content.
18 19 20 |
# File 'lib/anypost/resources/templates.rb', line 18 def get(id) request_object(:get, "/templates/#{encode(id)}") end |
#get_draft(id) ⇒ Object
Retrieve the template’s unpublished draft. Raises not_found if none exists.
41 42 43 |
# File 'lib/anypost/resources/templates.rb', line 41 def get_draft(id) request_object(:get, "/templates/#{encode(id)}/draft") end |
#list(params = {}) ⇒ Object
List the team’s templates, newest-first.
8 9 10 |
# File 'lib/anypost/resources/templates.rb', line 8 def list(params = {}) paginate("/templates", {limit: params[:limit], after: params[:after]}) end |
#publish(id) ⇒ Object
Promote the draft into the published slot, consuming the draft.
57 58 59 |
# File 'lib/anypost/resources/templates.rb', line 57 def publish(id) request_object(:post, "/templates/#{encode(id)}/publish") end |
#update(id, params) ⇒ Object
Update a template’s ‘name`. Body content lives on the draft.
23 24 25 |
# File 'lib/anypost/resources/templates.rb', line 23 def update(id, params) request_object(:patch, "/templates/#{encode(id)}", body: params) end |
#update_draft(id, params) ⇒ Object
Create or update the template’s draft. Idempotent upsert; published content untouched.
46 47 48 |
# File 'lib/anypost/resources/templates.rb', line 46 def update_draft(id, params) request_object(:patch, "/templates/#{encode(id)}/draft", body: params) end |