Module: Koa::LeaderboardClient
- Includes:
- Measurement
- Defined in:
- lib/koa/leaderboard-client.rb
Constant Summary collapse
Class Method Summary collapse
- .add_score(user_id, score) ⇒ Object
- .get_leaderboards(limit) ⇒ Object
- .get_user_scores(user_id) ⇒ Object
Methods included from Measurement
Class Method Details
.add_score(user_id, score) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/koa/leaderboard-client.rb', line 34 def self.add_score(user_id, score) response = Koa::Request.make( type: :put, url: URL + "/score", data: { user_id: user_id, score: score, request_id: SecureRandom.uuid, game_id: GAME_ID }, tries: 3, timeout: 5 ) JSON.parse(response.body)["scores"] if response.successful? end |
.get_leaderboards(limit) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/koa/leaderboard-client.rb', line 12 def self.get_leaderboards(limit) response = Koa::Request.make( type: :get, url: URL + "/boards", data: {limit: limit, game_id: GAME_ID} ) if response.successful? JSON.parse(response.body) else {} end end |
.get_user_scores(user_id) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/koa/leaderboard-client.rb', line 25 def self.get_user_scores(user_id) response = Koa::Request.make( type: :get, url: URL + "/user_scores", data: {game_id: GAME_ID, user_id: user_id} ) JSON.parse(response.body) if response.successful? end |