Class: CloudhouseGuardian::User
- Inherits:
-
BaseObject
- Object
- BaseObject
- CloudhouseGuardian::User
- Defined in:
- lib/cloudhouse_guardian/User.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#expiry ⇒ Object
Returns the value of attribute expiry.
-
#external_id ⇒ Object
Returns the value of attribute external_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#invited ⇒ Object
Returns the value of attribute invited.
-
#last_sign_in_at ⇒ Object
Returns the value of attribute last_sign_in_at.
-
#name ⇒ Object
Returns the value of attribute name.
-
#role ⇒ Object
Returns the value of attribute role.
-
#surname ⇒ Object
Returns the value of attribute surname.
Attributes inherited from BaseObject
#appliance_api_key, #appliance_url, #insecure, #sec_key
Instance Method Summary collapse
- #from_hash(h) ⇒ Object
-
#initialize(appliance_url, appliance_api_key, sec_key, insecure = false) ⇒ User
constructor
A new instance of User.
- #save ⇒ Object
- #to_hash ⇒ Object
- #to_json(options = nil) ⇒ Object
- #update ⇒ Object
- #update_role(role) ⇒ Object
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.last_sign_in_at = nil self.expiry = nil self.external_id = nil end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
6 7 8 |
# File 'lib/cloudhouse_guardian/User.rb', line 6 def email @email end |
#expiry ⇒ Object
Returns the value of attribute expiry.
10 11 12 |
# File 'lib/cloudhouse_guardian/User.rb', line 10 def expiry @expiry end |
#external_id ⇒ Object
Returns the value of attribute external_id.
11 12 13 |
# File 'lib/cloudhouse_guardian/User.rb', line 11 def external_id @external_id end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/cloudhouse_guardian/User.rb', line 3 def id @id end |
#invited ⇒ Object
Returns the value of attribute invited.
8 9 10 |
# File 'lib/cloudhouse_guardian/User.rb', line 8 def invited @invited end |
#last_sign_in_at ⇒ Object
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 @last_sign_in_at end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/cloudhouse_guardian/User.rb', line 4 def name @name end |
#role ⇒ Object
Returns the value of attribute role.
7 8 9 |
# File 'lib/cloudhouse_guardian/User.rb', line 7 def role @role end |
#surname ⇒ Object
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.last_sign_in_at = 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 |
#save ⇒ Object
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_hash ⇒ Object
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.last_sign_in_at 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( = nil) h = to_hash return h.to_json() end |
#update ⇒ Object
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 |