Module: RubyConversations::Concerns::ConversationTemplates
- Extended by:
- ActiveSupport::Concern
- Included in:
- RubyConversations::ConversationManager
- Defined in:
- lib/ruby_conversations/concerns/conversation_templates.rb
Overview
Handles template-related functionality for Conversation
Instance Method Summary collapse
-
#all_templates ⇒ Array<Hash>
Fetch metadata for all available templates.
-
#template_for(template_name) ⇒ Hash
Fetch template metadata for a given template name.
Instance Method Details
#all_templates ⇒ Array<Hash>
Fetch metadata for all available templates
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby_conversations/concerns/conversation_templates.rb', line 28 def all_templates begin templates_data = RubyConversations.client.fetch_all_conversation_templates rescue RubyConversations::ClientError => e raise RubyConversations::TemplateNotFoundError, 'Failed to fetch templates' if e.status_code == 404 raise e end return [] unless templates_data.is_a?(Array) templates_data.map { |template_data| (template_data) }.compact end |
#template_for(template_name) ⇒ Hash
Fetch template metadata for a given template name
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ruby_conversations/concerns/conversation_templates.rb', line 15 def template_for(template_name) begin template_data = RubyConversations.client.fetch_conversation_template(template_name) rescue RubyConversations::ClientError => e raise RubyConversations::TemplateNotFoundError, "Template #{template_name} not found" if e.status_code == 404 raise e end (template_data) end |