Class: TrophyApiClient::StreaksClient
- Inherits:
-
Object
- Object
- TrophyApiClient::StreaksClient
- Defined in:
- lib/trophy_api_client/streaks/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #initialize(request_client:) ⇒ TrophyApiClient::StreaksClient constructor
-
#list(user_ids: nil, request_options: nil) ⇒ TrophyApiClient::BULK_STREAK_RESPONSE
Get the streak lengths of a list of users, ranked by streak length from longest to shortest.
-
#rankings(limit: nil, type: nil, request_options: nil) ⇒ Array<TrophyApiClient::StreakRankingUser>
Get the top users by streak length (active or longest).
Constructor Details
#initialize(request_client:) ⇒ TrophyApiClient::StreaksClient
17 18 19 |
# File 'lib/trophy_api_client/streaks/client.rb', line 17 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ TrophyApiClient::RequestClient (readonly)
13 14 15 |
# File 'lib/trophy_api_client/streaks/client.rb', line 13 def request_client @request_client end |
Instance Method Details
#list(user_ids: nil, request_options: nil) ⇒ TrophyApiClient::BULK_STREAK_RESPONSE
Get the streak lengths of a list of users, ranked by streak length from longest
to shortest.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/trophy_api_client/streaks/client.rb', line 34 def list(user_ids: nil, request_options: nil) 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 || {}), "userIds": user_ids }.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)}/streaks" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::BulkStreakResponseItem.from_json(json_object: item) end end |
#rankings(limit: nil, type: nil, request_options: nil) ⇒ Array<TrophyApiClient::StreakRankingUser>
Get the top users by streak length (active or longest).
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/trophy_api_client/streaks/client.rb', line 69 def rankings(limit: nil, type: nil, request_options: nil) 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 || {}), "limit": limit, "type": type }.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)}/streaks/rankings" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::StreakRankingUser.from_json(json_object: item) end end |