Class: TicketMaster::Provider::Zendesk::Comment

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

Overview

The comment class for ticketmaster-zendesk

Do any mapping between Ticketmaster 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
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/provider/comment.rb', line 13

def initialize(*object)
  return super(object.first) if object.first.is_a? Hash 
  if object.first
    object = object.first
    ticket_id = object.shift
    project_id = object.shift
    comment_id = object.shift
    object = object.shift
    @system_data = {:client => object}
    unless object.is_a? Hash
      hash = {:author => object.author_id,
              :body => object.value,
              :id => comment_id,
              :created_at => object.created_at,
              :updated_at => object.created_at,
              :ticket_id => ticket_id,
              :project_id => project_id}
    else
      hash = object
    end
    super hash
  end
end

Class Method Details

.find(project_id, ticket_id, *options) ⇒ Object



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

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

.find_all(project_id, ticket_id) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/provider/comment.rb', line 58

def self.find_all(project_id, ticket_id)
  comment_id = 0
  ZendeskAPI::Ticket.find(ticket_id).comments.collect do |comment|
    comment_id += 1
    comment.author_id = USER_API.find(comment.author_id).email
    Comment.new [ticket_id, project_id, comment_id, comment]
  end
end

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



67
68
69
# File 'lib/provider/comment.rb', line 67

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

Instance Method Details

#created_atObject



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

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

#updated_atObject



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

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