Class: Fizzy::CLI::Comments

Inherits:
Thor
  • Object
show all
Includes:
Base
Defined in:
lib/fizzy/cli/comments.rb

Instance Method Summary collapse

Methods included from Base

included

Instance Method Details

#create(body_text) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/fizzy/cli/comments.rb', line 32

def create(body_text)
  resp = client.post("cards/#{options[:card]}/comments", body: { body: body_text })
  c = resp.body
  output_detail(c, pairs: [
                  ["ID", c["id"]],
                  ["Body", c["body"]]
                ])
end

#delete(comment_id) ⇒ Object



59
60
61
62
# File 'lib/fizzy/cli/comments.rb', line 59

def delete(comment_id)
  client.delete("cards/#{options[:card]}/comments/#{comment_id}")
  puts "Comment #{comment_id} deleted."
end

#get(comment_id) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/fizzy/cli/comments.rb', line 19

def get(comment_id)
  resp = client.get("cards/#{options[:card]}/comments/#{comment_id}")
  c = resp.body
  output_detail(c, pairs: [
                  ["ID", c["id"]],
                  ["Author", c.dig("creator", "name")],
                  ["Body", c["body"]],
                  ["Created", c["created_at"]]
                ])
end

#listObject



10
11
12
13
14
15
# File 'lib/fizzy/cli/comments.rb', line 10

def list
  data = paginator.all("cards/#{options[:card]}/comments")
  output_list(data, headers: %w[ID Author Created]) do |c|
    [c["id"], c.dig("creator", "name"), c["created_at"]]
  end
end

#update(comment_id) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fizzy/cli/comments.rb', line 44

def update(comment_id)
  resp = client.put("cards/#{options[:card]}/comments/#{comment_id}", body: build_body(:body))
  c = resp.body
  if c
    output_detail(c, pairs: [
                    ["ID", c["id"]],
                    ["Body", c["body"]]
                  ])
  else
    puts "Comment #{comment_id} updated."
  end
end