Module: Tr3llo::API::Checklist

Extended by:
Checklist
Included in:
Checklist
Defined in:
lib/3llo/api/checklist.rb

Instance Method Summary collapse

Instance Method Details

#create(card_id, data) ⇒ Object



6
7
8
9
10
# File 'lib/3llo/api/checklist.rb', line 6

def create(card_id, data)
  req_path = Utils.build_req_path("/cards/#{card_id}/checklists")

  client.post(req_path, {}, data)
end

#create_item(checklist_id, name) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/3llo/api/checklist.rb', line 76

def create_item(checklist_id, name)
  req_path = Utils.build_req_path("/checklists/#{checklist_id}/checkItems")
  payload = {
    name: name,
    pos: "bottom",
    state: "false"
  }

  client.post(req_path, {}, payload)
end

#delete(checklist_id) ⇒ Object



33
34
35
36
37
# File 'lib/3llo/api/checklist.rb', line 33

def delete(checklist_id)
  req_path = Utils.build_req_path("/checklists/#{checklist_id}")

  client.delete(req_path, {}, {})
end

#delete_item(card_id, item_id) ⇒ Object



93
94
95
96
97
# File 'lib/3llo/api/checklist.rb', line 93

def delete_item(card_id, item_id)
  req_path = Utils.build_req_path("/cards/#{card_id}/checkItem/#{item_id}")

  client.delete(req_path, {}, {})
end

#get(checklist_id) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/3llo/api/checklist.rb', line 12

def get(checklist_id)
  req_path = Utils.build_req_path("/checklists/#{checklist_id}")
  payload = client.get(req_path, {})

  checklist_id, checklist_name = payload.fetch_values("id", "name")
  checklist_shortcut = Entities.make_shortcut(:checklist, checklist_id)

  Entities::Checklist.new(
    id: checklist_id,
    shortcut: checklist_shortcut,
    name: checklist_name,
    items: []
  )
end

#get_item(card_id, item_id) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/3llo/api/checklist.rb', line 66

def get_item(card_id, item_id)
  req_path = Utils.build_req_path("/cards/#{card_id}/checkItem/#{item_id}")
  item_payload = client.get(req_path, {})

  item_id, item_name, item_state = item_payload.fetch_values("id", "name", "state")
  item_shortcut = Entities.make_shortcut(:check_item, item_id)

  Entities::Checklist::Item.new(id: item_id, shortcut: item_shortcut, name: item_name, state: item_state)
end

#list_by_card_id(card_id) ⇒ Object



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
64
# File 'lib/3llo/api/checklist.rb', line 39

def list_by_card_id(card_id)
  req_path = Utils.build_req_path("/cards/#{card_id}/checklists")
  payload = client.get(req_path, {})

  payload.map do |checklist_payload|
    checklist_id, checklist_name = checklist_payload.fetch_values("id", "name")
    checklist_shortcut = Entities.make_shortcut(:checklist, checklist_id)

    items =
      checklist_payload
        .fetch("checkItems", [])
        .map do |item_payload|
        item_id, item_name, item_state = item_payload.fetch_values("id", "name", "state")
        item_shortcut = Entities.make_shortcut(:check_item, item_id)

        Entities::Checklist::Item.new(id: item_id, shortcut: item_shortcut, name: item_name, state: item_state)
      end

    Entities::Checklist.new(
      id: checklist_id,
      shortcut: checklist_shortcut,
      name: checklist_name,
      items: items
    )
  end
end

#update(checklist_id, data) ⇒ Object



27
28
29
30
31
# File 'lib/3llo/api/checklist.rb', line 27

def update(checklist_id, data)
  req_path = Utils.build_req_path("/checklists/#{checklist_id}")

  client.put(req_path, {}, data)
end

#update_item(card_id, check_item_id, data) ⇒ Object



87
88
89
90
91
# File 'lib/3llo/api/checklist.rb', line 87

def update_item(card_id, check_item_id, data)
  req_path = Utils.build_req_path("/cards/#{card_id}/checkItem/#{check_item_id}")

  client.put(req_path, {}, data)
end