class TrelloGateway

Attributes

board[R]
inbox[R]

Public Class Methods

new(options) click to toggle source
# File lib/github_to_trello/trello_gateway.rb, line 10
def initialize(options)
  [:public_key, :token, :board_id, :inbox_name].each do |required_field|
    _raise_argument_error(required_field) unless options[required_field]
  end

  Trello.configure do |c|
    c.developer_public_key = options[:public_key]
    c.member_token = options[:token]
  end

  @board = _board(options[:board_id])
  @inbox = _list(options[:inbox_name])
end

Public Instance Methods

_board(id) click to toggle source
# File lib/github_to_trello/trello_gateway.rb, line 54
def _board(id)
  Trello::Board.find(id)
end
_create_card(issue) click to toggle source
# File lib/github_to_trello/trello_gateway.rb, line 46
def _create_card(issue)
  Trello::Card.create(
    :name => issue.title,
    :list_id => inbox.id,
    :desc => issue.body + "\n" + issue.html_url + "\n" + issue.updated_at.to_s,
  )
end
_existing_card(issue) click to toggle source
# File lib/github_to_trello/trello_gateway.rb, line 37
def _existing_card(issue)
  lists.each do |list|
    list.cards.each do |card|
      return card if card.name == issue.title
    end
  end
  nil
end
_list(name) click to toggle source
# File lib/github_to_trello/trello_gateway.rb, line 58
def _list(name)
  found_list = board.lists.detect do |list|
    list.name =~ /#{name}/
  end
  found_list || Trello::List.create(:name => name, :board_id => board.id)
end
_raise_argument_error(field) click to toggle source
# File lib/github_to_trello/trello_gateway.rb, line 33
def _raise_argument_error(field)
  raise "Argument '#{field}' is required yet missing"
end
create_or_update_card(issue) click to toggle source
# File lib/github_to_trello/trello_gateway.rb, line 24
def create_or_update_card(issue)
  existing_card = _existing_card(issue)
  existing_card.nil? ? _create_card(issue) : existing_card
end
lists() click to toggle source
# File lib/github_to_trello/trello_gateway.rb, line 29
def lists
  board.lists
end