Module: Legion::Extensions::ServiceNow::Attachment::Runners::Attachment

Includes:
Helpers::Lex, Helpers::Client
Included in:
Client
Defined in:
lib/legion/extensions/service_now/attachment/runners/attachment.rb

Instance Method Summary collapse

Methods included from Helpers::Client

#connection, #fetch_oauth2_token, #handle_response

Instance Method Details

#delete_attachment(sys_id:) ⇒ Object



43
44
45
46
# File 'lib/legion/extensions/service_now/attachment/runners/attachment.rb', line 43

def delete_attachment(sys_id:, **)
  resp = connection(**).delete("/api/now/attachment/#{sys_id}")
  { deleted: resp.status == 204, sys_id: sys_id }
end

#get_attachment(sys_id:) ⇒ Object



21
22
23
24
# File 'lib/legion/extensions/service_now/attachment/runners/attachment.rb', line 21

def get_attachment(sys_id:, **)
  resp = connection(**).get("/api/now/attachment/#{sys_id}")
  { attachment: resp.body['result'] }
end

#get_attachment_file(sys_id:) ⇒ Object



26
27
28
29
# File 'lib/legion/extensions/service_now/attachment/runners/attachment.rb', line 26

def get_attachment_file(sys_id:, **)
  resp = connection(**).get("/api/now/attachment/#{sys_id}/file")
  { content: resp.body, status: resp.status }
end

#list_attachments(table_name: nil, table_sys_id: nil, sysparm_limit: 100, sysparm_offset: 0) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/legion/extensions/service_now/attachment/runners/attachment.rb', line 13

def list_attachments(table_name: nil, table_sys_id: nil, sysparm_limit: 100,
                     sysparm_offset: 0, **)
  params = { sysparm_limit: sysparm_limit, sysparm_offset: sysparm_offset }
  params[:sysparm_query] = "table_name=#{table_name}^table_sys_id=#{table_sys_id}" if table_name && table_sys_id
  resp = connection(**).get('/api/now/attachment', params)
  { attachments: resp.body['result'] }
end

#upload_attachment(table_name:, table_sys_id:, file_name:, content_type:, content:) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/legion/extensions/service_now/attachment/runners/attachment.rb', line 31

def upload_attachment(table_name:, table_sys_id:, file_name:, content_type:, content:, **)
  upload_conn = upload_connection(**)
  resp = upload_conn.post('/api/now/attachment/file') do |req|
    req.params['table_name']   = table_name
    req.params['table_sys_id'] = table_sys_id
    req.params['file_name']    = file_name
    req.headers['Content-Type'] = content_type
    req.body = content
  end
  { attachment: resp.body['result'] }
end