Class: TicketAbstractorClient::Base::Ticket

Inherits:
Object
  • Object
show all
Defined in:
lib/ticket_abstractor_client/base/ticket.rb

Direct Known Subclasses

Jira::Ticket, ServiceNow::Ticket

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Ticket

Returns a new instance of Ticket.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 7

def initialize(opts = {})
  opts = opts.with_indifferent_access
  @ticket_id = opts[:ticket_id]
  @fields = opts.fetch(:fields, {}).with_indifferent_access
  @endpoint = opts[:endpoint] || raise(Errors::TicketArgumentError, 'Endpoint is not given')
  @project = opts[:project]
  @communications_stack = opts[:communications_stack] || []
  @attachments ||= []
  @comments ||= []
  initialize_changes!
  mark_changes!
end

Instance Attribute Details

#attachmentsObject (readonly)

Returns the value of attribute attachments.



4
5
6
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 4

def attachments
  @attachments
end

#changesObject (readonly)

Returns the value of attribute changes.



4
5
6
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 4

def changes
  @changes
end

#commentsObject (readonly)

Returns the value of attribute comments.



4
5
6
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 4

def comments
  @comments
end

#communications_stackObject

Returns the value of attribute communications_stack.



5
6
7
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 5

def communications_stack
  @communications_stack
end

#endpointObject

Returns the value of attribute endpoint.



5
6
7
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 5

def endpoint
  @endpoint
end

#fieldsObject

Returns the value of attribute fields.



5
6
7
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 5

def fields
  @fields
end

#projectObject

Returns the value of attribute project.



5
6
7
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 5

def project
  @project
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 4

def status
  @status
end

#ticket_idObject

Returns the value of attribute ticket_id.



5
6
7
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 5

def ticket_id
  @ticket_id
end

Instance Method Details

#add_attachment(attachment) ⇒ Object



20
21
22
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 20

def add_attachment(attachment)
  self.class.not_implemented __method__
end

#add_comment(comment) ⇒ Object



24
25
26
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 24

def add_comment(comment)
  self.class.not_implemented __method__
end

#any_changes?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 28

def any_changes?
  @changes.values.any? { |value| value.is_a?(Fixnum) ? !value.zero? : value.present? }
end

#reset_changes!Object



32
33
34
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 32

def reset_changes!
  initialize_changes!
end

#sync!Object



42
43
44
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 42

def sync!
  self.class.not_implemented __method__
end

#to_hashObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 46

def to_hash
  {
    ticket_id: self.ticket_id,
    status: self.status,
    updated_at: self.updated_at,
    fields: self.fields,
    comments: self.comments.map(&:to_hash),
    attachments: self.attachments.map(&:to_hash)
  }
end

#to_jsonObject



57
58
59
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 57

def to_json
  to_hash.to_json
end

#updated_atObject



61
62
63
# File 'lib/ticket_abstractor_client/base/ticket.rb', line 61

def updated_at
  self.class.not_implemented __method__
end