module Eco module API class UseCases class OozeSamples module Helpers # set of helpers to create entries from a template module Creatable module InstanceMethods private def creating_new_page(draft_reference = "new entry", template_id:) page_id = nil drafting_entry(template_id) do |draft| yield(draft) if block_given? if page_id = create_entry(draft, reference: draft_reference) log(:info) { "Page '#{page_id}' created successfully -- #{draft_reference}" } elsif options.dig(:dry_run) log(:info) { "Simulated launch for #{draft_reference}" } end end page_id end # @return [Page] a draft of `template_id` (still not saved) def drafting_entry(template_id) raise ArgumentError, "Expecting block, but not given" unless block_given? draft = apiv2.pages.get_new(template_id) yield(draft) end # Does the actual creation of the entry def create_entry(draft, reference: "new entry from #{draft&.template_id}") with_rescue(reference) do if result = create_ooze(draft, template_id: draft.template_id) return result.page_id end end end end class << self def included(base) super validate_base_type!(base) base.include(InstanceMethods) end def validate_base_type!(base) return super if defined?(super) msg = "#{self} can only be included in Eco::API::UseCases::OozeSamples::RegisterUpdateCase" msg << "\nCan't be included in #{base}" raise LoadError, msg unless base <= Eco::API::UseCases::OozeSamples::RegisterUpdateCase true end end end end end end end end