Module: Legion::Extensions::ServiceNow::Account::Runners::Account

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

Instance Method Summary collapse

Methods included from Helpers::Client

#connection, #fetch_oauth2_token

Instance Method Details

#create_account(name:, phone: nil, email: nil) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/legion/extensions/service_now/account/runners/account.rb', line 23

def (name:, phone: nil, email: nil, **)
  body = { name: name }
  body[:phone] = phone if phone
  body[:email] = email if email
  resp = connection(**).post('/api/now/account', body)
  { account: resp.body['result'] }
end

#get_account(sys_id:) ⇒ Object



18
19
20
21
# File 'lib/legion/extensions/service_now/account/runners/account.rb', line 18

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

#list_accounts(sysparm_limit: 100, sysparm_offset: 0, sysparm_query: nil) ⇒ Object



11
12
13
14
15
16
# File 'lib/legion/extensions/service_now/account/runners/account.rb', line 11

def list_accounts(sysparm_limit: 100, sysparm_offset: 0, sysparm_query: nil, **)
  params = { sysparm_limit: sysparm_limit, sysparm_offset: sysparm_offset }
  params[:sysparm_query] = sysparm_query if sysparm_query
  resp = connection(**).get('/api/now/account', params)
  { accounts: resp.body['result'] }
end

#update_account(sys_id:, name: nil, phone: nil, email: nil) ⇒ Object



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

def (sys_id:, name: nil, phone: nil, email: nil, **)
  body = {}
  body[:name]  = name if name
  body[:phone] = phone if phone
  body[:email] = email if email
  resp = connection(**).patch("/api/now/account/#{sys_id}", body)
  { account: resp.body['result'] }
end