Class: TaskMapper::Provider::Trello::Ticket

Inherits:
Base::Ticket
  • Object
show all
Defined in:
lib/provider/ticket.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*object) ⇒ Ticket

Returns a new instance of Ticket.



31
32
33
34
35
36
37
38
# 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

Class Method Details

.create(attributes) ⇒ Object



25
26
27
28
# File 'lib/provider/ticket.rb', line 25

def create(attributes)
  ticket = self.new(attributes)
  ticket if ticket.save
end

.find_all(project_id) ⇒ Object



18
19
20
21
22
23
# 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 = {}) ⇒ Object



13
14
15
16
# 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) ⇒ Object



5
6
7
8
9
10
11
# 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

Instance Method Details

#closeObject



75
76
77
78
# File 'lib/provider/ticket.rb', line 75

def close
  self.status = 'closed'
  update
end

#new?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/provider/ticket.rb', line 44

def new?
  list_id.nil?
end

#reopenObject



80
81
82
83
# File 'lib/provider/ticket.rb', line 80

def reopen
  self.status = 'open'
  update
end

#saveObject



40
41
42
# File 'lib/provider/ticket.rb', line 40

def save
  new? ? to_card : update
end

#to_cardObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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

#updateObject



66
67
68
69
70
71
72
73
# 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