class CoachClient::UserSubscription

A user subscription resource of the CyberCoach service.

Attributes

datesubscribed[R]

@return [Integer]

id[R]

@return [Integer]

user[RW]

@return [CoachClient::User]

Public Class Methods

new(client, user, sport, publicvisible: nil) click to toggle source

Creates a new user subscription.

@param [CoachClient::Client] client @param [String, CoachClient::User] user @param [String, Symbol, CoachClient::Sport] sport @param [Integer] publicvisible @return [CoachClient::UserSubscription]

Calls superclass method CoachClient::Subscription::new
# 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
path() click to toggle source

Returns the relative path to the user subscription resource.

@return [String] the relative path

# File lib/coach_client/user_subscription.rb, line 13
def self.path
  'users/'
end

Public Instance Methods

delete() click to toggle source

Deletes the user subscription on the CyberCoach service.

@raise [CoachClient::NotFound] if the user subscription does not exist @raise [CoachClient::Unauthorized] if not authorized @return [true]

Calls superclass method CoachClient::Subscription#delete
# File lib/coach_client/user_subscription.rb, line 63
def delete
  super(@user)
end
save() click to toggle source

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.

@raise [CoachClient::Unauthorized] if not authorized @raise [CoachClient::IncompleteInformation] if not all needed information

is given

@raise [CoachClient::NotSaved] if the user subscription could not be saved @return [CoachClient::UserSubscription] the saved user subscription

Calls superclass method CoachClient::Subscription#save
# File lib/coach_client/user_subscription.rb, line 54
def save
  super(@user)
end
to_s() click to toggle source

Returns the string representation of the user subscription.

@return [String]

# File lib/coach_client/user_subscription.rb, line 77
def to_s
  "#{@user.username}/#{@sport}"
end
update(size: 20, start: 0, all: false) click to toggle source

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

@param [Integer] size the number of entries @param [Integer] start the start of entries list @param [Boolean] all whether all entries are retrieved @raise [CoachClient::NotFound] if the user subscription does not exist @return [CoachClient::UserSubscription] the updated user subscription

Calls superclass method CoachClient::Subscription#update
# 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
url() click to toggle source

Returns the URL of the user subscription.

@return [String] the url of the user subscription

# File lib/coach_client/user_subscription.rb, line 70
def url
  "#{@user.url}/#{@sport}"
end