Module: MingleHelpers::Patches::UpdateCard

Defined in:
lib/helpers/patches/mingleapi.rb

Instance Method Summary collapse

Instance Method Details

#update_card(project, card_num, attrs) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/helpers/patches/mingleapi.rb', line 10

def update_card(project, card_num, attrs)
  params = [
    ['card[name]', attrs[:name]],
    ['card[card_type_name]', attrs[:type]],
    ['card[description]', attrs[:description]]
  ]
  Array(attrs[:attachments]).each_with_index do |attachment, i|
    path, content_type = attachment
    params << ["attachments[#{i}]", UploadIO.new(File.new(path), content_type, File.basename(path))]
  end
  Array(attrs[:properties]).each_with_index do |prop, _i|
    name, value = prop
    params << ['card[properties][][name]', name]
    params << ['card[properties][][value]', value]
  end
  @http.put(v2(:projects, project_identifier(project), :cards, card_num), params)
  OpenStruct.new(number: card_num, url: url('projects', project_identifier(project), 'cards', card_num))
end