class CyberCoach::User
A User
is needed to participate in Partnerships and Subscriptions, to which Entries are submitted.
Attributes
:attr: date_created
The date it was created.
The email address.
The password, which is never received from the server.
The privacy level, see PrivacyLevel
constants.
The real name.
The username.
Public Instance Methods
Returns the authentication options for basic auth, to pass in CRUD methods of other resources.
# File lib/cybercoach/user.rb, line 109 def authentication { basic_auth: { username: @username, password: @password } } end
Protected Instance Methods
CyberCoach::Resource#initializable_with
# File lib/cybercoach/user.rb, line 159 def initializable_with super + [:username, :email, :password, :real_name, :privacy_level] end
Configuration
↑ topPublic Instance Methods
Returns ‘users’.
# File lib/cybercoach/user.rb, line 132 def plural_name 'users' end
Returns ‘user’.
# File lib/cybercoach/user.rb, line 123 def singular_name 'user' end
Invalidation
↑ topProtected Instance Methods
Sets the basic auth token to the login, so it can be updated and deleted without explicitly specifying the token.
# File lib/cybercoach/user.rb, line 155 def invalidate_options @options = @options.merge(authentication) end
Sets the uri to the base uri and the username, if it is not nil.
# File lib/cybercoach/user.rb, line 143 def invalidate_uri unless @username.nil? @uri = "#{resource_base_uri}#{@username}/" end end
Serialization
↑ topPublic Instance Methods
Creates itself from a serializable representation, which only contains simple data types.
- serializable
-
A hash with the keys:
- uri
-
The URI.
- id
-
The identifier.
- username
-
The username.
-
The email address.
- realname
-
The real name.
- publicvisible
-
The privacy level, see
PrivacyLevel
constants.
- datecreated
-
The date it was created.
CyberCoach::Resource#from_serializable
# File lib/cybercoach/user.rb, line 68 def from_serializable(serializable) super(serializable) @username = serializable['username'] @email = serializable['email'] # the password is never received from the server, so don't set it @real_name = serializable['realname'] @privacy_level = serializable['publicvisible'] @date_created = nil unless serializable['datecreated'].nil? @date_created = Time.at(serializable['datecreated']).to_datetime end end
Returns a serializable representation, which only contains simple data types. The hash has the keys:
- uri
-
The URI.
- id
-
The identifier.
- username
-
The username.
-
The email address.
- realname
-
The real name.
- publicvisible
-
The privacy level, see
PrivacyLevel
constants.
- datecreated
-
The date it was created.
CyberCoach::Resource#to_serializable
# File lib/cybercoach/user.rb, line 95 def to_serializable serializable = super serializable['username'] = @username serializable['email'] = @email serializable['password'] = @password serializable['realname'] = @real_name serializable['publicvisible'] = @privacy_level serializable end