Module: ActiveProject::Adapters::Fizzy::Comments

Included in:
ActiveProject::Adapters::FizzyAdapter
Defined in:
lib/active_project/adapters/fizzy/comments.rb

Instance Method Summary collapse

Instance Method Details

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

Adds a comment to a card.

Parameters:

  • card_number (Integer, String)

    The card number.

  • comment_body (String)

    The comment body (supports HTML rich text).

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

    Optional context (not required for Fizzy).

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/active_project/adapters/fizzy/comments.rb', line 39

def add_comment(card_number, comment_body, context = {})
  path = "cards/#{card_number}/comments.json"
  payload = {
    comment: {
      body: comment_body
    }
  }

  response = @connection.post(path) do |req|
    req.body = payload.to_json
  end

  # Extract comment ID from Location header and fetch it
  location = response.headers["Location"]
  if location
    comment_id = location.match(%r{/comments/([^/.]+)})[1]
    find_comment(card_number, comment_id)
  else
    # Fallback: parse response body if available
    comment_data = parse_response(response)
    map_comment_data(comment_data, card_number)
  end
rescue Faraday::Error => e
  handle_faraday_error(e)
end

#delete_comment(card_number, comment_id) ⇒ Boolean

Deletes a comment.

Parameters:

  • card_number (Integer, String)

    The card number.

  • comment_id (String)

    The comment ULID.

Returns:

  • (Boolean)

    True if successfully deleted.



98
99
100
101
102
# File 'lib/active_project/adapters/fizzy/comments.rb', line 98

def delete_comment(card_number, comment_id)
  path = "cards/#{card_number}/comments/#{comment_id}.json"
  make_request(:delete, path)
  true
end

#find_comment(card_number, comment_id) ⇒ ActiveProject::Resources::Comment

Finds a specific comment.

Parameters:

  • card_number (Integer, String)

    The card number.

  • comment_id (String)

    The comment ULID.

Returns:



69
70
71
72
73
74
75
# File 'lib/active_project/adapters/fizzy/comments.rb', line 69

def find_comment(card_number, comment_id)
  path = "cards/#{card_number}/comments/#{comment_id}.json"
  comment_data = make_request(:get, path)
  return nil unless comment_data

  map_comment_data(comment_data, card_number)
end

#list_comments(card_number) ⇒ Array<ActiveProject::Resources::Comment>

Lists comments on a card.

Parameters:

  • card_number (Integer, String)

    The card number.

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/active_project/adapters/fizzy/comments.rb', line 10

def list_comments(card_number)
  all_comments = []
  path = "cards/#{card_number}/comments.json"

  loop do
    response = @connection.get(path)
    comments_data = parse_response(response)
    break if comments_data.empty?

    comments_data.each do |comment_data|
      all_comments << map_comment_data(comment_data, card_number)
    end

    next_url = parse_next_link(response.headers["Link"])
    break unless next_url

    path = extract_path_from_url(next_url)
  end

  all_comments
rescue Faraday::Error => e
  handle_faraday_error(e)
end

#update_comment(card_number, comment_id, comment_body) ⇒ ActiveProject::Resources::Comment

Updates a comment.

Parameters:

  • card_number (Integer, String)

    The card number.

  • comment_id (String)

    The comment ULID.

  • comment_body (String)

    The new comment body.

Returns:



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/active_project/adapters/fizzy/comments.rb', line 82

def update_comment(card_number, comment_id, comment_body)
  path = "cards/#{card_number}/comments/#{comment_id}.json"
  payload = {
    comment: {
      body: comment_body
    }
  }

  make_request(:put, path, payload.to_json)
  find_comment(card_number, comment_id)
end