class PivotalToTrello::TrelloWrapper
Interface to the Trello API.
Public Class Methods
new(key, token)
click to toggle source
Constructor
# File lib/pivotal_to_trello/trello_wrapper.rb, line 9 def initialize(key, token) Trello.configure do |config| config.developer_public_key = key config.member_token = token end end
Public Instance Methods
add_label(card, label_name, label_color)
click to toggle source
Adds the given label to the card.
# File lib/pivotal_to_trello/trello_wrapper.rb, line 72 def add_label(card, label_name, label_color) @labels ||= {} @labels[card.board_id] ||= Trello::Board.find(card.board_id).labels label = @labels[card.board_id].find { |l| l.name == label_name && l.color == label_color } label ||= Trello::Label.create(name: label_name, board_id: card.board_id, color: label_color) card.add_label(label) unless card.labels.detect { |l| l.id == label.id } end
board_choices()
click to toggle source
Returns a hash of available boards, keyed on board ID.
# File lib/pivotal_to_trello/trello_wrapper.rb, line 39 def board_choices Trello::Board.all.each_with_object({}) do |board, hash| hash[board.id] = board.name end end
cards_for_list(list_id)
click to toggle source
Returns a list of all cards in the given list, keyed on name.
# File lib/pivotal_to_trello/trello_wrapper.rb, line 62 def cards_for_list(list_id) @cards ||= {} @cards[list_id] ||= Trello::List.find(list_id).cards.each_with_object({}) do |card, hash| hash[card_hash(card.name, card.desc)] = card end @cards[list_id] end
create_card(list_id, pivotal_story)
click to toggle source
Creates a card in the given list if one with the same name doesn't already exist.
# File lib/pivotal_to_trello/trello_wrapper.rb, line 17 def create_card(list_id, pivotal_story) card = get_card(list_id, pivotal_story.name, pivotal_story.description) card ||= begin puts "Creating a card for #{pivotal_story.story_type} '#{pivotal_story.name}'." card = Trello::Card.create( name: pivotal_story.name, desc: pivotal_story.description, list_id: list_id, ) create_comments(card, pivotal_story) create_tasks(card, pivotal_story) card end key = card_hash(card.name, card.desc) @cards ||= {} @cards[list_id] ||= {} @cards[list_id][key] = card end
label_choices()
click to toggle source
Returns a list of colors that can be used to label cards.
# File lib/pivotal_to_trello/trello_wrapper.rb, line 82 def label_choices { 'blue' => 'Blue', 'green' => 'Green', 'orange' => 'Orange', 'purple' => 'Purple', 'red' => 'Red', 'yellow' => 'Yellow', false => '[none]', } end
list_choices(board_id)
click to toggle source
Returns a hash of available lists for the given board, keyed on board ID.
# File lib/pivotal_to_trello/trello_wrapper.rb, line 46 def list_choices(board_id) # Cache the list to improve performance. @lists ||= {} @lists[board_id] ||= begin choices = Trello::Board.find(board_id).lists.each_with_object({}) do |list, hash| hash[list.id] = list.name end choices = Hash[choices.sort_by { |_, v| v }] choices[false] = "[don't import these stories]" choices end @lists[board_id] end
Private Instance Methods
card_hash(name, description)
click to toggle source
Returns a unique identifier for this list/name/description combination.
# File lib/pivotal_to_trello/trello_wrapper.rb, line 118 def card_hash(name, description) Digest::SHA1.hexdigest("#{name}_#{description}") end
create_comments(card, pivotal_story)
click to toggle source
Copies notes from the pivotal story to the card.
# File lib/pivotal_to_trello/trello_wrapper.rb, line 97 def create_comments(card, pivotal_story) pivotal_story.comments.each do |comment| card.add_comment(comment.text.to_s.strip.to_s) unless comment.text.to_s.strip.empty? end end
create_tasks(card, pivotal_story)
click to toggle source
Copies notes from the pivotal story to the card.
# File lib/pivotal_to_trello/trello_wrapper.rb, line 104 def create_tasks(card, pivotal_story) tasks = pivotal_story.tasks return if tasks.empty? checklist = Trello::Checklist.create(name: 'Tasks', card_id: card.id) card.add_checklist(checklist) tasks.each do |task| puts " - Creating task '#{task.description}'" checklist.add_item(task.description, task.complete) end end
get_card(list_id, name, description)
click to toggle source
Returns a card with the given name and description if it exists in the given list, nil otherwise.
# File lib/pivotal_to_trello/trello_wrapper.rb, line 123 def get_card(list_id, name, description) key = card_hash(name, description) cards_for_list(list_id)[key] unless cards_for_list(list_id)[key].nil? end