Class: Lita::Handlers::Trello
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::Trello
- Defined in:
- lib/lita/handlers/trello.rb
Instance Method Summary collapse
- #handle_create_card(r) ⇒ Object
- #handle_list_cards(r) ⇒ Object
- #handle_lists(r) ⇒ Object
- #handle_move_card(r) ⇒ Object
Instance Method Details
#handle_create_card(r) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lita/handlers/trello.rb', line 13 def handle_create_card(r) list_name = r.args[1] name = r.args[2..-1].join(" ") list_id = lists[list_name.downcase].id if list_id.nil? r.reply "I couldn't find a list named #{list_name}." return end r.reply "Ok #{r.user.name}, I'm creating a new card in #{list}." begin card = new_card(name, list_id) r.reply "Here you go: #{card.short_url}" rescue => err r.reply "Something failed." end end |
#handle_list_cards(r) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/lita/handlers/trello.rb', line 67 def handle_list_cards(r) list_name = r.args[1] list = lists[list_name.downcase] if list.nil? r.reply "I couldn't find a list named #{list_name}." return end r.reply("Here are the cards in #{list.name}:\n\n" + list.cards.map { |card| "* #{card.name} - #{card.short_url}" }.join("\n") ) end |
#handle_lists(r) ⇒ Object
83 84 85 86 87 |
# File 'lib/lita/handlers/trello.rb', line 83 def handle_lists(r) r.reply("Here are all the lists on your board:\n\n" + lists.each_pair.map { |list_name, list| "* #{list_name}" }.join("\n") ) end |
#handle_move_card(r) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/lita/handlers/trello.rb', line 35 def handle_move_card(r) card_id = r.args[1] list_name = r.args[2] list = lists[list_name.downcase] if list.nil? r.reply "I couldn't find a list named #{list_name}." return end card_id = card_id.gsub(/(^<|>$)/, '') if %r{^https?://trello.com/c/([^/]+)/?$} =~ card_id card_id = $1 end card = trello.find(:card, card_id) if card.nil? r.reply "I couldn't find that card." return end begin card.move_to_list(list) r.reply "Ok #{r.user.name}, I moved that card to #{list_name}." rescue => err r.reply "Something failed." end end |