Class: Zendesk2::Ticket

Inherits:
Object
  • Object
show all
Extended by:
Attributes
Includes:
Model
Defined in:
lib/zendesk2/ticket.rb

Instance Attribute Summary

Attributes included from Model

#errors

Instance Method Summary collapse

Methods included from Attributes

assoc_accessor, assoc_reader, assoc_writer

Methods included from Model

#destroy, #destroyed?, #missing_attributes, #save, #update!

Instance Method Details

#assignee_idInteger



10
# File 'lib/zendesk2/ticket.rb', line 10

attribute :assignee_id, type: :integer

#auditsZendesk2::TicketAudits



123
124
125
# File 'lib/zendesk2/ticket.rb', line 123

def audits
  cistern.ticket_audits(ticket_id: identity).all
end

#brand_idInteger



63
# File 'lib/zendesk2/ticket.rb', line 63

attribute :brand_id

#collaborator_idsArray



12
# File 'lib/zendesk2/ticket.rb', line 12

attribute :collaborator_ids, type: :array

#collaboratorsArray<Zendesk2::User>



138
139
140
# File 'lib/zendesk2/ticket.rb', line 138

def collaborators
  (collaborator_ids || []).map { |id| cistern.users.get(id) }
end

#collaborators=(collaborators) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/zendesk2/ticket.rb', line 142

def collaborators=(collaborators)
  collaborators = [collaborators] unless collaborators.is_a?(Array)

  value = collaborators.map do |collaborator|
    case collaborator
    when Zendesk2::User
      collaborator.identity
    else
      collaborator
    end
  end

  attributes[:collaborators] = value
end

#comment(text, options = {}) ⇒ Zendesk2::TicketComment

Adds a ticket comment

Options Hash (options):

  • :attachments (Array)

    Attachment to upload with comment

  • :public (Boolean) — default: true


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/zendesk2/ticket.rb', line 105

def comment(text, options = {})
  requires :identity

  options[:public] = true if options[:public].nil?

  comment = Zendesk2.stringify_keys(options).merge('body' => text)

  cistern.ticket_comments.new(
    cistern.update_ticket(
      'ticket' => {
        'id'      => identity,
        'comment' => comment,
      }
    ).body['audit']['events'].first
  )
end

#commentsArray<Zendesk2::TicketComment>



133
134
135
# File 'lib/zendesk2/ticket.rb', line 133

def comments
  cistern.ticket_comments(ticket_id: identity).all
end

#created_atTime



14
# File 'lib/zendesk2/ticket.rb', line 14

attribute :created_at, type: :time

#custom_fieldsArray



16
# File 'lib/zendesk2/ticket.rb', line 16

attribute :custom_fields, type: :array

#descriptionString



18
# File 'lib/zendesk2/ticket.rb', line 18

attribute :description, type: :string

#destroy!Object



92
93
94
95
96
# File 'lib/zendesk2/ticket.rb', line 92

def destroy!
  requires :identity

  cistern.destroy_ticket('ticket' => { 'id' => identity })
end

#due_atTime



20
# File 'lib/zendesk2/ticket.rb', line 20

attribute :due_at, type: :time

#external_idString



22
# File 'lib/zendesk2/ticket.rb', line 22

attribute :external_id, type: :string

#forum_topic_idInteger



24
# File 'lib/zendesk2/ticket.rb', line 24

attribute :forum_topic_id, type: :integer

#group_idInteger



26
# File 'lib/zendesk2/ticket.rb', line 26

attribute :group_id, type: :integer

#has_incidentsBoolean



28
# File 'lib/zendesk2/ticket.rb', line 28

attribute :has_incidents, type: :boolean

#idInteger



8
# File 'lib/zendesk2/ticket.rb', line 8

identity :id, type: :integer

#metricsZendesk2::TicketMetric



128
129
130
# File 'lib/zendesk2/ticket.rb', line 128

def metrics
  Zendesk2::TicketMetric.new(cistern.get_ticket_metric('ticket_id' => identity).body['ticket_metric'])
end

#organizationZendesk2::Organization



66
# File 'lib/zendesk2/ticket.rb', line 66

assoc_reader :organization

#organization_idInteger



30
# File 'lib/zendesk2/ticket.rb', line 30

attribute :organization_id, type: :integer

#priorityString



33
# File 'lib/zendesk2/ticket.rb', line 33

attribute :priority, type: :string

#problem_idInteger



35
# File 'lib/zendesk2/ticket.rb', line 35

attribute :problem_id, type: :integer

#recipientString



37
# File 'lib/zendesk2/ticket.rb', line 37

attribute :recipient, type: :string

#requesterZendesk2::User



68
# File 'lib/zendesk2/ticket.rb', line 68

assoc_accessor :requester, collection: :users

#requester_idInteger



39
# File 'lib/zendesk2/ticket.rb', line 39

attribute :requester_id, type: :integer

#satisfaction_ratingHash



41
# File 'lib/zendesk2/ticket.rb', line 41

attribute :satisfaction_rating

#save!Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/zendesk2/ticket.rb', line 72

def save!
  data = if new_record?
           requires :subject, :description

           create_attributes = attributes.dup

           with_requester = (@requester || nil) && Zendesk2.stringify_keys(@requester)

           with_requester && create_attributes['requester'] = with_requester

           cistern.create_ticket('ticket' => create_attributes).body['ticket']
         else
           requires :identity

           cistern.update_ticket('ticket' => attributes).body['ticket']
         end

  merge_attributes(data)
end

#sharing_agreement_idsArray



43
# File 'lib/zendesk2/ticket.rb', line 43

attribute :sharing_agreement_ids, type: :array

#statusString



45
# File 'lib/zendesk2/ticket.rb', line 45

attribute :status, type: :string

#subjectString



47
# File 'lib/zendesk2/ticket.rb', line 47

attribute :subject, type: :string

#submitterZendesk2::User



70
# File 'lib/zendesk2/ticket.rb', line 70

assoc_reader :submitter, collection: :users

#submitter_idInteger



49
# File 'lib/zendesk2/ticket.rb', line 49

attribute :submitter_id, type: :integer

#tagsArray



51
# File 'lib/zendesk2/ticket.rb', line 51

attribute :tags, type: :array

#ticket_form_idInteger



61
# File 'lib/zendesk2/ticket.rb', line 61

attribute :ticket_form_id

#typeString



53
# File 'lib/zendesk2/ticket.rb', line 53

attribute :type, type: :string

#updated_atTime



55
# File 'lib/zendesk2/ticket.rb', line 55

attribute :updated_at, type: :time

#urlString



57
# File 'lib/zendesk2/ticket.rb', line 57

attribute :url, type: :string

#viaHash



59
# File 'lib/zendesk2/ticket.rb', line 59

attribute :via