Class: CoachClient::PartnershipSubscription

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

Overview

A partnership 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, partnership, sport, publicvisible: nil) ⇒ CoachClient::PartnershipSubscription

Creates a new partnership subscription.

Parameters:



24
25
26
27
28
29
30
31
32
33
# 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

Instance Attribute Details

#datesubscribedInteger (readonly)

Returns:

  • (Integer)


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

def datesubscribed
  @datesubscribed
end

#idInteger (readonly)

Returns:

  • (Integer)


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

def id
  @id
end

#partnershipCoachClient::Partnership



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

def partnership
  @partnership
end

Class Method Details

.pathString

Returns the relative path to the partnership subscription resource.

Returns:

  • (String)

    the relative path



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

def self.path
  'partnerships/'
end

Instance Method Details

#deletetrue

Deletes the partnership subscription on the CyberCoach service.

Returns:

  • (true)

Raises:



79
80
81
82
83
84
85
# File 'lib/coach_client/partnership_subscription.rb', line 79

def delete
  begin
    super(@partnership.user1)
  rescue CoachClient::Exception
    super(@partnership.user2)
  end
end

#saveCoachClient::PartnershipSubscription

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.

Returns:

Raises:



65
66
67
68
69
70
71
# File 'lib/coach_client/partnership_subscription.rb', line 65

def save
  begin
    super(@partnership.user1)
  rescue CoachClient::Exception
    super(@partnership.user2)
  end
end

#to_sString

Returns the string representation of the partnership subscription.

Returns:

  • (String)


97
98
99
# File 'lib/coach_client/partnership_subscription.rb', line 97

def to_s
  "#{@partnership}/#{@sport}"
end

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

Updates the partnership 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:



45
46
47
48
49
50
51
# 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

#urlString

Returns the URL of the partnership subscription.

Returns:

  • (String)

    the url of the partnership subscription



90
91
92
# File 'lib/coach_client/partnership_subscription.rb', line 90

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