Class: TicketMaster::Provider::Basecamp::Ticket

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

Overview

Ticket class for ticketmaster-basecamp

  • status => completed (either completed or incomplete)

  • priority => position

  • title => TodoList#name - TodoItem#content (up to 100 characters)

  • resolution => completed (either completed or ”)

  • updated_at => completed_on

  • description => content

  • assignee => responsible_party_name (read-only)

  • requestor => creator_name (read-only)

  • project_id

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*options) ⇒ Ticket

Returns a new instance of Ticket.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/provider/ticket.rb', line 16

def initialize(*options)
  @system_data ||= {}
  @cache ||= {}
  first = options.first
  case first
    when Hash
      super(first.to_hash)
    else
      @system_data[:client] = first
      super(first.attributes)
  end
end

Class Method Details

.create(attributes_hash) ⇒ Object

It expects a single hash



50
51
52
53
54
55
56
57
58
59
# File 'lib/provider/ticket.rb', line 50

def create(attributes_hash)
  todo_item_hash = create_todo_item_hash attributes_hash
  todo_item = create_todo_item todo_item_hash

  return nil unless todo_item.save

  todo_item.project_id = attributes_hash[:project_id]
  todo_item.todo_list_id = todo_item_hash[:todo_list_id]
  self.new(todo_item)
end

.find_by_attributes(project_id, attributes = {}) ⇒ Object



35
36
37
# File 'lib/provider/ticket.rb', line 35

def find_by_attributes(project_id, attributes = {})
  search(project_id, attributes)
end

.find_by_id(project_id, id) ⇒ Object



31
32
33
# File 'lib/provider/ticket.rb', line 31

def find_by_id(project_id, id)
  find_by_attributes(project_id, {:id => id}).first
end

.search(project_id, options = {}, limit = 1000) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/provider/ticket.rb', line 39

def search(project_id, options = {}, limit = 1000)
  tickets = BasecampAPI::TodoList.find(:all, :params => {:project_id => project_id}).collect do |list|
    list.todo_items.collect { |item|
      item.attributes['list'] = list
      item
    }
  end.flatten.collect { |ticket| self.new(ticket.attributes.merge!(:project_id => project_id)) }
  search_by_attribute(tickets, options, limit)
end

Instance Method Details

#assigneeObject



141
142
143
# File 'lib/provider/ticket.rb', line 141

def assignee
  self.responsible_party_name
end

#comment!(*options) ⇒ Object



149
150
151
152
# File 'lib/provider/ticket.rb', line 149

def comment!(*options)
  options[0].merge!(:todo_item_id => id) if options.first.is_a?(Hash)
  self.class.parent::Comment.create(*options)
end

#copy_to(todo_item) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'lib/provider/ticket.rb', line 89

def copy_to(todo_item)
  todo_item.completed = status
  todo_item.position = priority
  todo_item.name = title
  todo_item.content = title
  todo_item.completed = resolution
  todo_item.responsible_party_name = assignee
  todo_item.creator_name = requestor
  todo_item
end

#descriptionObject



133
134
135
# File 'lib/provider/ticket.rb', line 133

def description
  self.content
end

#description=(desc) ⇒ Object



137
138
139
# File 'lib/provider/ticket.rb', line 137

def description=(desc)
  self.content = desc
end

#priorityObject



113
114
115
# File 'lib/provider/ticket.rb', line 113

def priority
  self.position
end

#priority=(pri) ⇒ Object



117
118
119
# File 'lib/provider/ticket.rb', line 117

def priority=(pri)
  self.position = pri
end

#requestorObject



145
146
147
# File 'lib/provider/ticket.rb', line 145

def requestor
  self.creator_name
end

#saveObject



100
101
102
103
# File 'lib/provider/ticket.rb', line 100

def save
  todo_item = BasecampAPI::TodoItem.find id, :params => { :todo_list_id => todo_list_id }
  copy_to(todo_item).save
end

#statusObject



109
110
111
# File 'lib/provider/ticket.rb', line 109

def status
  self.completed ? 'completed' : 'incomplete'
end

#titleObject



121
122
123
# File 'lib/provider/ticket.rb', line 121

def title
  self.content
end

#title=(titl) ⇒ Object



125
126
127
# File 'lib/provider/ticket.rb', line 125

def title=(titl)
  self.content = titl
end

#todo_list_idObject



105
106
107
# File 'lib/provider/ticket.rb', line 105

def todo_list_id
  self['todo_list_id'].to_i
end

#updated_at=(comp) ⇒ Object



129
130
131
# File 'lib/provider/ticket.rb', line 129

def updated_at=(comp)
  self.completed_on = comp
end