class Trellor::Trellor

Attributes

be_verbose[RW]

Public Class Methods

logger() click to toggle source
# File lib/trellor.rb, line 21
def self.logger
  unless @logger
    file = File.new(logger_filename.to_s, 'a')
    # webapi wasn't logging to the file until it was killed.
    # this causes the logger to flush immediately
    file.sync = true
    @logger = Logger.new file
  end
  @logger
end
logger_filename() click to toggle source
# File lib/trellor.rb, line 32
def self.logger_filename
  dirpath = Pathname.new(ENV['HOME']) + '.config/trellor'
  dirpath.mkdir unless dirpath.directory?
  filename = 'trellor.log'
  dirpath + filename
end
singleton() click to toggle source
# File lib/trellor.rb, line 13
def self.singleton
  unless @singleton
    puts 'getting singleton'
    @singleton = self.new
  end
  @singleton
end

Public Instance Methods

archive_card(board_name, list_name, name) click to toggle source
# File lib/trellor.rb, line 63
def archive_card(board_name, list_name, name)
  card = find_card(board_name, list_name, name)
  card.close!
end
board_names() click to toggle source

trellor interface queries ###############

# File lib/trellor.rb, line 46
def board_names
  boards.collect{ |board| board.name }.sort_by{|name| name.downcase}
end
boards() click to toggle source

private queries #################

# File lib/trellor.rb, line 71
def boards
  verbose_log('getting boards') unless @boards
  @boards ||= user.boards.select{ |b| !b.closed? }
end
boards=(boards) click to toggle source
# File lib/trellor.rb, line 75
def boards=(boards)
  @boards = boards
end
card_names(board_name, list_name) click to toggle source
# File lib/trellor.rb, line 52
def card_names(board_name, list_name)
  find_list(board_name, list_name).cards.collect{ |card| card.name }
end
cards(board_name, list_name) click to toggle source
# File lib/trellor.rb, line 93
def cards(board_name, list_name)
  verbose_log('       getting cards for', board_name, list_name)
  find_list(board_name, list_name).cards
end
create_card(board_name, list_name, name, descript=nil) click to toggle source
# File lib/trellor.rb, line 55
def create_card(board_name, list_name, name, descript=nil)
  card = Trello::Card.new
  card.client = client
  card.list_id = find_list(board_name, list_name).id
  card.name = name
  card.desc = descript if descript
  card.save
end
find_board(name) click to toggle source
# File lib/trellor.rb, line 79
def find_board(name)
  boards   # to get verbose log ordering correct
  verbose_log('getting board', name)
  name = Regexp.new(name, Regexp::IGNORECASE)
  boards.find{ |board| name.match(board.name) }
end
find_card(board_name, list_name, card_name) click to toggle source
# File lib/trellor.rb, line 98
def find_card(board_name, list_name, card_name)
  this_list = find_list(board_name, list_name)
  verbose_log('   getting card', board_name, list_name, card_name)
  name = Regexp.new(card_name, Regexp::IGNORECASE)
  this_list.cards.find{ |card| name.match(card.name) }
end
find_list(board_name, list_name) click to toggle source
# File lib/trellor.rb, line 86
def find_list(board_name, list_name)
  this_board = find_board(board_name)
  verbose_log('   getting list', board_name, list_name)
  name = Regexp.new(list_name, Regexp::IGNORECASE)
  this_board.lists.find{ |list| name.match(list.name) }
end
list_names(board_name) click to toggle source
# File lib/trellor.rb, line 49
def list_names(board_name)
  find_board(board_name).lists.collect{ |list| list.name }.sort_by{|name| name.downcase}
end
logger() click to toggle source
# File lib/trellor.rb, line 39
def logger
  self.class.logger
end

Private Instance Methods

client(key=ENV['TRELLOR_KEY'], token=ENV['TRELLOR_TOKEN']) click to toggle source

connecting ###############

# File lib/trellor.rb, line 110
def client(key=ENV['TRELLOR_KEY'], token=ENV['TRELLOR_TOKEN'])
  @client ||= connect(key, token)
end
connect(key=ENV['TRELLOR_KEY'], token=ENV['TRELLOR_TOKEN']) click to toggle source
# File lib/trellor.rb, line 114
def connect(key=ENV['TRELLOR_KEY'], token=ENV['TRELLOR_TOKEN'])
  verbose_log("connecting with", key, token)
  Trello::Client.new(
    :developer_public_key => key,
    :member_token => token
  )
end
user() click to toggle source
# File lib/trellor.rb, line 126
def user()
  verbose_log('username', ENV['TRELLOR_USERNAME'])
  @user ||= client.find(:members, ENV['TRELLOR_USERNAME'])
end
verbose_log(*args) click to toggle source
# File lib/trellor.rb, line 122
def verbose_log(*args)
  logger.error("           ****** #{args.inspect}") if be_verbose
end