Class: TrackerApi::Endpoints::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/tracker_api/endpoints/comment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Comment

Returns a new instance of Comment.



6
7
8
# File 'lib/tracker_api/endpoints/comment.rb', line 6

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/tracker_api/endpoints/comment.rb', line 4

def client
  @client
end

Instance Method Details

#create(project_id, story_id: nil, epic_id: nil, params: {}) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
# File 'lib/tracker_api/endpoints/comment.rb', line 10

def create(project_id, story_id: nil, epic_id: nil, params: {})
  raise ArgumentError, 'One of story id or epic id must be provided.' if story_id.nil? && epic_id.nil?

  comment_target_slug = !story_id.nil? ? "stories/#{story_id}" : "epics/#{epic_id}"

  data = client.post("/projects/#{project_id}/#{comment_target_slug}/comments", params: params).body
  Resources::Comment.new({ client: client, project_id: project_id }.merge(data))
end

#delete(comment) ⇒ Object

Raises:

  • (ArgumentError)


35
36
37
38
39
40
41
# File 'lib/tracker_api/endpoints/comment.rb', line 35

def delete(comment)
  raise ArgumentError, 'Valid comment required to update.' unless comment.instance_of?(Resources::Comment)

  comment_target_slug = !comment.story_id.nil? ? "stories/#{comment.story_id}" : "epics/#{comment.epic_id}"

  client.delete("/projects/#{comment.project_id}/#{comment_target_slug}/comments/#{comment.id}").body
end

#update(comment, params = {}) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tracker_api/endpoints/comment.rb', line 19

def update(comment, params={})
  raise ArgumentError, 'Valid comment required to update.' unless comment.instance_of?(Resources::Comment)

  comment_target_slug = !comment.story_id.nil? ? "stories/#{comment.story_id}" : "epics/#{comment.epic_id}"

  path = "/projects/#{comment.project_id}/#{comment_target_slug}/comments/#{comment.id}"
  if params.represented.file_attachment_ids_to_add.present? || params.represented.file_attachment_ids_to_remove.present?
    path += "?fields=:default,file_attachments"
  end
  data = client.put(path, params: params).body

  comment.attributes = data
  comment.clean!
  comment
end