Class: S2Netbox::Commands::Person

Inherits:
ApiRequest show all
Includes:
Helpers
Defined in:
lib/s2_netbox/commands/person.rb

Class Method Summary collapse

Methods included from Helpers

#blank?, included

Methods inherited from ApiRequest

build_command, build_params, command_for_method, command_map, map_attributes, method_missing, provides_command, respond_to_missing?, send_request, supported_operations

Class Method Details

.add(attributes = {}, access_levels = [], user_defined_fields = [], session_id = nil) ⇒ Object



4
5
6
# File 'lib/s2_netbox/commands/person.rb', line 4

def self.add(attributes={}, access_levels=[], user_defined_fields=[], session_id=nil)
  send_request('AddPerson', build_attributes(attributes, access_levels, user_defined_fields), session_id)
end

.build_access_level(hash, access_levels) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/s2_netbox/commands/person.rb', line 23

def self.build_access_level(hash, access_levels)
  unless access_levels.empty?
    hash['ACCESSLEVELS'] = {:singular_node_name => 'ACCESSLEVEL', :values => Array.wrap(access_levels)}
  end

  hash
end

.build_attributes(attributes, access_levels, user_defined_fields) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/s2_netbox/commands/person.rb', line 15

def self.build_attributes(attributes, access_levels, user_defined_fields)
  hash = map_attributes(attributes)
  hash = build_user_defined_fields(hash, user_defined_fields)
  hash = build_access_level(hash, access_levels)

  hash
end

.build_user_defined_fields(hash, user_defined_fields) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/s2_netbox/commands/person.rb', line 31

def self.build_user_defined_fields(hash, user_defined_fields)
  Array.wrap(user_defined_fields).each_with_index do |udf, index|
    hash["UDF#{index+1}"] = udf
  end

  hash
end

.modify(person_id, attributes = {}, access_levels = [], user_defined_fields = [], session_id = nil) ⇒ Object



8
9
10
11
12
13
# File 'lib/s2_netbox/commands/person.rb', line 8

def self.modify(person_id, attributes={}, access_levels=[], user_defined_fields=[], session_id=nil)
  person_attributes = build_attributes(attributes, access_levels, user_defined_fields)
  person_attributes['PERSONID'] = person_id

  send_request('ModifyPerson', person_attributes, session_id)
end