Class: PivotalApi::Endpoints::Comments

Inherits:
Object
  • Object
show all
Defined in:
lib/pivotal_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/pivotal_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/pivotal_api/endpoints/comments.rb', line 4

def client
  @client
end

Instance Method Details

#all(project_id, story_id, params = {}) ⇒ Object



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

def all(project_id, story_id, params={})
  data = client.paginate("/projects/#{project_id}/stories/#{story_id}/comments", params: params)
  raise PivotalApi::Errors::UnexpectedData, 'Array of stories expected' unless data.is_a? Array

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

#create(project_id, story_id, params) ⇒ Object



25
26
27
28
29
# File 'lib/pivotal_api/endpoints/comments.rb', line 25

def create(project_id, story_id, params)
  data = client.post("/projects/#{project_id}/stories/#{story_id}/comments", params: params).body

  Resources::Comment.new({ project_id: project_id }.merge(data))
end

#delete(project_id, story_id, id) ⇒ Object



37
38
39
# File 'lib/pivotal_api/endpoints/comments.rb', line 37

def delete(project_id, story_id, id)
  client.delete("/projects/#{project_id}/stories/#{story_id}/comments/#{id}").body
end

#get(project_id, story_id, id) ⇒ Object



19
20
21
22
23
# File 'lib/pivotal_api/endpoints/comments.rb', line 19

def get(project_id, story_id, id)
  data = client.get("/projects/#{project_id}/stories/#{story_id}/comments/#{id}").body

  Resources::Comment.new({ project_id: project_id }.merge(data))
end

#update(project_id, story_id, id, params) ⇒ Object



31
32
33
34
35
# File 'lib/pivotal_api/endpoints/comments.rb', line 31

def update(project_id, story_id, id, params)
  data = client.put("/projects/#{project_id}/stories/#{story_id}/comments/#{id}", params: params).body

  Resources::Comment.new({ }.merge(data))
end