Module: TicketAbstractorClient::ServiceNow::ParamsBuilder

Extended by:
ActiveSupport::Concern
Included in:
Client
Defined in:
lib/ticket_abstractor_client/service_now/params_builder.rb

Instance Method Summary collapse

Instance Method Details

#build_all_tickets_params(opts) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/ticket_abstractor_client/service_now/params_builder.rb', line 6

def build_all_tickets_params(opts)
  opts[:table_name] = opts[:project]
  opts[:sysparm_query] = build_sysparm_query(opts)
  opts[:sysparm_fields] = Array.wrap(opts.delete(:fields))
  opts.except!(:service_desk, :states)
  opts[:display_value] = TicketAbstractorClient.configuration.snow_display_value if opts[:display_value].nil?
  opts
end

#build_attachment_params(attachment) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ticket_abstractor_client/service_now/params_builder.rb', line 15

def build_attachment_params(attachment)
  file_path = attachment.file_path
  mime_type = MIME::Types.type_for(file_path).first.try(:to_s) || '*/*'
  [
    {
      table_name: attachment.project,
      table_sys_id: attachment.ticket_id,
      file_name: File.basename(file_path),
      content_type: mime_type
    },
    {
      attachments: [File.new(file_path, 'rb')]
    }
  ]
end

#build_comment_params(comment) ⇒ Object



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

def build_comment_params(comment)
  {
    comment_params: { comments: comment.body },
    sys_id: comment.ticket_id,
    table_name: comment.project,
    display_value: TicketAbstractorClient.configuration.snow_display_value
  }
end

#build_status_params(ticket) ⇒ Object



40
41
42
# File 'lib/ticket_abstractor_client/service_now/params_builder.rb', line 40

def build_status_params(ticket)
  { ticket_params: { state: ticket.status }, sys_id: ticket.sys_id, table_name: ticket.project }
end

#build_sysparm_query(opts) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/ticket_abstractor_client/service_now/params_builder.rb', line 50

def build_sysparm_query(opts)
  sysparm_query = {
    'u_support_fieldLIKE' => opts[:service_desk],
    'u_input_source=' => 'OIV',
    '' => opts.fetch(:states, '').split(',').map { |st| "state=#{st}" }.join('^OR')
  }
  sysparm_query.select { |_, v| v.present? }.map { |k, v| [k, v].join }.join('^')
end

#build_ticket_params(ticket) ⇒ Object



44
45
46
47
48
# File 'lib/ticket_abstractor_client/service_now/params_builder.rb', line 44

def build_ticket_params(ticket)
  opts = { ticket_params: ticket.fields, table_name: ticket.project }
  opts.merge!(sys_id: ticket.sys_id) if ticket.sys_id.present?
  opts
end