module DesignHuddle class Project attr_accessor :project_title, :page_count, :date_created, :date_updated, :last_edited, :last_opened, :template_count, :user, :project_id, :thumbnail_url, :media_type, :project_status, :dimensions def initialize(project) @project_title = project["project_title"] @page_count = project["page_count"] @date_created = project["date_created"] @date_updated = project["date_updated"] @last_edited = project["last_edited"] @last_opened = project["last_opened"] @template_count = project["template_count"] @user = project["user"] @project_id = project["project_id"] @thumbnail_url = project["thumbnail_url"] @media_type = project["media_type"] @project_status = project["project_status"] @dimensions = project["dimensions"] self end def reload initialize(Project.fetch(project_id)) end def update(**args) DesignHuddle.client.call( method: :patch, path: "/partners/api/projects/#{project_id}", payload: args.to_json ) end def delete DesignHuddle.client.call( method: :delete, path: "/partners/api/projects/#{project_id}" ) end def export(**args) DesignHuddle.client.call( method: :post, path: "/partners/api/projects/#{project_id}/export", payload: args.to_json ) end def retrieve_export_progress(job_id) Project.retrieve_export_progress(project_id: project_id, job_id: job_id) end def self.retrieve_export_progress(project_id:, job_id:) DesignHuddle.client.call( method: :get, path: "/projects/#{project_id}/export/jobs/#{job_id}" ) end def self.create(media_type: "print", dimensions: { width: 11, height: 6.5, unit_type: "in" }, template_id: nil, customizations: {}) DesignHuddle.client.call( method: :post, path: "/partners/api/projects", payload: { media_type: media_type, dimensions: dimensions, template_id: template_id, customizations: customizations }.to_json ) end def self.list(**_args) DesignHuddle.client.call(path: "/partners/api/projects")["data"]["items"].map do |project| Project.new(project) end end def self.retrieve(project_id, generate_latest_thumbnail = false) Project.new(Project.fetch(project_id, generate_latest_thumbnail)) end def self.fetch(project_id, generate_latest_thumbnail = false) DesignHuddle.client.call( path: "/partners/api/projects/#{project_id}", headers: { params: { generate_latest_thumbnail: generate_latest_thumbnail } } )["data"] end end end