Class: Fizzy::CLI::Boards

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

Instance Method Summary collapse

Methods included from Base

included

Instance Method Details

#create(name) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/fizzy/cli/boards.rb', line 30

def create(name)
  resp = client.post("boards", body: { name: name })
  b = resp.body
  output_detail(b, pairs: [
                  ["ID", b["id"]],
                  ["Name", b["name"]]
                ])
end

#delete(board_id) ⇒ Object



55
56
57
58
# File 'lib/fizzy/cli/boards.rb', line 55

def delete(board_id)
  client.delete("boards/#{board_id}")
  puts "Board #{board_id} deleted."
end

#get(board_id) ⇒ Object



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

def get(board_id)
  resp = client.get("boards/#{board_id}")
  b = resp.body
  output_detail(b, pairs: [
                  ["ID", b["id"]],
                  ["Name", b["name"]],
                  ["Open cards", b["open_cards_count"]],
                  ["Columns", b["columns_count"]],
                  ["Created", b["created_at"]]
                ])
end

#listObject



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

def list
  data = paginator.all("boards")
  output_list(data, headers: %w[ID Name Cards Columns]) do |b|
    [b["id"], b["name"], b["open_cards_count"], b["columns_count"]]
  end
end

#syncObject

Raises:

  • (Thor::Error)


61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fizzy/cli/boards.rb', line 61

def sync
  raise Thor::Error, "No .fizzy.yml found. Run: fizzy init" unless project_config.found?

  boards = paginator.all("boards")
  boards_hash = boards.to_h { |b| [b["id"], b["name"]] }

  config = YAML.safe_load_file(project_config.path)
  config = {} unless config.is_a?(Hash)
  config["boards"] = boards_hash

  File.write(project_config.path, YAML.dump(config))
  say "Synced #{boards_hash.size} board(s) to #{project_config.path}"
end

#update(board_id) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fizzy/cli/boards.rb', line 41

def update(board_id)
  resp = client.put("boards/#{board_id}", body: { name: options[:name] })
  b = resp.body
  if b
    output_detail(b, pairs: [
                    ["ID", b["id"]],
                    ["Name", b["name"]]
                  ])
  else
    puts "Board #{board_id} updated."
  end
end