class Lita::Handlers::Trello

Public Instance Methods

list(r) click to toggle source
# File lib/lita/handlers/trello.rb, line 87
def list(r)
  list_name = r.match_data['list_name']
  list = lists[list_name.downcase]
  if list.nil?
    r.reply t('error.no_list', list_name: list_name)
    return
  end

  r.reply(t('card.list', list_name: list_name) +
          list.cards.map { |card| "* #{card.name} - #{card.short_url}" }.join("\n")
         )
end
move(r) click to toggle source
# File lib/lita/handlers/trello.rb, line 63
def move(r)
  card_id = r.match_data['card_id']
  list_name = r.match_data['list_name']

  list = lists[list_name.downcase]
  if list.nil?
    r.reply t('error.no_list', list_name: list_name)
    return
  end

  card = trello.find(:card, card_id)
  if card.nil?
    r.reply t('error.no_card')
    return
  end

  begin
    card.move_to_list(list)
    r.reply t('card.moved', user_name: r.user.name, list_name: list_name)
  rescue
    r.reply t('error.generic')
  end
end
new(r) click to toggle source
# File lib/lita/handlers/trello.rb, line 44
def new(r)
  list_name = r.match_data['list_name']
  name = r.match_data['name']

  list_id = lists[list_name.downcase].id
  if list_id.nil?
    r.reply t('error.no_list', list_name: list_name)
    return
  end

  r.reply t('card.creating', user_name: r.user.name, list_name: list_name)
  begin
    card = new_card(name, list_id)
    r.reply t('card.created', url: card.short_url)
  rescue
    r.reply t('error.generic')
  end
end
show_lists(r) click to toggle source
# File lib/lita/handlers/trello.rb, line 100
def show_lists(r)
  r.reply(t('list.list') +
          lists.keys.map { |list_name| "* #{list_name}" }.join("\n")
         )
end

Private Instance Methods

board() click to toggle source
# File lib/lita/handlers/trello.rb, line 115
def board
  @board ||= trello.find(:board, config.board)
end
default_list_id() click to toggle source
# File lib/lita/handlers/trello.rb, line 125
def default_list_id
  @default_list_id ||= redis.get('default_list_id')
end
lists() click to toggle source
# File lib/lita/handlers/trello.rb, line 119
def lists
  @lists ||= begin
    board.lists.map { |list| [list.name.downcase, list] }.to_h
  end
end
new_card(name, list_id = nil) click to toggle source
# File lib/lita/handlers/trello.rb, line 129
def new_card(name, list_id = nil)
  trello.create(:card,
                'name' => name,
                'idList' => list_id || default_list_id
               )
end
trello() click to toggle source
# File lib/lita/handlers/trello.rb, line 108
def trello
  @trello ||= ::Trello::Client.new(
    developer_public_key: config.public_key,
    member_token: config.token
  )
end