Class: CoachClient::UserSubscription

Inherits:
Subscription show all
Defined in:
lib/coach_client/user_subscription.rb

Overview

A user subscription resource of the CyberCoach service.

Instance Attribute Summary collapse

Attributes inherited from Subscription

#entries, #publicvisible, #sport

Attributes inherited from Resource

#client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#exist?, #to_h

Constructor Details

#initialize(client, user, sport, publicvisible: nil) ⇒ CoachClient::UserSubscription

Creates a new user subscription.

Parameters:



24
25
26
27
28
29
30
31
# File 'lib/coach_client/user_subscription.rb', line 24

def initialize(client, user, sport, publicvisible: nil)
  super(client, sport, publicvisible: publicvisible)
  @user = if user.is_a?(CoachClient::User)
            user
          else
            CoachClient::User.new(client, user)
          end
end

Instance Attribute Details

#datesubscribedInteger (readonly)

Returns:

  • (Integer)


5
6
7
# File 'lib/coach_client/user_subscription.rb', line 5

def datesubscribed
  @datesubscribed
end

#idInteger (readonly)

Returns:

  • (Integer)


5
6
7
# File 'lib/coach_client/user_subscription.rb', line 5

def id
  @id
end

#userCoachClient::User

Returns:



8
9
10
# File 'lib/coach_client/user_subscription.rb', line 8

def user
  @user
end

Class Method Details

.pathString

Returns the relative path to the user subscription resource.

Returns:

  • (String)

    the relative path



13
14
15
# File 'lib/coach_client/user_subscription.rb', line 13

def self.path
  'users/'
end

Instance Method Details

#deletetrue

Deletes the user subscription on the CyberCoach service.

Returns:

  • (true)

Raises:



60
61
62
# File 'lib/coach_client/user_subscription.rb', line 60

def delete
  super(@user)
end

#saveCoachClient::UserSubscription

Saves the user subscription to the CyberCoach service.

The user subscription is created if it does not exist on the CyberCoach service, otherwise it tries to overwrite it.

Returns:

Raises:



51
52
53
# File 'lib/coach_client/user_subscription.rb', line 51

def save
  super(@user)
end

#to_sString

Returns the string representation of the user subscription.

Returns:

  • (String)


74
75
76
# File 'lib/coach_client/user_subscription.rb', line 74

def to_s
  "#{@user.username}/#{@sport}"
end

#updateCoachClient::UserSubscription

Updates the user subscription with the data from the CyberCoach service.

Returns:

Raises:



37
38
39
# File 'lib/coach_client/user_subscription.rb', line 37

def update
  super(@user)
end

#urlString

Returns the URL of the user subscription.

Returns:

  • (String)

    the url of the user subscription



67
68
69
# File 'lib/coach_client/user_subscription.rb', line 67

def url
  "#{@user.url}/#{@sport}"
end