Sha256: 36ae3ca2a476d3c342793dbe4cfe2095968bad9dbab191d263c1167ea6415dc3

Contents?: true

Size: 1.3 KB

Versions: 7

Compression:

Stored size: 1.3 KB

Contents

class Zendesk2::Client::Category < Zendesk2::Model
  PARAMS = %w[id name description position]

  identity  :id, type: :integer         # ro[yes] mandatory[no]  Automatically assigned during creation
  attribute :url, type: :string         # ro[yes] mandatory[no]  The API url of this category
  attribute :name, type: :string        # ro[no]  mandatory[yes] The name of the category
  attribute :description, type: :string # ro[no]  mandatory[no]  The description of the category
  attribute :position, type: :integer   # ro[no]  mandatory[no]  The position of this category relative to other categories
  attribute :created_at, type: :date    # ro[yes] mandatory[no]  The time the category was created
  attribute :updated_at, type: :date    # ro[yes] mandatory[no]  The time of the last update of the category

  def destroy
    requires :id

    connection.destroy_category("id" => self.id)
  end

  def destroyed?
    !self.reload
  end

  def save!
    data = if new_record?
             requires :name
             connection.create_category(params).body["category"]
           else
             requires :id
             connection.update_category(params).body["category"]
           end
    merge_attributes(data)
  end

  private

  def params
    Cistern::Hash.slice(Zendesk2.stringify_keys(attributes), *PARAMS)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
zendesk2-0.1.2 lib/zendesk2/client/models/category.rb
zendesk2-0.1.1 lib/zendesk2/client/models/category.rb
zendesk2-0.1.0 lib/zendesk2/client/models/category.rb
zendesk2-0.0.23 lib/zendesk2/client/models/category.rb
zendesk2-0.0.22 lib/zendesk2/client/models/category.rb
zendesk2-0.0.20 lib/zendesk2/client/models/category.rb
zendesk2-0.0.19 lib/zendesk2/client/models/category.rb