Class: TicketAbstractorClient::ServiceNow::Attachment

Inherits:
Base::Attachment show all
Defined in:
lib/ticket_abstractor_client/service_now/attachment.rb

Constant Summary

Constants inherited from Base::Attachment

Base::Attachment::SANITIZE_REGEXP

Instance Attribute Summary collapse

Attributes inherited from Base::Attachment

#communications_stack, #data_hash, #external_created_at, #file_path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base::Attachment

#set_data_hash!, #to_hash, #to_json

Constructor Details

#initialize(opts) ⇒ Attachment

Returns a new instance of Attachment.



29
30
31
32
# File 'lib/ticket_abstractor_client/service_now/attachment.rb', line 29

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/attachment.rb', line 4

def endpoint
  @endpoint
end

#projectObject

Returns the value of attribute project.



4
5
6
# File 'lib/ticket_abstractor_client/service_now/attachment.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/attachment.rb', line 4

def ticket_id
  @ticket_id
end

Class Method Details

.fetch(ticket_id, endpoint, project) ⇒ Object



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

def fetch(ticket_id, endpoint, project)
  client = Client.new(endpoint)
  attachments_list = client.get_attachments(ticket_id: ticket_id)
  return [[], client.communications_stack] if attachments_list.blank?

  attachments =
    attachments_list.map do |attachment|
      attachment_data = client.get_attachment_file(sys_id: attachment['sys_id'])
      filepath = save_content(attachment_data.body, attachment['file_name'])
      new(
        file_path: filepath,
        ticket_id: ticket_id,
        endpoint: endpoint,
        project: project,
        communications_stack: client.communications_stack
      )
    end

  [attachments, client.communications_stack]
end

Instance Method Details

#sync!Object



34
35
36
37
38
39
40
# File 'lib/ticket_abstractor_client/service_now/attachment.rb', line 34

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

  response
end