Class: Lifen::User
- Inherits:
-
Object
- Object
- Lifen::User
- Defined in:
- lib/lifen/user.rb
Constant Summary collapse
- @@create_lock =
Mutex.new
Class Method Summary collapse
Instance Method Summary collapse
- #client ⇒ Object
- #create(persisted_lifen_uuid: ->(user) {}, save_to_db: ->(user) {}) ⇒ Object
- #flows ⇒ Object
- #reload ⇒ Object
- #save ⇒ Object
- #settings ⇒ Object
- #status ⇒ Object
- #token ⇒ Object
- #token=(token) ⇒ Object
- #unread_messages ⇒ Object
Class Method Details
.find(uuid) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/lifen/user.rb', line 49 def self.find(uuid) json = application_client.get("docbook/api/thirdParty/person/#{uuid}") json[:uuid] = json["uuid"] json[:email] = json["emailAddress"] json[:first_name] = json["firstName"] json[:last_name] = json["lastName"] json[:profile_picture_url] = json["profilePicUrl"] new(json) end |
Instance Method Details
#client ⇒ Object
100 101 102 |
# File 'lib/lifen/user.rb', line 100 def client UserAuthenticatedClient.new(token) end |
#create(persisted_lifen_uuid: ->(user) {}, save_to_db: ->(user) {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lifen/user.rb', line 24 def create(persisted_lifen_uuid: ->(user) {}, save_to_db: ->(user) {}) params = {emailAddress: email, lastName: last_name, firstName: first_name, profilePicUrl: profile_picture_url} @@create_lock.synchronize do exisiting_uuid = persisted_lifen_uuid.call(self) if exisiting_uuid.nil? json = application_client.post("authentication/api/register/third_party", params) self.uuid = json["accountUuid"] else self.uuid = exisiting_uuid end save_to_db.call(self) end end |
#flows ⇒ Object
20 21 22 |
# File 'lib/lifen/user.rb', line 20 def flows Lifen::Flows.new(user: self).all end |
#reload ⇒ Object
61 62 63 |
# File 'lib/lifen/user.rb', line 61 def reload self.class.find(uuid) end |
#save ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/lifen/user.rb', line 65 def save params = {emailAddress: email, lastName: last_name, firstName: first_name, profilePicUrl: profile_picture_url} params[:uuid] = uuid json = application_client.put("docbook/api/thirdParty/person/", params) self.email = json["emailAddress"] self.first_name = json["firstName"] self.last_name = json["lastName"] self.profile_picture_url = json["profilePicUrl"] self end |
#settings ⇒ Object
96 97 98 |
# File 'lib/lifen/user.rb', line 96 def settings @settings ||= Lifen::Settings.new(user: self).reload end |
#status ⇒ Object
92 93 94 |
# File 'lib/lifen/user.rb', line 92 def status @status ||= Lifen::Status.new(user: self).reload end |
#token ⇒ Object
83 84 85 |
# File 'lib/lifen/user.rb', line 83 def token @token ||= Lifen::Token.new(user: self) end |
#token=(token) ⇒ Object
87 88 89 90 |
# File 'lib/lifen/user.rb', line 87 def token=(token) token.user = self @token = token end |
#unread_messages ⇒ Object
79 80 81 |
# File 'lib/lifen/user.rb', line 79 def status.unread end |