Class: WixAnswers::Models::Ticket

Inherits:
Base
  • Object
show all
Defined in:
lib/wixanswers/models/ticket/ticket.rb

Direct Known Subclasses

ByAgent, Chat, PhoneCallback, Widget

Instance Attribute Summary

Attributes inherited from Base

#attrs

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#method_missing, #validate!, #validate_schema!

Constructor Details

#initialize(attrs = {}) ⇒ Ticket

Returns a new instance of Ticket.



53
54
55
# File 'lib/wixanswers/models/ticket/ticket.rb', line 53

def initialize(attrs={})
  super(attrs)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class WixAnswers::Models::Base

Class Method Details

.from_payload(payload) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/wixanswers/models/ticket/ticket.rb', line 97

def self.from_payload(payload)
  Enumerations::Channel.validate!(payload[:channel])

  case payload[:channel]
    when Enumerations::Channel::WEB
      payload[:type].nil? ? Models::Ticket.new(payload) : Models::Reply.new(payload)
    when Enumerations::Channel::BY_AGENT
      Models::ByAgent.new(payload)
    when Enumerations::Channel::EMAIL
      payload[:type].nil? ? Models::Ticket.new(payload) : Models::Reply.new(payload)
    when Enumerations::Channel::PHONE_CALLBACK
      Models::PhoneCallback.new(payload)
    when Enumerations::Channel::WIDGET
      Models::Widget.new(payload)
    else
      raise Exceptions::NotImplementedError.new('Channel', payload[:channel])
  end
end

Instance Method Details

#all_cc_usersObject



93
94
95
# File 'lib/wixanswers/models/ticket/ticket.rb', line 93

def all_cc_users
  @_all_cc_users ||= (self.attrs[:allCcUsers] || []).map {|attrs| User.new(attrs)}
end

#assigned_byObject



77
78
79
# File 'lib/wixanswers/models/ticket/ticket.rb', line 77

def assigned_by
  @_assigned_by ||= User.new(self.attrs[:assignedBy] || {})
end

#assigned_groupObject



89
90
91
# File 'lib/wixanswers/models/ticket/ticket.rb', line 89

def assigned_group
  @_assigned_group ||= Group.new(self.attrs[:assignedGroup] || {})
end

#assigned_userObject



85
86
87
# File 'lib/wixanswers/models/ticket/ticket.rb', line 85

def assigned_user
  @_assigned_user ||= Agent.new(self.attrs[:assignedUser] || {})
end

#attachmentsObject



57
58
59
# File 'lib/wixanswers/models/ticket/ticket.rb', line 57

def attachments
  @_attachments ||= (self.attrs[:attachments] || []).map {|attrs| Attachment.new(attrs)}
end

#created_by_agentObject



81
82
83
# File 'lib/wixanswers/models/ticket/ticket.rb', line 81

def created_by_agent
  @_created_by_agent ||= User.new(self.attrs[:createdByAgent] || {})
end

#labelsObject



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

def labels
  @_labels ||= (self.attrs[:labels] || []).map {|attrs| Label.new(attrs)}
end

#last_replyObject



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

def last_reply
  @_last_reply ||= Reply.new(self.attrs[:lastReply] || {})
end

#userObject



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

def user
  @_user ||= User.new(self.attrs[:user] || {})
end

#user_infoObject



61
62
63
# File 'lib/wixanswers/models/ticket/ticket.rb', line 61

def 
  @_user_info ||= UserInfo.new(self.attrs[:userInfo] || {})
end