class TicketAbstractorClient::ServiceNow::Attachment

Attributes

endpoint[RW]
project[RW]
ticket_id[RW]

Public Class Methods

fetch(ticket_id, endpoint, project) click to toggle source
# 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
new(opts) click to toggle source
# 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

Public Instance Methods

sync!() click to toggle source
# 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