Class: CoachClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/coach_client/client.rb

Overview

A client to communicate with the CyberCoach service.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, path = '/') ⇒ CoachClient::Client

Creates a new client with the CyberCoach informations.

Parameters:

  • host (String)

    the host address

  • path (String) (defaults to: '/')

    the path to the resources



14
15
16
# File 'lib/coach_client/client.rb', line 14

def initialize(host, path = '/')
  @url = host + path
end

Instance Attribute Details

#urlString (readonly)

The URL of the CyberCoach service.

Returns:

  • (String)


7
8
9
# File 'lib/coach_client/client.rb', line 7

def url
  @url
end

Instance Method Details

#authenticated?(username, password) ⇒ Boolean

Returns whether the given credentials are valid.

Parameters:

  • username (String)
  • password (String)

Returns:

  • (Boolean)


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

def authenticated?(username, password)
  begin
    CoachClient::Request.get("#{@url}authenticateduser/",
                             username: username, password: password)
    true
  rescue CoachClient::Unauthorized
    false
  end
end

#get_partnership(user1, user2) ⇒ CoachClient::Partnership

Returns the partnership from the CyberCoach service.

Parameters:

Returns:



56
57
58
59
# File 'lib/coach_client/client.rb', line 56

def get_partnership(user1, user2)
  partnership = CoachClient::Partnership.new(self, user1, user2)
  partnership.update
end

#get_partnership_subscription(user1, user2, sport) ⇒ CoachClient::PartnershipSubscription

Returns the subscription of a partnership from the CyberCoach service.

Parameters:

Returns:



77
78
79
80
81
# File 'lib/coach_client/client.rb', line 77

def get_partnership_subscription(user1, user2, sport)
  partnership = CoachClient::Partnership.new(self, user1, user2)
  subscription = CoachClient::PartnershipSubscription.new(self, partnership, sport)
  subscription.update
end

#get_sport(sportname) ⇒ CoachClient::Sport

Returns the sport from the CyberCoach service.

Parameters:

  • sportname (String, Symbol)

Returns:



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

def get_sport(sportname)
  sport = CoachClient::Sport.new(self, sportname)
  sport.update
end

#get_user(username) ⇒ CoachClient::User

Returns the user from the CyberCoach service.

Parameters:

  • username (String)

Returns:



46
47
48
49
# File 'lib/coach_client/client.rb', line 46

def get_user(username)
  user = CoachClient::User.new(self, username)
  user.update
end

#get_user_subscription(user, sport) ⇒ CoachClient::UserSubscription

Returns the subscription of a user from the CyberCoach service.

Parameters:

Returns:



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

def get_user_subscription(user, sport)
  subscription = CoachClient::UserSubscription.new(self, user, sport)
  subscription.update
end