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::LeaderboardResponse>
Get all active leaderboards for your organization.
-
#get(key:, offset: nil, limit: nil, run: nil, user_id: 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
108 109 110 |
# File 'lib/trophy_api_client/leaderboards/client.rb', line 108 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ TrophyApiClient::AsyncRequestClient (readonly)
104 105 106 |
# File 'lib/trophy_api_client/leaderboards/client.rb', line 104 def request_client @request_client end |
Instance Method Details
#all(request_options: nil) ⇒ Array<TrophyApiClient::LeaderboardResponse>
Get all active leaderboards for your organization.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/trophy_api_client/leaderboards/client.rb', line 123 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: )}/leaderboards" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::LeaderboardResponse.from_json(json_object: item) end end end |
#get(key:, offset: nil, limit: nil, run: nil, user_id: nil, request_options: nil) ⇒ TrophyApiClient::LeaderboardResponseWithRankings
Get a specific leaderboard by its key.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/trophy_api_client/leaderboards/client.rb', line 171 def get(key:, offset: nil, limit: nil, run: nil, user_id: 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 }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: )}/leaderboards/#{key}" end TrophyApiClient::LeaderboardResponseWithRankings.from_json(json_object: response.body) end end |