module DesignHuddle class Template attr_accessor :template_id, :template_code, :template_title, :default_social_post_text, :date_created, :date_updated, :project_count, :primary_template_category, :primary_template_category_item, :source_project, :internal_project_id, :page_count, :preview_url, :thumbnail_url, :media_type, :template_status, :user_groups_match_type, :dimensions def initialize(template) @template_id = template["template_id"] @template_code = template["template_code"] @template_title = template["template_title"] @default_social_post_text = template["default_social_post_text"] @date_created = template["date_created"] @date_updated = template["date_updated"] @project_count = template["project_count"] @primary_template_category = template["primary_template_category"] @primary_template_category_item = template["primary_template_category_item"] @source_project = template["source_project"] @internal_project_id = template["internal_project_id"] @page_count = template["page_count"] @preview_url = template["preview_url"] @thumbnail_url = template["thumbnail_url"] @media_type = template["media_type"] @template_status = template["template_status"] @user_groups_match_type = template["user_groups_match_type"] @dimensions = template["dimensions"] self end def reload initialize(Template.fetch(template_id)) end def update(**args) DesignHuddle.client.call( method: :patch, path: "/partners/api/templates/#{template_id}", payload: args.to_json ) end def delete DesignHuddle.client.call( method: :delete, path: "/partners/api/templates/#{template_id}" ) end def self.upsert(template_id_or_code, **args) DesignHuddle.client.call( method: :put, path: "/partners/api/templates/#{template_id_or_code}", payload: args.to_json ) end def self.publish(**args) DesignHuddle.client.call( method: :post, path: "/partners/api/templates", payload: args.to_json ) end def self.create_template_customization_object(**args) # TODO: Validate this works for the admin API DesignHuddle.client.call( method: :post, path: "/partners/api/templates/customization-objects", payload: args.to_json ) end def self.list(**_args) DesignHuddle.client.call(path: "/partners/api/templates")["data"]["items"].map do |template| Template.new(template) end end def self.retrieve(template_id_or_code) Template.new(Template.fetch(template_id_or_code)) end def self.retrieve_publish_progress(job_id) DesignHuddle.client.call(path: "/partners/api/template/jobs/#{job_id}")["data"] end def self.fetch(template_id_or_code) DesignHuddle.client.call(path: "/partners/api/templates/#{template_id_or_code}")["data"] end end end