lib/lifen/user.rb in lifen-1.3.0 vs lib/lifen/user.rb in lifen-1.4.0

- old
+ new

@@ -8,23 +8,54 @@ attribute :uuid, String attribute :email, String attribute :last_name, String attribute :first_name, String + attribute :profile_picture_url, String def flows Lifen::Flows.new(user: self).all end def create - params = {emailAddress: email, lastName: last_name, firstName: first_name} + params = {emailAddress: email, lastName: last_name, firstName: first_name, profilePicUrl: profile_picture_url} json = application_client.post("authentication/api/register/third_party", params) self.uuid = json["accountUuid"] end + 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 + + def reload + self.class.find(uuid) + end + + 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 + def unread_messages status.unread end def token @@ -35,23 +66,27 @@ token.user = self @token = token end def status - @status ||= Lifen::Status.new(user: self) + @status ||= Lifen::Status.new(user: self).reload end def settings - @settings ||= Lifen::Settings.new(user: self).refresh + @settings ||= Lifen::Settings.new(user: self).reload end def client UserAuthenticatedClient.new(token) end private def application_client + @application_client ||= AppAuthenticatedClient.new + end + + def self.application_client @application_client ||= AppAuthenticatedClient.new end end end \ No newline at end of file