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 = '/', max_size = 1000) ⇒ 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

  • max_size (Integer) (defaults to: 1000)

    the maximum size of requests



20
21
22
23
# File 'lib/coach_client/client.rb', line 20

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

Instance Attribute Details

#max_sizeInteger

The maximum size of the requests

Returns:

  • (Integer)


12
13
14
# File 'lib/coach_client/client.rb', line 12

def max_size
  @max_size
end

#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)


30
31
32
33
34
35
36
37
38
# File 'lib/coach_client/client.rb', line 30

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:



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

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:



84
85
86
87
88
# File 'lib/coach_client/client.rb', line 84

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:



44
45
46
47
# File 'lib/coach_client/client.rb', line 44

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:



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

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:



73
74
75
76
# File 'lib/coach_client/client.rb', line 73

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