Class: API::Templates::Service
- Inherits:
-
Object
- Object
- API::Templates::Service
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/api/templates/service.rb
Constant Summary collapse
- MESSAGE_TEMPLATES_PATH =
T.let("message_templates", ::String)
Instance Method Summary collapse
- #create(name:, category:, language:, components:) ⇒ Object
- #delete(name:, template_id: nil) ⇒ Object
-
#initialize(config:) ⇒ Service
constructor
A new instance of Service.
- #list(limit: 20) ⇒ Object
- #update(template_id:, category:, components:) ⇒ Object
Constructor Details
#initialize(config:) ⇒ Service
Returns a new instance of Service.
14 15 16 |
# File 'lib/api/templates/service.rb', line 14 def initialize(config:) @config = config end |
Instance Method Details
#create(name:, category:, language:, components:) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/api/templates/service.rb', line 39 def create(name:, category:, language:, components:) allow_category_change = true payload = { "name": name, "category": category.serialize, "allow_category_change": allow_category_change, "language": language, "components": components.map(&:serialize) } response = with_error_handling { templates_client.post(body: payload) } ::CloudWaba::Models::Templates::Response.parse(response: response) end |
#delete(name:, template_id: nil) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/api/templates/service.rb', line 79 def delete(name:, template_id: nil) params = { name: name } params[:hsm_id] = template_id unless template_id.nil? response = with_error_handling { templates_client.delete(params: params) } parsed_response = JSON.parse(response.body.to_s) parsed_response["success"] || false end |
#list(limit: 20) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/api/templates/service.rb', line 22 def list(limit: 20) fields = "id,name,category,language,status" response = with_error_handling { templates_client.get(params: { fields: fields, limit: limit }) } parsed_response = JSON.parse(response.body.to_s) templates = parsed_response["data"].map{|hash| ::CloudWaba::Models::Templates::Response.parse(template_hash: hash)} ::CloudWaba::Models::Templates::List.new(templates: templates, paging: parsed_response["paging"]) end |
#update(template_id:, category:, components:) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/api/templates/service.rb', line 61 def update(template_id:, category:, components:) template_client = template_endpoint(template_id: template_id) payload = { "category": category.serialize, "components": components.map(&:serialize) } response = with_error_handling { client.post(body: payload) } parsed_response = JSON.parse(response.body.to_s) parsed_response["success"] || false end |