class CyberCoach::User

A User is needed to participate in Partnerships and Subscriptions, to which Entries are submitted.

Attributes

date_created[RW]

:attr: date_created The date it was created.

email[RW]

The email address.

password[RW]

The password, which is never received from the server.

privacy_level[RW]

The privacy level, see PrivacyLevel constants.

real_name[RW]

The real name.

username[RW]

The username.

Public Instance Methods

authentication() click to toggle source

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

initializable_with() click to toggle source
Calls superclass method CyberCoach::Resource#initializable_with
# File lib/cybercoach/user.rb, line 159
def initializable_with
  super + [:username, :email, :password, :real_name, :privacy_level]
end

Configuration

↑ top

Public Instance Methods

plural_name() click to toggle source

Returns ‘users’.

# File lib/cybercoach/user.rb, line 132
def plural_name
  'users'
end
singular_name() click to toggle source

Returns ‘user’.

# File lib/cybercoach/user.rb, line 123
def singular_name
  'user'
end

Invalidation

↑ top

Protected Instance Methods

invalidate_options() click to toggle source

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
invalidate_uri() click to toggle source

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

↑ top

Public Instance Methods

from_serializable(serializable) click to toggle source

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.

  • email

    The email address.

  • realname

    The real name.

  • publicvisible

    The privacy level, see PrivacyLevel constants.

  • datecreated

    The date it was created.

Calls superclass method 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
to_serializable() click to toggle source

Returns a serializable representation, which only contains simple data types. The hash has the keys:

  • uri

    The URI.

  • id

    The identifier.

  • username

    The username.

  • email

    The email address.

  • realname

    The real name.

  • publicvisible

    The privacy level, see PrivacyLevel constants.

  • datecreated

    The date it was created.

Calls superclass method 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