module Camper::Client::CommentsAPI
Defines methods related to comments. @see github.com/basecamp/bc3-api/blob/master/sections/comments.md
Public Instance Methods
Get a comment within a resource
@example
client.comment(todo, 10)
@example
client.comment(my_message, '23')
@param resource [Resource] resource to get the comment from @param comment_id [Integer|String] id of comment ot retrieve @return [Resource] @raise [Error::ResourceCannotBeCommented] if the resource doesn't support comments @see github.com/basecamp/bc3-api/blob/master/sections/comments.md#get-a-comment
# File lib/camper/api/comments.rb, line 35 def comment(resource, comment_id) raise Error::ResourceCannotBeCommented, resource unless resource.can_be_commented? bucket_id = resource.bucket.id get("/buckets/#{bucket_id}/comments/#{comment_id}") end
Get a paginated list of active comments for a given resource
@example
client.comments(todo)
@param resource [Resource] resource to gets the comments from @return [PaginatedResponse<Resource>] @raise [Error::ResourceCannotBeCommented] if the resource doesn't support comments @see github.com/basecamp/bc3-api/blob/master/sections/comments.md#get-comments
# File lib/camper/api/comments.rb, line 17 def comments(resource) raise Error::ResourceCannotBeCommented, resource unless resource.can_be_commented? get(resource.comments_url, override_path: true) end
Create a new comment for a given resource
@example
client.create_comment(my_message, 'We are ready to start the project')
@param resource [Resource] resource to create the comment on @param content [String] content of the comment @return [Resource] @raise [Error::ResourceCannotBeCommented] if the resource doesn't support comments @see github.com/basecamp/bc3-api/blob/master/sections/comments.md#create-a-comment
# File lib/camper/api/comments.rb, line 53 def create_comment(resource, content) raise Error::ResourceCannotBeCommented, resource unless resource.can_be_commented? post(resource.comments_url, override_path: true, body: { content: content }) end
Trash a comment
it calls the trash_recording endpoint under the hood
@example
client.trash_comment(current_comment)
@param comment [Resource] the comment to be trashed @see github.com/basecamp/bc3-api/blob/master/sections/recordings.md#trash-a-recording
# File lib/camper/api/comments.rb, line 82 def trash_comment(comment) trash_recording(comment) end
Update the content in a comment
@example
client.update_comment(comment, 'Fixed grammar mistakes')
@param comment [Resource] comment to modify @param content [String] new content of the comment @return [Resource] @see github.com/basecamp/bc3-api/blob/master/sections/comments.md#update-a-comment
# File lib/camper/api/comments.rb, line 68 def update_comment(comment, content) bucket_id = comment.bucket.id put("/buckets/#{bucket_id}/comments/#{comment.id}", body: { content: content }) end