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
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lifen/user.rb', line 48 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
99 100 101 |
# File 'lib/lifen/user.rb', line 99 def client UserAuthenticatedClient.new(token) end |
#create(persisted_lifen_uuid: ->(user) {}, save_to_db: ->(user) {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lifen/user.rb', line 23 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
19 20 21 |
# File 'lib/lifen/user.rb', line 19 def flows Lifen::Flows.new(user: self).all end |
#reload ⇒ Object
60 61 62 |
# File 'lib/lifen/user.rb', line 60 def reload self.class.find(uuid) end |
#save ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/lifen/user.rb', line 64 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
95 96 97 |
# File 'lib/lifen/user.rb', line 95 def settings @settings ||= Lifen::Settings.new(user: self).reload end |
#status ⇒ Object
91 92 93 |
# File 'lib/lifen/user.rb', line 91 def status @status ||= Lifen::Status.new(user: self).reload end |
#token ⇒ Object
82 83 84 |
# File 'lib/lifen/user.rb', line 82 def token @token ||= Lifen::Token.new(user: self) end |
#token=(token) ⇒ Object
86 87 88 89 |
# File 'lib/lifen/user.rb', line 86 def token=(token) token.user = self @token = token end |
#unread_messages ⇒ Object
78 79 80 |
# File 'lib/lifen/user.rb', line 78 def status.unread end |