Class: TrackerApi::Endpoints::Comments

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Comments

Returns a new instance of Comments.



6
7
8
# File 'lib/tracker_api/endpoints/comments.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/comments.rb', line 4

def client
  @client
end

Instance Method Details

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

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tracker_api/endpoints/comments.rb', line 10

def get(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.paginate("/projects/#{project_id}/#{comment_target_slug}/comments", params: params)
  raise Errors::UnexpectedData, 'Array of comments expected' unless data.is_a? Array

  data.map do |comment|
    Resources::Comment.new({
      client: client,
      project_id: project_id
    }.merge(comment))
  end
end