class CoachClient::PartnershipSubscription

A partnership subscription resource of the CyberCoach service.

Attributes

datesubscribed[R]

@return [Integer]

id[R]

@return [Integer]

partnership[RW]

@return [CoachClient::Partnership]

Public Class Methods

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

Creates a new partnership subscription.

@param [CoachClient::Client] client @param [String, CoachClient::Partnership] partnership @param [String, Symbol, CoachClient::Sport] sport @param [Integer] publicvisible @return [CoachClient::PartnershipSubscription]

Calls superclass method CoachClient::Subscription::new
# File lib/coach_client/partnership_subscription.rb, line 24
def initialize(client, partnership, sport, publicvisible: nil)
  super(client, sport, publicvisible: publicvisible)
  @partnership = if partnership.is_a?(CoachClient::Partnership)
                   partnership
                 else
                   uri = "partnerships/#{partnership}/"
                   users = CoachClient::Partnership.extract_users_from_uri(uri)
                   CoachClient::Partnership.new(client, *users)
                 end
end
path() click to toggle source

Returns the relative path to the partnership subscription resource.

@return [String] the relative path

# File lib/coach_client/partnership_subscription.rb, line 13
def self.path
  'partnerships/'
end

Public Instance Methods

delete() click to toggle source

Deletes the partnership subscription on the CyberCoach service.

@raise [CoachClient::NotFound] if the partnership subscription does not

exist

@raise [CoachClient::Unauthorized] if not authorized @return [true]

Calls superclass method CoachClient::Subscription#delete
# File lib/coach_client/partnership_subscription.rb, line 79
def delete
  begin
    super(@partnership.user1)
  rescue CoachClient::Exception
    super(@partnership.user2)
  end
end
save() click to toggle source

Saves the partnership subscription to the CyberCoach service.

The partnership 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 partnership subscription could not

be saved

@return [CoachClient::PartnershipSubscription] the saved partnership

subscription
Calls superclass method CoachClient::Subscription#save
# File lib/coach_client/partnership_subscription.rb, line 65
def save
  begin
    super(@partnership.user1)
  rescue CoachClient::Exception
    super(@partnership.user2)
  end
end
to_s() click to toggle source

Returns the string representation of the partnership subscription.

@return [String]

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

Updates the partnership 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 partnership subscription does not

exist

@return [CoachClient::PartnershipSubscription] the updated partnership

subscription
Calls superclass method CoachClient::Subscription#update
# File lib/coach_client/partnership_subscription.rb, line 45
def update(size: 20, start: 0, all: false)
  begin
    super(@partnership.user1, size: size, start: start, all: all)
  rescue CoachClient::Exception
    super(@partnership.user2, size: size, start: start, all: all)
  end
end
url() click to toggle source

Returns the URL of the partnership subscription.

@return [String] the url of the partnership subscription

# File lib/coach_client/partnership_subscription.rb, line 90
def url
  "#{@partnership.url}/#{@sport}"
end