Class: CloudFS::User

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

Overview

User class maintains user profile information

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rest_adapter, **properties) ⇒ User

Returns a new instance of User.

Parameters:

  • rest_adapter (RestAdapter)

    cloudfs RESTful api object

  • properties (Hash)

    metadata of user

Options Hash (**properties):

  • :username (String)
  • :created_at (Fixnum)

    in milliseconds since epoch

  • :first_name (String)
  • :last_name (String)
  • :email (String)
  • :last_login (Fixnum)

    in milliseconds since epoch

  • :id (String)


68
69
70
71
72
73
74
# File 'lib/cloudfs/user.rb', line 68

def initialize(rest_adapter, ** properties)
  fail RestAdapter::Errors::ArgumentError,
       "invalid rest_adapter type #{rest_adapter.class}, expected CloudFS::Client" unless rest_adapter.is_a?(CloudFS::RestAdapter)

  @rest_adapter = rest_adapter
  set_user_info(** properties)
end

Instance Attribute Details

#created_atTime (readonly)

Returns account creation time.

Returns:

  • (Time)

    account creation time



41
42
43
44
45
46
47
# File 'lib/cloudfs/user.rb', line 41

def created_at
  if @properties[:created_at]
    Time.at(@properties[:created_at]/1000.0)
  else
    nil
  end
end

#emailString (readonly)

Returns email id of user.

Returns:

  • (String)

    email id of user



35
36
37
# File 'lib/cloudfs/user.rb', line 35

def email
  @properties[:email]
end

#first_nameString (readonly)

Returns first name of user.

Returns:

  • (String)

    first name of user



23
24
25
# File 'lib/cloudfs/user.rb', line 23

def first_name
  @properties[:first_name]
end

#idString (readonly)

Returns internal id of user.

Returns:

  • (String)

    internal id of user



11
12
13
# File 'lib/cloudfs/user.rb', line 11

def id
  @properties[:id]
end

#last_loginTime (readonly)

Returns last login time.

Returns:

  • (Time)

    last login time



51
52
53
54
55
56
57
# File 'lib/cloudfs/user.rb', line 51

def last_login
  if @properties[:last_login]
    Time.at(@properties[:last_login]/1000.0)
  else
    nil
  end
end

#last_nameString (readonly)

Returns last name of user.

Returns:

  • (String)

    last name of user



29
30
31
# File 'lib/cloudfs/user.rb', line 29

def last_name
  @properties[:last_name]
end

#usernameString (readonly)

Returns end-user's username.

Returns:

  • (String)

    end-user's username



17
18
19
# File 'lib/cloudfs/user.rb', line 17

def username
  @properties[:username]
end

Instance Method Details

#refreshUser

Refresh this user's metadata from server

Returns:

  • (User)

    returns self



88
89
90
91
92
# File 'lib/cloudfs/user.rb', line 88

def refresh
  response = @rest_adapter.get_profile
  set_user_info(** response)
  self
end