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.
12 13 14 |
# File 'lib/api/templates/service.rb', line 12 def initialize(config:) @config = config end |
Instance Method Details
#create(name:, category:, language:, components:) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/api/templates/service.rb', line 37 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
77 78 79 80 81 82 83 84 85 |
# File 'lib/api/templates/service.rb', line 77 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
20 21 22 23 24 25 26 27 |
# File 'lib/api/templates/service.rb', line 20 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
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/api/templates/service.rb', line 59 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 |