Class: TicketAbstractorClient::ServiceNow::Comment

Inherits:
Base::Comment
  • Object
show all
Defined in:
lib/ticket_abstractor_client/service_now/comment.rb

Instance Attribute Summary collapse

Attributes inherited from Base::Comment

#author, #body, #communications_stack, #data_hash, #external_created_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base::Comment

#set_data_hash!, #to_hash, #to_json

Constructor Details

#initialize(opts) ⇒ Comment

Returns a new instance of Comment.



26
27
28
29
# File 'lib/ticket_abstractor_client/service_now/comment.rb', line 26

def initialize(opts)
  super(opts)
  @ticket_id, @endpoint, @project = opts.values_at(:ticket_id, :endpoint, :project)
end

Instance Attribute Details

#endpointObject

Returns the value of attribute endpoint.



4
5
6
# File 'lib/ticket_abstractor_client/service_now/comment.rb', line 4

def endpoint
  @endpoint
end

#projectObject

Returns the value of attribute project.



4
5
6
# File 'lib/ticket_abstractor_client/service_now/comment.rb', line 4

def project
  @project
end

#ticket_idObject

Returns the value of attribute ticket_id.



4
5
6
# File 'lib/ticket_abstractor_client/service_now/comment.rb', line 4

def ticket_id
  @ticket_id
end

Class Method Details

.fetch(ticket_id, endpoint, project) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ticket_abstractor_client/service_now/comment.rb', line 6

def self.fetch(ticket_id, endpoint, project)
  client = Client.new(endpoint)
  response = client.get_comments(ticket_id: ticket_id, project: project)

  comments =
    response.map do |raw_comment|
      new({
        author: raw_comment['sys_created_by'],
        body: raw_comment['value'],
        external_created_at: raw_comment['sys_created_on'],
        ticket_id: ticket_id,
        endpoint: endpoint,
        project: project,
        communications_stack: client.communications_stack
      })
    end

  [comments, client.communications_stack]
end

Instance Method Details

#sync!Object



31
32
33
34
35
36
37
# File 'lib/ticket_abstractor_client/service_now/comment.rb', line 31

def sync!
  client = Client.new(@endpoint)
  response = client.create_comment(self)
  @communications_stack = client.communications_stack

  response
end