Class: TaskMapper::Provider::Zendesk::Ticket

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

Constant Summary collapse

SEARCH_API =

declare needed overloaded methods here

ZendeskAPI::Search
API =
ZendeskAPI::Ticket
USER_API =
ZendeskAPI::User

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*object) ⇒ Ticket

Returns a new instance of Ticket.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/provider/ticket.rb', line 12

def initialize(*object)
  return super(object.first) if object.first.is_a? Hash 
  if object.first 
    args = object.first
    object = args.shift
    project_id = args.shift
    @system_data = {:client => object}
    unless object.is_a? Hash
      hash = {:id => object.nice_id,
              :status => object.status_id,
              :title => object.subject,
              :created_at => object.created_at,
              :updated_at => object.updated_at,
              :description => object.description,
              :assignee => object.assignee_id,
              :requestor => object.requester_id,
              :priority => object.priority_id,
              :project_id => project_id}
    else
      hash = object
    end
    super hash
  end
end

Class Method Details

.find(project_id, *options) ⇒ Object



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

def self.find(project_id, *options)
  tickets = self.find_all(project_id)
  if options[0].first.is_a? Array
    Ticket.find_all(self.name).select { |ticket| ticket if options[0].first.any? { |ticket_id| ticket_id == ticket.id }}
  elsif options[0].first.is_a? Hash
    Ticket.find_by_attributes(self.name, options[0].first)
  else
    tickets
  end
end

.find_all(*options) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/provider/ticket.rb', line 56

def self.find_all(*options)
  project_id = options.first
  SEARCH_API.find(:all, :params => {:query => "status:open"}).collect do |ticket| 
    ticket.requester_id = requestor(ticket)
    ticket.assignee_id = assignee(ticket)
    self.new([ticket, project_id])
  end
end

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



69
70
71
# File 'lib/provider/ticket.rb', line 69

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

.find_by_id(project_id, ticket_id) ⇒ Object



65
66
67
# File 'lib/provider/ticket.rb', line 65

def self.find_by_id(project_id, ticket_id)
  self.new [API.find(ticket_id), project_id]
end

Instance Method Details

#comment(*options) ⇒ Object



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

def comment(*options)
  if options.first.is_a? Fixnum
    Comment.find(project_id, id, [options.first]).first
  elsif options.first.is_a? Hash
    Comment.find_by_attributes(project_id, id, options.first).first
  end
end

#comments(*options) ⇒ Object



73
74
75
# File 'lib/provider/ticket.rb', line 73

def comments(*options)
  Comment.find(project_id, id, options)
end

#created_atObject



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

def created_at
  Time.parse(self[:created_at])
end

#updated_atObject



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

def updated_at
  Time.parse(self[:updated_at])
end