Class: TrophyApiClient::AsyncLeaderboardsClient
- Inherits:
-
Object
- Object
- TrophyApiClient::AsyncLeaderboardsClient
- Defined in:
- lib/trophy_api_client/leaderboards/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#all(request_options: nil) ⇒ Array<TrophyApiClient::Leaderboards::LeaderboardsAllResponseItem>
Get all active leaderboards for your organization.
-
#get(key:, offset: nil, limit: nil, run: nil, user_id: nil, user_attributes: nil, request_options: nil) ⇒ TrophyApiClient::LeaderboardResponseWithRankings
Get a specific leaderboard by its key.
- #initialize(request_client:) ⇒ TrophyApiClient::AsyncLeaderboardsClient constructor
Constructor Details
#initialize(request_client:) ⇒ TrophyApiClient::AsyncLeaderboardsClient
116 117 118 |
# File 'lib/trophy_api_client/leaderboards/client.rb', line 116 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ TrophyApiClient::AsyncRequestClient (readonly)
112 113 114 |
# File 'lib/trophy_api_client/leaderboards/client.rb', line 112 def request_client @request_client end |
Instance Method Details
#all(request_options: nil) ⇒ Array<TrophyApiClient::Leaderboards::LeaderboardsAllResponseItem>
Get all active leaderboards for your organization.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/trophy_api_client/leaderboards/client.rb', line 131 def all(request_options: nil) Async do response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["X-API-KEY"] = .api_key unless &.api_key.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact unless .nil? || &.additional_query_parameters.nil? req.params = { **(&.additional_query_parameters || {}) }.compact end unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/leaderboards" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::Leaderboards::LeaderboardsAllResponseItem.from_json(json_object: item) end end end |
#get(key:, offset: nil, limit: nil, run: nil, user_id: nil, user_attributes: nil, request_options: nil) ⇒ TrophyApiClient::LeaderboardResponseWithRankings
Get a specific leaderboard by its key.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/trophy_api_client/leaderboards/client.rb', line 186 def get(key:, offset: nil, limit: nil, run: nil, user_id: nil, user_attributes: nil, request_options: nil) Async do response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["X-API-KEY"] = .api_key unless &.api_key.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "offset": offset, "limit": limit, "run": run, "userId": user_id, "userAttributes": user_attributes }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/leaderboards/#{key}" end TrophyApiClient::LeaderboardResponseWithRankings.from_json(json_object: response.body) end end |