Class: TrackerApi::Resources::Comment

Inherits:
Object
  • Object
show all
Includes:
Shared::Base
Defined in:
lib/tracker_api/resources/comment.rb

Defined Under Namespace

Classes: UpdateRepresenter

Instance Method Summary collapse

Methods included from Shared::Base

included

Instance Method Details

#attachments(reload: false) ⇒ Array[FileAttachments]

Provides a list of all the attachments on the comment.

Returns:

  • (Array[FileAttachments])


62
63
64
65
66
67
68
# File 'lib/tracker_api/resources/comment.rb', line 62

def attachments(reload: false)
  if !reload && @file_attachments.present?
    @file_attachments
  else
    @file_attachments = Endpoints::Attachment.new(client).get(self)
  end
end

#create_attachments(params) ⇒ Comment

Returns newly created Comment.

Parameters:

  • params (Hash)

    attributes to create the comment with

Returns:

  • (Comment)

    newly created Comment



48
49
50
51
# File 'lib/tracker_api/resources/comment.rb', line 48

def create_attachments(params)
  self.file_attachment_ids_to_add = Endpoints::Attachments.new(client).create(self, params[:files]).collect(&:id)
  save
end

#deleteObject

Raises:

  • (ArgumentError)


40
41
42
43
44
# File 'lib/tracker_api/resources/comment.rb', line 40

def delete
  raise ArgumentError, 'Cannot delete a comment with an unknown story_id or epic_id.' if story_id.nil? && epic_id.nil?

  Endpoints::Comment.new(client).delete(self)
end

#delete_attachments(attachment_ids = nil) ⇒ Object



53
54
55
56
# File 'lib/tracker_api/resources/comment.rb', line 53

def delete_attachments(attachment_ids = nil)
  self.file_attachment_ids_to_remove = attachment_ids || attachments.collect(&:id)
  save
end

#saveObject

Raises:

  • (ArgumentError)


34
35
36
37
38
# File 'lib/tracker_api/resources/comment.rb', line 34

def save
  raise ArgumentError, 'Cannot update a comment with an unknown story_id or epic_id.' if story_id.nil? && epic_id.nil?

  Endpoints::Comment.new(client).update(self, UpdateRepresenter.new(Comment.new(self.dirty_attributes)))
end