Class: CoachClient::Client
- Inherits:
-
Object
- Object
- CoachClient::Client
- Defined in:
- lib/coach_client/client.rb
Overview
A client to communicate with the CyberCoach service.
Instance Attribute Summary collapse
-
#max_size ⇒ Integer
The maximum size of the requests.
-
#url ⇒ String
readonly
The URL of the CyberCoach service.
Instance Method Summary collapse
-
#authenticated?(username, password) ⇒ Boolean
Returns whether the given credentials are valid.
-
#get_partnership(user1, user2) ⇒ CoachClient::Partnership
Returns the partnership from the CyberCoach service.
-
#get_partnership_subscription(user1, user2, sport) ⇒ CoachClient::PartnershipSubscription
Returns the subscription of a partnership from the CyberCoach service.
-
#get_sport(sportname) ⇒ CoachClient::Sport
Returns the sport from the CyberCoach service.
-
#get_user(username) ⇒ CoachClient::User
Returns the user from the CyberCoach service.
-
#get_user_subscription(user, sport) ⇒ CoachClient::UserSubscription
Returns the subscription of a user from the CyberCoach service.
-
#initialize(host, path = '/', max_size = 1000) ⇒ CoachClient::Client
constructor
Creates a new client with the CyberCoach informations.
Constructor Details
#initialize(host, path = '/', max_size = 1000) ⇒ CoachClient::Client
Creates a new client with the CyberCoach informations.
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_size ⇒ Integer
The maximum size of the requests
12 13 14 |
# File 'lib/coach_client/client.rb', line 12 def max_size @max_size end |
#url ⇒ String (readonly)
The URL of the CyberCoach service.
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.
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.
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.
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.
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.
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.
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 |