Module: ActiveProject::Adapters::Basecamp::Comments

Included in:
ActiveProject::Adapters::BasecampAdapter
Defined in:
lib/active_project/adapters/basecamp/comments.rb

Instance Method Summary collapse

Instance Method Details

#add_comment(todo_id, comment_body, context = {}) ⇒ ActiveProject::Resources::Comment

Adds a comment to a To-do in Basecamp.

Parameters:

  • todo_id (String, Integer)

    The ID of the Basecamp To-do.

  • comment_body (String)

    The comment text (HTML).

  • context (Hash) (defaults to: {})

    Required context: { project_id: ‘…’ }.

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/active_project/adapters/basecamp/comments.rb', line 12

def add_comment(todo_id, comment_body, context = {})
  project_id = context[:project_id]
  unless project_id
    raise ArgumentError,
          "Missing required context: :project_id must be provided for BasecampAdapter#add_comment"
  end

  path = "buckets/#{project_id}/recordings/#{todo_id}/comments.json"
  payload = { content: comment_body }.to_json
  comment_data = make_request(:post, path, payload)
  map_comment_data(comment_data, todo_id.to_i)
end

#delete_comment(comment_id, context = {}) ⇒ Boolean

Deletes a comment from a To-do in Basecamp.

Parameters:

  • comment_id (String, Integer)

    The ID of the comment to delete.

  • context (Hash) (defaults to: {})

    Required context: { project_id: ‘…’ }.

Returns:

  • (Boolean)

    True if successfully deleted.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_project/adapters/basecamp/comments.rb', line 47

def delete_comment(comment_id, context = {})
  project_id = context[:project_id]
  unless project_id
    raise ArgumentError,
          "Missing required context: :project_id must be provided for BasecampAdapter#delete_comment"
  end

  path = "buckets/#{project_id}/recordings/#{comment_id}/status/trashed.json"
  make_request(:put, path)
  true
end

#update_comment(comment_id, body, context = {}) ⇒ ActiveProject::Resources::Comment

Updates a comment on a To-do in Basecamp.

Parameters:

  • comment_id (String, Integer)

    The ID of the comment.

  • body (String)

    The new comment text (HTML).

  • context (Hash) (defaults to: {})

    Required context: { project_id: ‘…’ }.

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/active_project/adapters/basecamp/comments.rb', line 30

def update_comment(comment_id, body, context = {})
  project_id = context[:project_id]
  unless project_id
    raise ArgumentError,
          "Missing required context: :project_id must be provided for BasecampAdapter#update_comment"
  end

  path = "buckets/#{project_id}/comments/#{comment_id}.json"
  payload = { content: body }.to_json
  comment_data = make_request(:put, path, payload)
  map_comment_data(comment_data, comment_data["parent"]&.dig("id"))
end