Class: TaskMapper::Provider::Basecamp::Ticket

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

Overview

Ticket class for taskmapper-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



45
46
47
48
49
50
51
52
53
54
# File 'lib/provider/ticket.rb', line 45

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
# File 'lib/provider/ticket.rb', line 39

def search(project_id, options = {}, limit = 1000)
  tickets = todo_items(project_id).map {|ti| self.new ti.attributes.merge :project_id => project_id }
  search_by_attribute(tickets, options, limit)
end

Instance Method Details

#assigneeObject



153
154
155
# File 'lib/provider/ticket.rb', line 153

def assignee
  self.responsible_party_name ? self.responsible_party_name : 'Unassigned'
end

#comment!(attributes) ⇒ Object



161
162
163
# File 'lib/provider/ticket.rb', line 161

def comment!(attributes)
  Comment.create id, attributes
end

#copy_to(todo_item) ⇒ Object



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

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



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

def description
  self.content
end

#description=(desc) ⇒ Object



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

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

#priorityObject



115
116
117
# File 'lib/provider/ticket.rb', line 115

def priority
  self.position
end

#priority=(pri) ⇒ Object



123
124
125
# File 'lib/provider/ticket.rb', line 123

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

#requestorObject



157
158
159
# File 'lib/provider/ticket.rb', line 157

def requestor
  self.creator_name
end

#resolutionObject



119
120
121
# File 'lib/provider/ticket.rb', line 119

def resolution
  self.completed ? self.completed : 'In Progress'
end

#saveObject



102
103
104
105
# File 'lib/provider/ticket.rb', line 102

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

#statusObject



111
112
113
# File 'lib/provider/ticket.rb', line 111

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

#titleObject



127
128
129
# File 'lib/provider/ticket.rb', line 127

def title
  self.content
end

#title=(titl) ⇒ Object



131
132
133
# File 'lib/provider/ticket.rb', line 131

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

#todo_list_idObject



107
108
109
# File 'lib/provider/ticket.rb', line 107

def todo_list_id
  self['todo_list_id'].to_i
end

#updated_atObject



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

def updated_at
  self.completed_on.to_time
rescue NoMethodError
  Time.now
end

#updated_at=(comp) ⇒ Object



135
136
137
# File 'lib/provider/ticket.rb', line 135

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