Class: PivotalToTrello::TrelloWrapper
- Inherits:
-
Object
- Object
- PivotalToTrello::TrelloWrapper
- Defined in:
- lib/pivotal_to_trello/trello_wrapper.rb
Overview
Interface to the Trello API.
Instance Method Summary collapse
-
#add_label(card, label_name, label_color) ⇒ Object
Adds the given label to the card.
-
#board_choices ⇒ Object
Returns a hash of available boards, keyed on board ID.
-
#cards_for_list(list_id) ⇒ Object
Returns a list of all cards in the given list, keyed on name.
-
#create_card(list_id, pivotal_story) ⇒ Object
Creates a card in the given list if one with the same name doesn’t already exist.
-
#initialize(key, token) ⇒ TrelloWrapper
constructor
Constructor.
-
#label_choices ⇒ Object
Returns a list of colors that can be used to label cards.
-
#list_choices(board_id) ⇒ Object
Returns a hash of available lists for the given board, keyed on board ID.
Constructor Details
#initialize(key, token) ⇒ TrelloWrapper
Constructor
9 10 11 12 13 14 |
# 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 |
Instance Method Details
#add_label(card, label_name, label_color) ⇒ Object
Adds the given label to the card.
72 73 74 75 76 77 78 79 |
# 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 ⇒ Object
Returns a hash of available boards, keyed on board ID.
39 40 41 42 43 |
# 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) ⇒ Object
Returns a list of all cards in the given list, keyed on name.
62 63 64 65 66 67 68 69 |
# 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) ⇒ Object
Creates a card in the given list if one with the same name doesn’t already exist.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# 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 ⇒ Object
Returns a list of colors that can be used to label cards.
82 83 84 85 86 87 88 89 90 91 92 |
# 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) ⇒ Object
Returns a hash of available lists for the given board, keyed on board ID.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 |