Class: Lifen::User

Inherits:
Object
  • Object
show all
Defined in:
lib/lifen/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find(uuid) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lifen/user.rb', line 27

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

#clientObject



78
79
80
# File 'lib/lifen/user.rb', line 78

def client
  UserAuthenticatedClient.new(token)
end

#createObject



19
20
21
22
23
24
25
# File 'lib/lifen/user.rb', line 19

def create
  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

#flowsObject



15
16
17
# File 'lib/lifen/user.rb', line 15

def flows
  Lifen::Flows.new(user: self).all
end

#reloadObject



39
40
41
# File 'lib/lifen/user.rb', line 39

def reload
  self.class.find(uuid)
end

#saveObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/lifen/user.rb', line 43

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

#settingsObject



74
75
76
# File 'lib/lifen/user.rb', line 74

def settings
  @settings ||= Lifen::Settings.new(user: self).reload
end

#statusObject



70
71
72
# File 'lib/lifen/user.rb', line 70

def status
  @status ||= Lifen::Status.new(user: self).reload
end

#tokenObject



61
62
63
# File 'lib/lifen/user.rb', line 61

def token
  @token ||= Lifen::Token.new(user: self)
end

#token=(token) ⇒ Object



65
66
67
68
# File 'lib/lifen/user.rb', line 65

def token=(token)
  token.user = self
  @token = token
end

#unread_messagesObject



57
58
59
# File 'lib/lifen/user.rb', line 57

def unread_messages
  status.unread
end