Class: CyberCoach::Subscription

Inherits:
Resource show all
Includes:
PutCreateable
Defined in:
lib/cybercoach/subscription.rb

Overview

A Subscription to a Sport is placed by a User or a Partnership and contains Entries.

Instance Attribute Summary collapse

Attributes inherited from Resource

#id

Attributes inherited from AbstractResource

#uri

Instance Method Summary collapse

Methods included from PutCreateable

included

Methods inherited from Resource

#create, #delete, #update

Methods inherited from AbstractResource

#deserialize, #initialize, #read, #serialize

Constructor Details

This class inherits a constructor from CyberCoach::AbstractResource

Instance Attribute Details

#date_createdObject

:attr: date_created The date it was created.



37
38
39
# File 'lib/cybercoach/subscription.rb', line 37

def date_created
  @date_created
end

#entriesObject

:attr: date_created The date it was created.



37
38
39
# File 'lib/cybercoach/subscription.rb', line 37

def entries
  @entries
end

#privacy_levelObject

:attr: date_created The date it was created.



37
38
39
# File 'lib/cybercoach/subscription.rb', line 37

def privacy_level
  @privacy_level
end

#sportObject

:attr: date_created The date it was created.



37
38
39
# File 'lib/cybercoach/subscription.rb', line 37

def sport
  @sport
end

#subscriberObject

:attr: date_created The date it was created.



37
38
39
# File 'lib/cybercoach/subscription.rb', line 37

def subscriber
  @subscriber
end

Instance Method Details

#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.

  • user|partnership

    A User or Partnership serializable of the subscriber.

  • sport

    A Sport serializable.

  • entries

    Entry serializables.

  • publicvisible

    The privacy level, see PrivacyLevel constants.

  • datesubscribed

    The date it was created.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 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

#plural_nameObject

:category: Configuration

Returns ‘subscriptions’.



118
119
120
# File 'lib/cybercoach/subscription.rb', line 118

def plural_name
  'subscriptions'
end

#resource_base_uriObject

:category: Configuration

Return the URI of its subscriber and sport.



127
128
129
# File 'lib/cybercoach/subscription.rb', line 127

def resource_base_uri
  "#{@subscriber.uri}#{@sport.name}/"
end

#singular_nameObject

:category: Configuration

Returns ‘subscription’.



109
110
111
# File 'lib/cybercoach/subscription.rb', line 109

def singular_name
  'subscription'
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.

  • user|partnership

    A User or Partnership serializable of the subscriber.

  • sport

    A Sport serializable.

  • publicvisible

    The privacy level, see PrivacyLevel constants.



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