class TaskMapper::Provider::Trello::Ticket

Public Class Methods

create(attributes) click to toggle source
# File lib/provider/ticket.rb, line 25
def create(attributes)
  ticket = self.new(attributes)
  ticket if ticket.save
end
find_all(project_id) click to toggle source
# File lib/provider/ticket.rb, line 18
def find_all(project_id)
  api = TaskMapper::Provider::Trello.api
  board = api.boards.find { |b| b.id == project_id }
  cards = board.cards.map(&:attributes)
  cards.collect { |c| self.new c }
end
find_by_attributes(project_id, attributes = {}) click to toggle source
# File lib/provider/ticket.rb, line 13
def find_by_attributes(project_id, attributes = {})
  tickets = self.find_all(project_id)
  search_by_attribute(tickets, attributes)
end
find_by_id(project_id, ticket_id) click to toggle source
# File lib/provider/ticket.rb, line 5
def find_by_id(project_id, ticket_id)
  api = TaskMapper::Provider::Trello.api
  board = api.boards.find { |b| b.id == project_id }
  cards = board.cards.map(&:attributes)
  card = cards.find { |c| c[:id] == ticket_id }
  self.new card
end
new(*object) click to toggle source
Calls superclass method
# File lib/provider/ticket.rb, line 31
def initialize(*object)
  object = object.first if object.is_a? Array
  super object
  check_and_replace_attribute :desc, :description
  check_and_replace_attribute :board_id, :project_id
  check_and_replace_attribute :last_activity_date, :updated_at
  set_status
end

Public Instance Methods

close() click to toggle source
# File lib/provider/ticket.rb, line 75
def close
  self.status = 'closed'
  update
end
new?() click to toggle source
# File lib/provider/ticket.rb, line 44
def new?
  list_id.nil?
end
reopen() click to toggle source
# File lib/provider/ticket.rb, line 80
def reopen
  self.status = 'open'
  update
end
save() click to toggle source
# File lib/provider/ticket.rb, line 40
def save
  new? ? to_card : update
end
to_card() click to toggle source
# File lib/provider/ticket.rb, line 48
def to_card
  opts = {
    :name => name,
    :list_id => project_id,
    :desc => description
  }

  card = ::Trello::Card.create(opts)

  card = card.first if card.is_a?(Array)

  self.merge!(card.attributes)
  check_and_replace_attribute :desc, :description
  check_and_replace_attribute :board_id, :project_id
  check_and_replace_attribute :last_activity_date, :updated_at
  set_status
end
update() click to toggle source
# File lib/provider/ticket.rb, line 66
def update
  card = find_card
  attrs = Hash[self]
  attrs['desc'] = attrs.delete('description')
  attrs['board_id'] = attrs.delete('project_id')
  attrs['closed'] = (attrs.delete('status') == 'closed')
  card.update_fields(attrs).save
end

Private Instance Methods

check_and_replace_attribute(base, target) click to toggle source
# File lib/provider/ticket.rb, line 86
def check_and_replace_attribute(base, target)
  if self[base] && !self[target]
    self[target] = self.delete(base)
  end
end
find_card() click to toggle source
# File lib/provider/ticket.rb, line 96
def find_card
  api = TaskMapper::Provider::Trello.api
  board = api.boards.find { |b| b.id == project_id }
  board.cards.find { |c| c.id == id }
end
set_status() click to toggle source
# File lib/provider/ticket.rb, line 92
def set_status
  self[:status] = (self[:closed] ? 'closed' : 'open')
end