Sha256: 2951d2b5324c90e3f662600c0253cb4a99ebd90c503b810bc3356497f824dd1b

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

class Zendesk2::Client::TopicComment < Cistern::Model
  extend Zendesk2::Attributes

  PARAMS = %w[id topic_id user_id body informative]

  identity  :id,          type: :integer # ro[integer] mandatory [yes] Automatically assigned upon creation
  attribute :url,         type: :string  # ro[yes]     mandatory [no]  The API url of this topic comment
  attribute :topic_id,    type: :integer # ro[no]      mandatory [yes] The id of the topic this comment was made on
  attribute :user_id,     type: :integer # ro[no]      mandatory [yes] The id of the user making the topic comment
  attribute :body,        type: :string  # ro[no]      mandatory [yes] The comment body
  attribute :informative, type: :boolean # ro[no]      mandatory [no]  If the comment has been flagged as informative
  attribute :attachments, type: :array   # ro[yes]     mandatory [no]  Attachments to this comment as Attachment objects
  attribute :created_at,  type: :date    # ro[yes]     mandatory [no]  The time the topic_comment was created
  attribute :updated_at,  type: :date    # ro[yes]     mandatory [no]  The time of the last update of the topic_comment

  assoc_accessor :user
  assoc_accessor :topic

  def destroy
    requires :identity

    connection.destroy_topic_comment("id" => self.identity)
  end

  def destroyed?
    !self.reload
  end

  def save
    data = if new_record?
             requires :topic_id, :user_id, :body
             connection.create_topic_comment(params).body["topic_comment"]
           else
             requires :identity
             connection.update_topic_comment(params).body["topic_comment"]
           end
    merge_attributes(data)
  end

  private

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
zendesk2-0.0.18 lib/zendesk2/client/models/topic_comment.rb
zendesk2-0.0.17 lib/zendesk2/client/models/topic_comment.rb
zendesk2-0.0.16 lib/zendesk2/client/models/topic_comment.rb