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) ⇒ 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
8 9 10 11 12 13 |
# File 'lib/pivotal_to_trello/trello_wrapper.rb', line 8 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) ⇒ Object
Adds the given label to the card.
76 77 78 |
# File 'lib/pivotal_to_trello/trello_wrapper.rb', line 76 def add_label(card, label) card.add_label(label) unless card.labels.collect { |label| label.color }.include?(label) end |
#board_choices ⇒ Object
Returns a hash of available boards, keyed on board ID.
40 41 42 43 44 45 |
# File 'lib/pivotal_to_trello/trello_wrapper.rb', line 40 def board_choices Trello::Board.all.inject({}) do |hash, board| hash[board.id] = board.name hash end end |
#cards_for_list(list_id) ⇒ Object
Returns a list of all cards in the given list, keyed on name.
65 66 67 68 69 70 71 72 73 |
# File 'lib/pivotal_to_trello/trello_wrapper.rb', line 65 def cards_for_list(list_id) @cards ||= {} @cards[list_id] ||= Trello::List.find(list_id).cards.inject({}) do |hash, card| hash[card_hash(card.name, card.desc)] = card hash 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.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pivotal_to_trello/trello_wrapper.rb', line 16 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 ) pivotal_story.notes.all.each do |note| card.add_comment("[#{note.author}] #{note.text.to_s.strip}") unless note.text.to_s.strip.empty? end 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.
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pivotal_to_trello/trello_wrapper.rb', line 81 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.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/pivotal_to_trello/trello_wrapper.rb', line 48 def list_choices(board_id) # Cache the list to improve performance. @lists ||= {} @lists[board_id] ||= begin choices = Trello::Board.find(board_id).lists.inject({}) do |hash, list| hash[list.id] = list.name hash end choices = Hash[choices.sort_by { |_, v| v }] choices[false] = "[don't import these stories]" choices end @lists[board_id] end |