Class: CyberCoach::User
- Inherits:
-
Resource
- Object
- AbstractResource
- Resource
- CyberCoach::User
- 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
-
#date_created ⇒ Object
:attr: date_created The date it was created.
-
#email ⇒ Object
:attr: date_created The date it was created.
-
#password ⇒ Object
:attr: date_created The date it was created.
-
#privacy_level ⇒ Object
:attr: date_created The date it was created.
-
#real_name ⇒ Object
:attr: date_created The date it was created.
-
#username ⇒ Object
:attr: date_created The date it was created.
Attributes inherited from Resource
Attributes inherited from AbstractResource
Instance Method Summary collapse
-
#authentication ⇒ Object
Returns the authentication options for basic auth, to pass in CRUD methods of other resources.
-
#from_serializable(serializable) ⇒ Object
:category: Serialization.
-
#plural_name ⇒ Object
:category: Configuration.
-
#singular_name ⇒ Object
:category: Configuration.
-
#to_serializable ⇒ Object
:category: Serialization.
Methods included from PutCreateable
Methods included from Pageable
Methods inherited from Resource
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_created ⇒ Object
:attr: date_created The date it was created.
47 48 49 |
# File 'lib/cybercoach/user.rb', line 47 def date_created @date_created end |
#email ⇒ Object
:attr: date_created The date it was created.
47 48 49 |
# File 'lib/cybercoach/user.rb', line 47 def email @email end |
#password ⇒ Object
:attr: date_created The date it was created.
47 48 49 |
# File 'lib/cybercoach/user.rb', line 47 def password @password end |
#privacy_level ⇒ Object
: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_name ⇒ Object
:attr: date_created The date it was created.
47 48 49 |
# File 'lib/cybercoach/user.rb', line 47 def real_name @real_name end |
#username ⇒ Object
: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
#authentication ⇒ Object
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.
-
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_name ⇒ Object
:category: Configuration
Returns ‘users’.
132 133 134 |
# File 'lib/cybercoach/user.rb', line 132 def plural_name 'users' end |
#singular_name ⇒ Object
:category: Configuration
Returns ‘user’.
123 124 125 |
# File 'lib/cybercoach/user.rb', line 123 def singular_name 'user' end |
#to_serializable ⇒ Object
: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.
-
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 |