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
-
#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 = '/') ⇒ CoachClient::Client
constructor
Creates a new client with the CyberCoach informations.
Constructor Details
#initialize(host, path = '/') ⇒ CoachClient::Client
Creates a new client with the CyberCoach informations.
14 15 16 |
# File 'lib/coach_client/client.rb', line 14 def initialize(host, path = '/') @url = host + path end |
Instance Attribute Details
#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.
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:: false end end |
#get_partnership(user1, user2) ⇒ CoachClient::Partnership
Returns the partnership from the CyberCoach service.
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.
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.
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.
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.
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 |