Class: Zensana::Zendesk::Ticket

Inherits:
Object
  • Object
show all
Includes:
Validate::Key, Access
Defined in:
lib/zensana/models/zendesk/ticket.rb

Constant Summary collapse

REQUIRED_KEYS =
[:requester_id ]
OPTIONAL_KEYS =
[
  :external_id, :type, :subject, :description, :priority, :status,
  :submitter_id, :assignee_id, :group_id, :collaborator_ids, :tags,
  :created_at, :updated_id, :comments, :solved_at, :updated_at
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Validate::Key

#has_required_keys?, #has_unknown_keys?, #optional_keys, #required_keys, #valid_keys, #validate_keys

Methods included from Access

#zendesk_service

Constructor Details

#initialize(attributes) ⇒ Ticket

Returns a new instance of Ticket.



26
27
28
# File 'lib/zensana/models/zendesk/ticket.rb', line 26

def initialize(attributes)
  @attributes = attributes || {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



52
53
54
# File 'lib/zensana/models/zendesk/ticket.rb', line 52

def method_missing(name, *args, &block)
  attributes[name.to_s] || super
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



24
25
26
# File 'lib/zensana/models/zendesk/ticket.rb', line 24

def attributes
  @attributes
end

Class Method Details

.external_id_exists?(external_id) ⇒ Boolean

if external_id is present for a ticket in ZenDesk then we can say that it was already created

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/zensana/models/zendesk/ticket.rb', line 11

def self.external_id_exists?(external_id)
  query = "/search.json?query=type:ticket,,external_id:#{external_id}"
  external_id && (result = Zensana::Zendesk.inst.fetch(query)['results']) &&
    ! (result.nil? || result.empty?)
end

Instance Method Details

#external_idObject



48
49
50
# File 'lib/zensana/models/zendesk/ticket.rb', line 48

def external_id
  attributes['external_id']
end

#find(id) ⇒ Object



30
31
32
# File 'lib/zensana/models/zendesk/ticket.rb', line 30

def find(id)
  @attributes = fetch(id)
end

#idObject



44
45
46
# File 'lib/zensana/models/zendesk/ticket.rb', line 44

def id
  attributes['id']
end

#import(attributes = @attributes) ⇒ Object

Raises:



34
35
36
37
38
# File 'lib/zensana/models/zendesk/ticket.rb', line 34

def import(attributes=@attributes)
  validate_keys attributes
  raise AlreadyExists, "This ticket has already been imported with id #{self.id}" if imported?
  import_ticket(attributes)
end

#imported?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/zensana/models/zendesk/ticket.rb', line 40

def imported?
  !! id
end