Class: CloudhouseGuardian::User

Inherits:
BaseObject show all
Defined in:
lib/cloudhouse_guardian/User.rb

Instance Attribute Summary collapse

Attributes inherited from BaseObject

#appliance_api_key, #appliance_url, #insecure, #sec_key

Instance Method Summary collapse

Methods inherited from BaseObject

#http_delete, #http_get, #http_post, #http_put, #make_headers

Constructor Details

#initialize(appliance_url, appliance_api_key, sec_key, insecure = false) ⇒ User

Returns a new instance of User.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cloudhouse_guardian/User.rb', line 12

def initialize(appliance_url, appliance_api_key, sec_key, insecure = false)
  super(appliance_url, appliance_api_key, sec_key, insecure)
  self.id = nil
  self.name = nil
  self.surname = nil
  self.email = nil
  self.role = nil
  self.invited = nil
  self. = nil
  self.expiry = nil
  self.external_id = nil
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



6
7
8
# File 'lib/cloudhouse_guardian/User.rb', line 6

def email
  @email
end

#expiryObject

Returns the value of attribute expiry.



10
11
12
# File 'lib/cloudhouse_guardian/User.rb', line 10

def expiry
  @expiry
end

#external_idObject

Returns the value of attribute external_id.



11
12
13
# File 'lib/cloudhouse_guardian/User.rb', line 11

def external_id
  @external_id
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/cloudhouse_guardian/User.rb', line 3

def id
  @id
end

#invitedObject

Returns the value of attribute invited.



8
9
10
# File 'lib/cloudhouse_guardian/User.rb', line 8

def invited
  @invited
end

#last_sign_in_atObject

Returns the value of attribute last_sign_in_at.



9
10
11
# File 'lib/cloudhouse_guardian/User.rb', line 9

def 
  @last_sign_in_at
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/cloudhouse_guardian/User.rb', line 4

def name
  @name
end

#roleObject

Returns the value of attribute role.



7
8
9
# File 'lib/cloudhouse_guardian/User.rb', line 7

def role
  @role
end

#surnameObject

Returns the value of attribute surname.



5
6
7
# File 'lib/cloudhouse_guardian/User.rb', line 5

def surname
  @surname
end

Instance Method Details

#from_hash(h) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cloudhouse_guardian/User.rb', line 25

def from_hash(h)
  self.id = h['id'] if h.include?('id')
  self.name = h['name'] if h.include?('name')
  self.surname = h['surname'] if h.include?('surname')
  self.email = h['email'] if h.include?('email')
  self.role = h['role'] if h.include?('role')
  self.invited = h['invited'] if h.include?('invited')
  self. = h['last_sign_in_at'] if h.include?('last_sign_in_at')
  self.expiry = h['expiry'] if h.include?('expiry')
  self.external_id = h['external_id'] if h.include?('external_id')
end

#saveObject



60
61
62
63
64
65
66
# File 'lib/cloudhouse_guardian/User.rb', line 60

def save
  if self.id.to_i == 0
    raise "Cannot create a User"
  else
    return update
  end
end

#to_hashObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cloudhouse_guardian/User.rb', line 36

def to_hash
  h = {}
  h['id'] = self.id
  h['name'] = self.name
  h['surname'] = self.surname
  h['email'] = self.email
  h['role'] = self.role
  h['invited'] = self.invited
  h['last_sign_in_at'] = self.
  h['expiry'] = self.expiry
  h['external_id'] = self.external_id
  return h
end

#to_json(options = nil) ⇒ Object



49
50
51
52
# File 'lib/cloudhouse_guardian/User.rb', line 49

def to_json(options = nil)
  h = to_hash
  return h.to_json(options)
end

#updateObject



69
70
71
72
73
74
75
76
77
78
# File 'lib/cloudhouse_guardian/User.rb', line 69

def update
  h = to_hash
  h.delete("id")
  h.delete("email")
  h.delete("role")
  h.delete("invited")
  h.delete("last_sign_in_at")
  h.delete("expiry")
  http_put("/api/v2/users/#{self.id}.json", h)
end

#update_role(role) ⇒ Object



53
54
55
56
57
# File 'lib/cloudhouse_guardian/User.rb', line 53

def update_role(role)
  url = "/api/v2/users/update_role.json?role=#{role}"
  obj = http_put(url, nil)
  return obj
end