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:



63
64
65
# File 'lib/coach_client/user_subscription.rb', line 63

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:



54
55
56
# File 'lib/coach_client/user_subscription.rb', line 54

def save
  super(@user)
end

#to_sString

Returns the string representation of the user subscription.

Returns:

  • (String)


77
78
79
# File 'lib/coach_client/user_subscription.rb', line 77

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

#update(size: 20, start: 0, all: false) ⇒ CoachClient::UserSubscription

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

Parameters:

  • size (Integer) (defaults to: 20)

    the number of entries

  • start (Integer) (defaults to: 0)

    the start of entries list

  • all (Boolean) (defaults to: false)

    whether all entries are retrieved

Returns:

Raises:



40
41
42
# File 'lib/coach_client/user_subscription.rb', line 40

def update(size: 20, start: 0, all: false)
  super(@user, size: size, start: start, all: all)
end

#urlString

Returns the URL of the user subscription.

Returns:

  • (String)

    the url of the user subscription



70
71
72
# File 'lib/coach_client/user_subscription.rb', line 70

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