Class: Sendly::TemplatesResource
- Inherits:
-
Object
- Object
- Sendly::TemplatesResource
- Defined in:
- lib/sendly/templates_resource.rb
Instance Method Summary collapse
- #clone(id, name: nil) ⇒ Object
- #create(name:, body:, locale: nil, is_published: nil) ⇒ Object
- #delete(id) ⇒ Object
- #generate(description:, category: nil) ⇒ Object
- #get(id) ⇒ Object
-
#initialize(client) ⇒ TemplatesResource
constructor
A new instance of TemplatesResource.
- #list(limit: nil, type: nil, locale: nil) ⇒ Object
- #publish(id) ⇒ Object
- #unpublish(id) ⇒ Object
- #update(id, name: nil, body: nil, locale: nil, is_published: nil) ⇒ Object
Constructor Details
#initialize(client) ⇒ TemplatesResource
Returns a new instance of TemplatesResource.
54 55 56 |
# File 'lib/sendly/templates_resource.rb', line 54 def initialize(client) @client = client end |
Instance Method Details
#clone(id, name: nil) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/sendly/templates_resource.rb', line 108 def clone(id, name: nil) body = {} body[:name] = name if name response = @client.post("/templates/#{id}/clone", body) Template.new(response) end |
#create(name:, body:, locale: nil, is_published: nil) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/sendly/templates_resource.rb', line 74 def create(name:, body:, locale: nil, is_published: nil) request_body = { name: name, body: body } request_body[:locale] = locale if locale request_body[:isPublished] = is_published unless is_published.nil? response = @client.post("/verify/templates", request_body) Template.new(response) end |
#delete(id) ⇒ Object
94 95 96 |
# File 'lib/sendly/templates_resource.rb', line 94 def delete(id) @client.delete("/verify/templates/#{id}") end |
#generate(description:, category: nil) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/sendly/templates_resource.rb', line 115 def generate(description:, category: nil) body = { description: description } body[:category] = category if category response = @client.post("/templates/generate", body) GeneratedTemplate.new(response) end |
#get(id) ⇒ Object
69 70 71 72 |
# File 'lib/sendly/templates_resource.rb', line 69 def get(id) response = @client.get("/verify/templates/#{id}") Template.new(response) end |
#list(limit: nil, type: nil, locale: nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/sendly/templates_resource.rb', line 58 def list(limit: nil, type: nil, locale: nil) params = {} params[:limit] = limit if limit params[:type] = type if type params[:locale] = locale if locale response = @client.get("/verify/templates", params) templates = (response["templates"] || []).map { |t| Template.new(t) } { templates: templates, pagination: response["pagination"] } end |
#publish(id) ⇒ Object
98 99 100 101 |
# File 'lib/sendly/templates_resource.rb', line 98 def publish(id) response = @client.post("/verify/templates/#{id}/publish") Template.new(response) end |
#unpublish(id) ⇒ Object
103 104 105 106 |
# File 'lib/sendly/templates_resource.rb', line 103 def unpublish(id) response = @client.post("/verify/templates/#{id}/unpublish") Template.new(response) end |
#update(id, name: nil, body: nil, locale: nil, is_published: nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/sendly/templates_resource.rb', line 83 def update(id, name: nil, body: nil, locale: nil, is_published: nil) request_body = {} request_body[:name] = name if name request_body[:body] = body if body request_body[:locale] = locale if locale request_body[:isPublished] = is_published unless is_published.nil? response = @client.patch("/verify/templates/#{id}", request_body) Template.new(response) end |