Module: Legion::Extensions::ServiceNow::Location::Runners::Location

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

Instance Method Summary collapse

Methods included from Helpers::Client

#connection, #fetch_oauth2_token, #handle_response

Instance Method Details

#create_location(name:, street: nil, city: nil, state: nil, country: nil, zip: nil, phone: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/legion/extensions/service_now/location/runners/location.rb', line 23

def create_location(name:, street: nil, city: nil, state: nil,
                    country: nil, zip: nil, phone: nil, **)
  body = { name: name }
  body[:street]  = street if street
  body[:city]    = city if city
  body[:state]   = state if state
  body[:country] = country if country
  body[:zip]     = zip if zip
  body[:phone]   = phone if phone
  resp = connection(**).post('/api/now/table/cmn_location', body)
  { location: resp.body['result'] }
end

#delete_location(sys_id:) ⇒ Object



47
48
49
50
# File 'lib/legion/extensions/service_now/location/runners/location.rb', line 47

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

#get_location(sys_id:) ⇒ Object



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

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

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



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

def list_locations(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/table/cmn_location', params)
  { locations: resp.body['result'] }
end

#update_location(sys_id:, name: nil, street: nil, city: nil, country: nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/legion/extensions/service_now/location/runners/location.rb', line 36

def update_location(sys_id:, name: nil, street: nil, city: nil,
                    country: nil, **)
  body = {}
  body[:name]    = name if name
  body[:street]  = street if street
  body[:city]    = city if city
  body[:country] = country if country
  resp = connection(**).patch("/api/now/table/cmn_location/#{sys_id}", body)
  { location: resp.body['result'] }
end