Module: Koa::LeaderboardClient
- 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
Class Method Details
.add_score(user_id, score) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/koa/leaderboard-client.rb', line 37 def self.add_score(user_id, score) Logger.measure_block("leaderboard-client.add-score") do 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 ) end end |
.get_leaderboards(limit) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/koa/leaderboard-client.rb', line 9 def self.get_leaderboards(limit) Logger.measure_block("leaderboard-client.get-leaderboards") do 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 end |
.get_user_scores(user_id) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/koa/leaderboard-client.rb', line 24 def self.get_user_scores(user_id) Logger.measure_block("leaderboard-client.get-user-scores") do response = Koa::Request.make( type: :get, url: URL + "/user_scores", data: {game_id: GAME_ID, user_id: user_id} ) if response.successful? user_scores = JSON.parse(response.body) end end end |