Sha256: c4fe9010c9639fbbe22bf71ed0c09c289718e364cbabfef831572e51942ebda6

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true
class Zendesk2::Category
  include Zendesk2::Model

  # @return [Integer] Automatically assigned during creation
  identity :id, type: :integer

  # @return [Time] The time the category was created
  attribute :created_at, type: :time
  # @return [String] The description of the category
  attribute :description, type: :string
  # @return [String] The name of the category
  attribute :name, type: :string
  # @return [Integer] The position of this category relative to other categories
  attribute :position, type: :integer
  # @return [Time] The time of the last update of the category
  attribute :updated_at, type: :time
  # @return [String] The API url of this category
  attribute :url, type: :string

  def destroy!
    requires :identity

    cistern.destroy_category('category' => { 'id' => identity })
  end

  def save!
    data = if new_record?
             requires :name

             cistern.create_category(params).body['category']
           else
             requires :identity

             cistern.update_category(params).body['category']
           end

    merge_attributes(data)
  end

  protected

  def params
    {
      'category' => Cistern::Hash.slice(
        Zendesk2.stringify_keys(attributes),
        *Zendesk2::CreateCategory.accepted_attributes
      ),
    }
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
zendesk2-1.15.0 lib/zendesk2/category.rb
zendesk2-1.13.1 lib/zendesk2/category.rb
zendesk2-1.13.0 lib/zendesk2/category.rb
zendesk2-1.12.0 lib/zendesk2/category.rb
zendesk2-1.11.0 lib/zendesk2/category.rb
zendesk2-1.10.0 lib/zendesk2/category.rb