class CyberCoach::Subscription
A Subscription
to a Sport
is placed by a User
or a Partnership
and contains Entries.
Attributes
:attr: date_created
The date it was created.
The Entries already placed by the subscriber.
The privacy level, see PrivacyLevel
constants.
The Sport
.
Either a User
or a Partnership
, which places Entries to it.
Protected Instance Methods
CyberCoach::Resource#initializable_with
# File lib/cybercoach/subscription.rb, line 145 def initializable_with super + [:subscriber, :sport, :privacy_level] end
Configuration
↑ topPublic Instance Methods
Returns ‘subscriptions’.
# File lib/cybercoach/subscription.rb, line 118 def plural_name 'subscriptions' end
Return the URI of its subscriber and sport.
# File lib/cybercoach/subscription.rb, line 127 def resource_base_uri "#{@subscriber.uri}#{@sport.name}/" end
Returns ‘subscription’.
# File lib/cybercoach/subscription.rb, line 109 def singular_name 'subscription' end
Invalidation
↑ topProtected Instance Methods
Sets the uri to the base uri if neither the subscriber, nor the sport is nil.
# File lib/cybercoach/subscription.rb, line 139 def invalidate_uri unless @subscriber.nil? || @sport.nil? @uri = resource_base_uri 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.
- user|partnership
-
A
User
orPartnership
serializable of the subscriber.
- sport
-
A
Sport
serializable.
- entries
-
Entry
serializables.
- publicvisible
-
The privacy level, see
PrivacyLevel
constants.
- datesubscribed
-
The date it was created.
CyberCoach::Resource#from_serializable
# File lib/cybercoach/subscription.rb, line 53 def from_serializable(serializable) super(serializable) @subscriber = nil unless serializable['user'].nil? @subscriber = User.new @subscriber.from_serializable(serializable['user']) end unless serializable['partnership'].nil? @subscriber = Partnership.new @subscriber.from_serializable(serializable['partnership']) end @sport = nil unless serializable['sport'].nil? @sport = Sport.new @sport.from_serializable(serializable['sport']) end @entries = [] unless serializable['entries'].nil? @entries = serializable['entries'].map do |entry_serializable| entry = Entry.new entry.from_serializable(entry_serializable) entry end end @privacy_level = serializable['publicvisible'] @date_created = nil unless serializable['datesubscribed'].nil? @date_created = Time.at(serializable['datesubscribed']).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.
- user|partnership
-
A
User
orPartnership
serializable of the subscriber.
- sport
-
A
Sport
serializable.
- publicvisible
-
The privacy level, see
PrivacyLevel
constants.
CyberCoach::Resource#to_serializable
# File lib/cybercoach/subscription.rb, line 96 def to_serializable serializable = super serializable[@subscriber.singular_name] = @subscriber.to_serializable serializable['sport'] = @sport.to_serializable serializable['publicvisible'] = @privacy_level serializable end