Class: TicketMaster::Provider::Teambox::Ticket

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

Overview

The class to access the api’s tickets

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*object) ⇒ Ticket

declare needed overloaded methods here



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/provider/ticket.rb', line 9

def initialize(*object)
  if object.first
    args = object
    object = args.shift
    project_id = args.shift
    @system_data = {:client => object}
    unless object.is_a? Hash
     hash = {:status => object.status,
             :name => object.name,
             :updated_at => object.updated_at,
             :id => object.id,
             :project_id => project_id.nil? ? object.prefix_options[:project_id] : project_id}
    else
      hash = object
    end
    super hash
  end
end

Class Method Details

.create(*options) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/provider/ticket.rb', line 28

def self.create(*options)
  task = API.new(options.first.merge!(:status => 1,
                                      :updated_at => Time.now
                                      )) 
  ticket = self.new task
  task.save
  ticket
end

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



46
47
48
# File 'lib/provider/ticket.rb', line 46

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

.find_by_id(project_id, task_id) ⇒ Object



37
38
39
# File 'lib/provider/ticket.rb', line 37

def self.find_by_id(project_id, task_id)
  self.search(project_id, {:id => task_id}).first
end

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



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

def self.search(project_id, options = {}, limit = 1000)
  tickets = API.find(:all, :params => {:project_id => project_id}).collect { |ticket| self.new ticket, project_id }
  self.search_by_attribute(tickets, options, limit)
end

Instance Method Details

#comment!(*options) ⇒ Object



58
59
60
61
# File 'lib/provider/ticket.rb', line 58

def comment!(*options)
  options[0].update(:project_id => project_id, :task_id => task_id) if options.first.is_a?(Hash)
  provider_parent(self.class)::Comment.create(*options)
end

#project_idObject



50
51
52
# File 'lib/provider/ticket.rb', line 50

def project_id
  self[:project_id]
end

#task_idObject



54
55
56
# File 'lib/provider/ticket.rb', line 54

def task_id
  self[:id]
end