Module: Camper::Client::CommentsAPI

Included in:
Camper::Client
Defined in:
lib/camper/api/comments.rb

Overview

Defines methods related to comments.

Instance Method Summary collapse

Instance Method Details

#comment(resource, comment_id) ⇒ Resource

Get a comment within a resource

Examples:

client.comment(todo, 10)
client.comment(my_message, '23')

Parameters:

  • resource (Resource)

    resource to get the comment from

  • comment_id (Integer|String)

    id of comment ot retrieve

Returns:

Raises:

See Also:



35
36
37
38
39
40
41
# 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

#comments(resource) ⇒ PaginatedResponse<Resource>

Get a paginated list of active comments for a given resource

Examples:

client.comments(todo)

Parameters:

  • resource (Resource)

    resource to gets the comments from

Returns:

Raises:

See Also:



17
18
19
20
21
# 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_comment(resource, content) ⇒ Resource

Create a new comment for a given resource

Examples:

client.create_comment(my_message, 'We are ready to start the project')

Parameters:

  • resource (Resource)

    resource to create the comment on

  • content (String)

    content of the comment

Returns:

Raises:

See Also:



53
54
55
56
57
# 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_comment(comment) ⇒ Object

Trash a comment

it calls the trash_recording endpoint under the hood

Examples:

client.trash_comment(current_comment)

Parameters:

  • comment (Resource)

    the comment to be trashed

See Also:



82
83
84
# File 'lib/camper/api/comments.rb', line 82

def trash_comment(comment)
  trash_recording(comment)
end

#update_comment(comment, content) ⇒ Resource

Update the content in a comment

Examples:

client.update_comment(comment, 'Fixed grammar mistakes')

Parameters:

  • comment (Resource)

    comment to modify

  • content (String)

    new content of the comment

Returns:

See Also:



68
69
70
71
72
# 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