Class: CS::EndPoint::User
- Inherits:
-
Object
- Object
- CS::EndPoint::User
show all
- Includes:
- CS::EndPoint
- Defined in:
- lib/cs/end_point/user.rb
Instance Attribute Summary
Attributes included from CS::EndPoint
#session
Instance Method Summary
collapse
#create, #create!, #delete, #delete!, #duplicate, #inspect, #parameter, #reload!, #retrieve, #retrieve!, #save, #to_parameters, #update, #update!, #url_for
Methods included from Serializer
#from_hash, #to_h
Constructor Details
#initialize(hash = {}) ⇒ User
Returns a new instance of User.
14
15
16
17
18
19
|
# File 'lib/cs/end_point/user.rb', line 14
def initialize(hash={})
if hash[:password]
hash[:password] = Digest::MD5.hexdigest(hash[:password])
end
super(hash)
end
|
Instance Method Details
#current_user ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/cs/end_point/user.rb', line 29
def current_user
res = session.get('/users/current.json', )
return nil unless res && res["user"]
from_hash(res["user"])
self
end
|
#groups ⇒ Object
get groups that this users belongs to
47
48
49
50
51
|
# File 'lib/cs/end_point/user.rb', line 47
def groups
group = Group.new
group.session = session
group.groups
end
|
#password=(plain_text) ⇒ Object
21
22
23
|
# File 'lib/cs/end_point/user.rb', line 21
def password=(plain_text)
@password = Digest::MD5.hexdigest(plain_text)
end
|
#password_hashed=(hash) ⇒ Object
25
26
27
|
# File 'lib/cs/end_point/user.rb', line 25
def password_hashed=(hash)
self.password = hash
end
|
#reload ⇒ Object
37
38
39
|
# File 'lib/cs/end_point/user.rb', line 37
def reload
current_user
end
|
#save!(options = {}) ⇒ Object
41
42
43
44
|
# File 'lib/cs/end_point/user.rb', line 41
def save!(options={})
raise Error::ClientError, "No session found. use Client#new_user instead" unless @session
super(options)
end
|