Class: CyberCoach::User

Inherits:
Resource show all
Includes:
Pageable, PutCreateable
Defined in:
lib/cybercoach/user.rb

Overview

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

Instance Attribute Summary collapse

Attributes inherited from Resource

#id

Attributes inherited from AbstractResource

#uri

Instance Method Summary collapse

Methods included from PutCreateable

included

Methods included from Pageable

included

Methods inherited from Resource

#create, #delete, #update

Methods inherited from AbstractResource

#deserialize, #initialize, #read, #resource_base_uri, #serialize

Constructor Details

This class inherits a constructor from CyberCoach::AbstractResource

Instance Attribute Details

#date_createdObject

:attr: date_created The date it was created.



47
48
49
# File 'lib/cybercoach/user.rb', line 47

def date_created
  @date_created
end

#emailObject

:attr: date_created The date it was created.



47
48
49
# File 'lib/cybercoach/user.rb', line 47

def email
  @email
end

#passwordObject

:attr: date_created The date it was created.



47
48
49
# File 'lib/cybercoach/user.rb', line 47

def password
  @password
end

#privacy_levelObject

:attr: date_created The date it was created.



47
48
49
# File 'lib/cybercoach/user.rb', line 47

def privacy_level
  @privacy_level
end

#real_nameObject

:attr: date_created The date it was created.



47
48
49
# File 'lib/cybercoach/user.rb', line 47

def real_name
  @real_name
end

#usernameObject

:attr: date_created The date it was created.



47
48
49
# File 'lib/cybercoach/user.rb', line 47

def username
  @username
end

Instance Method Details

#authenticationObject

Returns the authentication options for basic auth, to pass in CRUD methods of other resources.



109
110
111
112
113
114
115
116
# File 'lib/cybercoach/user.rb', line 109

def authentication
  {
    basic_auth: {
      username: @username,
      password: @password
    }
  }
end

#from_serializable(serializable) ⇒ Object

:category: Serialization

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.



68
69
70
71
72
73
74
75
76
77
78
79
# 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

#plural_nameObject

:category: Configuration

Returns ‘users’.



132
133
134
# File 'lib/cybercoach/user.rb', line 132

def plural_name
  'users'
end

#singular_nameObject

:category: Configuration

Returns ‘user’.



123
124
125
# File 'lib/cybercoach/user.rb', line 123

def singular_name
  'user'
end

#to_serializableObject

:category: Serialization

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.



95
96
97
98
99
100
101
102
103
# 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