lib/lifen/user.rb in lifen-0.2.1 vs lib/lifen/user.rb in lifen-1.0.0
- old
+ new
@@ -1,49 +1,60 @@
module Lifen
- class User < Base
+ class User
+ include Virtus.model(finalize: false)
- attribute :uuid, String
- attribute :token, String
+ attribute :token, "Lifen::Token"#, default: proc { Lifen::Token.new() }
+ attribute :status, "Lifen::Status"
+ attribute :uuid, String
attribute :email, String
attribute :last_name, String
attribute :first_name, String
- attribute :unread_messages, Integer, default: 0
+ # def initialize(*args)
+ # self.token = Lifen::Token.new(user: self)
+ # self.status = Lifen::Status.new(user: self)
+
+ # super
+ # end
+
def flows
- Lifen::Flows.new(self).all
+ Lifen::Flows.new(user: self).all
end
- def create!
- authentication = Lifen::Authentication.new(user: self)
- authentication.register!
+ def create
+ params = {emailAddress: email, lastName: last_name, firstName: first_name}
- self.token = authentication.token
- self.uuid = authentication.uuid
+ json = application_client.post("authentication/api/register/third_party", params)
- self
+ self.uuid = json["accountUuid"]
end
- def refresh_token
- authentication = Lifen::Authentication.new(user: self)
- authentication.refresh_token
+ def unread_messages
+ status.unread
+ end
- self.token = authentication.token
+ def token
+ @token ||= Lifen::Token.new(user: self)
+ end
- self
+ def token=(token)
+ token.user = self
+ @token = token
end
- def refresh_unread_messages
- status = Lifen::Status.new(user: self)
- status.refresh
-
- self.unread_messages = status.unread
-
- self
+ def status
+ @status ||= Lifen::Status.new(user: self)
end
def client
UserAuthenticatedClient.new(token)
end
+
+ private
+
+ def application_client
+ @application_client ||= AppAuthenticatedClient.new
+ end
end
end
\ No newline at end of file