Class: TaskMapper::Provider::Zendesk::Comment

Inherits:
Base::Comment
  • Object
show all
Defined in:
lib/provider/comment.rb

Overview

The comment class for taskmapper-zendesk

Do any mapping between taskmapper and your system’s comment model here versions of the ticket.

Constant Summary collapse

USER_API =

declare needed overloaded methods here

ZendeskAPI::User

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*object) ⇒ Comment

Returns a new instance of Comment.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/provider/comment.rb', line 13

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

Class Method Details

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



57
58
59
# File 'lib/provider/comment.rb', line 57

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

.find_by_id(project_id, ticket_id, id) ⇒ Object



53
54
55
# File 'lib/provider/comment.rb', line 53

def find_by_id(project_id, ticket_id, id) 
  search(project_id, ticket_id).find { |ticket| ticket.id == id } 
end

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



43
44
45
46
47
48
49
50
51
# File 'lib/provider/comment.rb', line 43

def search(project_id, ticket_id, options = {}, limit = 1000)
  comment_id = 0
  ZendeskAPI::Ticket.find(ticket_id).comments.collect do |comment|
    comment_id += 1
    self.new comment.attributes.merge!(:project_id => project_id,
                                       :ticket_id => ticket_id,
                                       :comment_id => comment_id)
  end
end

Instance Method Details

#authorObject



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

def author
  USER_API.find(comment.author_id).email
end

#created_atObject



34
35
36
# File 'lib/provider/comment.rb', line 34

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

#idObject



30
31
32
# File 'lib/provider/comment.rb', line 30

def id
  self.comment_id
end

#updated_atObject



38
39
40
# File 'lib/provider/comment.rb', line 38

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