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

Returns What agent is currently assigned to the ticket.

Returns:

  • (Integer)

    What agent is currently assigned to the ticket



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

attribute :assignee_id, type: :integer

#auditsZendesk2::TicketAudits

Returns all audits for this ticket.

Returns:



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

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

#brand_idInteger

Returns Enterprise only. The id of the brand this ticket is associated with.

Returns:

  • (Integer)

    Enterprise only. The id of the brand this ticket is associated with



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

attribute :brand_id

#collaborator_idsArray

Returns Who are currently CC’ed on the ticket.

Returns:

  • (Array)

    Who are currently CC’ed on the ticket



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

attribute :collaborator_ids, type: :array

#collaboratorsArray<Zendesk2::User>

Returns All users CCD on this ticket.

Returns:



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

Parameters:

  • text (String)

    comment body

  • options (Hash) (defaults to: {})

    comment options

Options Hash (options):

  • :attachments (Array)

    Attachment to upload with comment

  • :public (Boolean) — default: true

Returns:



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>

Returns all comments for this ticket.

Returns:



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

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

#created_atTime

Returns When this record was created.

Returns:

  • (Time)

    When this record was created



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

attribute :created_at, type: :time

#custom_fieldsArray

Returns The custom fields of the ticket.

Returns:

  • (Array)

    The custom fields of the ticket



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

attribute :custom_fields, type: :array

#descriptionString

Returns The first comment on the ticket.

Returns:

  • (String)

    The first comment on the ticket



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

Returns If this is a ticket of type “task” it has a due date. Due date format uses ISO 8601 format.

Returns:

  • (Time)

    If this is a ticket of type “task” it has a due date. Due date format uses ISO 8601 format.



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

attribute :due_at, type: :time

#external_idString

Returns A unique external id, you can use this to link Zendesk tickets to local records.

Returns:

  • (String)

    A unique external id, you can use this to link Zendesk tickets to local records



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

attribute :external_id, type: :string

#forum_topic_idInteger

Returns The topic this ticket originated from, if any.

Returns:

  • (Integer)

    The topic this ticket originated from, if any



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

attribute :forum_topic_id, type: :integer

#group_idInteger

Returns The group this ticket is assigned to.

Returns:

  • (Integer)

    The group this ticket is assigned to



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

attribute :group_id, type: :integer

#has_incidentsBoolean

Returns Is true of this ticket has been marked as a problem, false otherwise.

Returns:

  • (Boolean)

    Is true of this ticket has been marked as a problem, false otherwise



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

attribute :has_incidents, type: :boolean

#idInteger

Returns Automatically assigned when creating tickets.

Returns:

  • (Integer)

    Automatically assigned when creating tickets



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

identity :id, type: :integer

#metricsZendesk2::TicketMetric

Returns metrics for this ticket.

Returns:



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

Returns organization assigned to ticket.

Returns:



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

assoc_reader :organization

#organization_idInteger

Returns The organization of the requester.

Returns:

  • (Integer)

    The organization of the requester



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

attribute :organization_id, type: :integer

#priorityString

Returns Priority, defines the urgency with which the ticket should be addressed: “urgent”, “high”, “normal”, “low”.

Returns:

  • (String)

    Priority, defines the urgency with which the ticket should be addressed: “urgent”, “high”, “normal”, “low”



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

attribute :priority, type: :string

#problem_idInteger

Returns The problem this incident is linked to, if any.

Returns:

  • (Integer)

    The problem this incident is linked to, if any



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

attribute :problem_id, type: :integer

#recipientString

Returns The original recipient e-mail address of the ticket.

Returns:

  • (String)

    The original recipient e-mail address of the ticket



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

attribute :recipient, type: :string

#requesterZendesk2::User

Returns user that requested the ticket.

Returns:



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

assoc_accessor :requester, collection: :users

#requester_idInteger

Returns The user who requested this ticket.

Returns:

  • (Integer)

    The user who requested this ticket



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

attribute :requester_id, type: :integer

#satisfaction_ratingHash

Returns The satisfaction rating of the ticket, if it exists.

Returns:

  • (Hash)

    The satisfaction rating of the ticket, if it exists



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

Returns The ids of the sharing agreements used for this ticket.

Returns:

  • (Array)

    The ids of the sharing agreements used for this ticket



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

attribute :sharing_agreement_ids, type: :array

#statusString

Returns The state of the ticket, “new”, “open”, “pending”, “hold”, “solved”, “closed”.

Returns:

  • (String)

    The state of the ticket, “new”, “open”, “pending”, “hold”, “solved”, “closed”



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

attribute :status, type: :string

#subjectString

Returns The value of the subject field for this ticket.

Returns:

  • (String)

    The value of the subject field for this ticket



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

attribute :subject, type: :string

#submitterZendesk2::User

Returns user that submitted the ticket.

Returns:



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

assoc_reader :submitter, collection: :users

#submitter_idInteger

Returns The user who submitted the ticket; this is the currently authenticated API user.

Returns:

  • (Integer)

    The user who submitted the ticket; this is the currently authenticated API user



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

attribute :submitter_id, type: :integer

#tagsArray

Returns The array of tags applied to this ticket.

Returns:

  • (Array)

    The array of tags applied to this ticket



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

attribute :tags, type: :array

#ticket_form_idInteger

Returns Enterprise only. The id of the ticket form to render for the ticket.

Returns:

  • (Integer)

    Enterprise only. The id of the ticket form to render for the ticket



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

attribute :ticket_form_id

#typeString

Returns The type of this ticket, i.e. “problem”, “incident”, “question” or “task”.

Returns:

  • (String)

    The type of this ticket, i.e. “problem”, “incident”, “question” or “task”



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

attribute :type, type: :string

#updated_atTime

Returns When this record last got updated.

Returns:

  • (Time)

    When this record last got updated



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

attribute :updated_at, type: :time

#urlString

Returns The API url of this ticket.

Returns:

  • (String)

    The API url of this ticket



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

attribute :url, type: :string

#viaHash

Returns This object explains how the ticket was created.

Returns:

  • (Hash)

    This object explains how the ticket was created



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

attribute :via