Class: ServiceNow::User

Inherits:
Object
  • Object
show all
Defined in:
lib/classes/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ User

Returns a new instance of User.



4
5
6
# File 'lib/classes/user.rb', line 4

def initialize(attributes = {})
    @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, args = nil) ⇒ Object



58
59
60
61
# File 'lib/classes/user.rb', line 58

def method_missing(method, args = nil)
    method_name = method.to_s
    @attributes[method_name.to_sym]
end

Class Method Details

.find(netid) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/classes/user.rb', line 12

def self.find(netid)
    User.check_configuration
    query_hash = {}
    query_hash[:user_name] = netid
    response = Configuration.get_resource(query_hash = query_hash, table = "sys_user").get()
    hash = JSON.parse(response, { :symbolize_names => true })
    # there should be only one
    user = User.new(hash[:records][0])
    if user.attributes.nil?
        puts "SN::Alert: No user with netID: #{netid} found"
        return User.new
    else
        user
    end
end

.find_by_name(name) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/classes/user.rb', line 43

def self.find_by_name(name)
    User.check_configuration
    query_hash = {}
    query_hash[:name] = name
    response = Configuration.get_resource(query_hash = query_hash, table = "sys_user").get()
    hash = JSON.parse(response, { :symbolize_names => true })
    user = User.new(hash[:records][0])
    if user.attributes.nil?
        puts "SN::Alert: No user with user_name: #{name} found"
        return User.new
    else
        user
    end
end

.find_by_sys_id(sys_id) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/classes/user.rb', line 28

def self.find_by_sys_id(sys_id)
    User.check_configuration
    query_hash = {}
    query_hash[:sys_id] = sys_id
    response = Configuration.get_resource(query_hash = query_hash, table = "sys_user").get()
    hash = JSON.parse(response, { :symbolize_names => true })
    user = User.new(hash[:records][0])
    if user.attributes.nil?
        puts "SN::Alert: No user with sys_id: #{sys_id} found"
        return User.new
    else
        user
    end
end

Instance Method Details

#attributesObject



8
9
10
# File 'lib/classes/user.rb', line 8

def attributes
    @attributes
end