class TicketAbstractorClient::ServiceNow::Client

Constants

SYS_ID_LENGTH
TICKET_NOT_FOUND

Public Class Methods

new(endpoint = 'default') click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 9
def initialize(endpoint = 'default')
  super()
  @service_now_endpoint = endpoint
end

Public Instance Methods

create_attachment(attachment) click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 55
def create_attachment(attachment)
  attachment.ticket_id = get_ticket_sys_id(ticket_id: attachment.ticket_id, table_name: attachment.project)

  args, params = build_attachment_params(attachment)
  post(__method__, args, params)
end
create_comment(comment) click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 62
def create_comment(comment)
  comment.ticket_id = get_ticket_sys_id(ticket_id: comment.ticket_id, table_name: comment.project)
  post(__method__, build_comment_params(comment))
end
create_ticket(ticket) click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 67
def create_ticket(ticket)
  post(__method__, build_ticket_params(ticket))
end
endpoints() click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 34
def endpoints
  get(__method__)
end
get_all_tickets(opts) click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 14
def get_all_tickets(opts)
  get_tickets_by_query(build_all_tickets_params(opts))
end
get_attachment_file(opts) click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 23
def get_attachment_file(opts)
  get(__method__, opts)
end
get_attachments(opts) click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 18
def get_attachments(opts)
  opts[:ticket_id] = get_ticket_sys_id(opts)
  get(__method__, opts)
end
get_comments(opts) click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 27
def get_comments(opts)
  opts[:table_name] = opts[:project]
  opts[:sys_id] = get_ticket_sys_id(opts)
  opts[:display_value] = TicketAbstractorClient.configuration.snow_display_value if opts[:display_value].nil?
  get(__method__, opts)
end
get_ticket_by_id(opts) click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 38
def get_ticket_by_id(opts)
  opts[:table_name] = opts[:project]
  opts[:sys_id] = get_ticket_sys_id(opts)
  opts[:display_value] = TicketAbstractorClient.configuration.snow_display_value if opts[:display_value].nil?
  get(__method__, opts)
end
get_tickets_by_query(opts) click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 45
def get_tickets_by_query(opts)
  opts[:table_name] = opts[:project]
  opts[:display_value] = TicketAbstractorClient.configuration.snow_display_value if opts[:display_value].nil?
  get(__method__, opts)
end
get_users(opts) click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 51
def get_users(opts)
  get(__method__, opts)
end
update_ticket(ticket) click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 71
def update_ticket(ticket)
  ticket.sys_id = get_ticket_sys_id(ticket_id: ticket.ticket_id, table_name: ticket.project)
  post(__method__, build_ticket_params(ticket))
end
update_ticket_status(ticket) click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 76
def update_ticket_status(ticket)
  ticket.sys_id = get_ticket_sys_id(ticket_id: ticket.ticket.id, table_name: ticket.project)
  post(:update_ticket, build_status_params(ticket))
end

Protected Instance Methods

get(path, args = {}, params = {}) click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 93
def get(path, args = {}, params = {})
  super("service_now/#{path}", args, params.merge(service_now_endpoint: @service_now_endpoint))
end
get_ticket_sys_id(opts) click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 83
def get_ticket_sys_id(opts)
  return opts[:ticket_id] if opts[:ticket_id].length == SYS_ID_LENGTH

  response = get(__method__, opts)

  raise(Errors::NotFoundError, TICKET_NOT_FOUND) if response.blank?

  response[0]['sys_id']
end
post(path, args = {}, params = {}) click to toggle source
# File lib/ticket_abstractor_client/service_now/client.rb, line 97
def post(path, args = {}, params = {})
  super("service_now/#{path}", args, params.merge(service_now_endpoint: @service_now_endpoint))
end