Class: TrophyApiClient::UsersClient
- Inherits:
-
Object
- Object
- TrophyApiClient::UsersClient
- Defined in:
- lib/trophy_api_client/users/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#achievements(id:, include_incomplete: nil, request_options: nil) ⇒ Array<TrophyApiClient::UserAchievementWithStatsResponse>
Get a user’s achievements.
-
#all_metrics(id:, request_options: nil) ⇒ Array<TrophyApiClient::MetricResponse>
Get a single user’s progress against all active metrics.
-
#create(request:, request_options: nil) ⇒ TrophyApiClient::User
Create a new user.
-
#get(id:, request_options: nil) ⇒ TrophyApiClient::User
Get a single user.
-
#get_preferences(id:, request_options: nil) ⇒ TrophyApiClient::UserPreferencesResponse
Get a user’s notification preferences.
-
#identify(id:, request:, request_options: nil) ⇒ TrophyApiClient::User
Identify a user.
- #initialize(request_client:) ⇒ TrophyApiClient::UsersClient constructor
-
#leaderboard(id:, key:, run: nil, num_events: nil, request_options: nil) ⇒ TrophyApiClient::UserLeaderboardResponseWithHistory
Get a user’s rank, value, and history for a specific leaderboard.
-
#metric_event_summary(id:, key:, aggregation:, start_date:, end_date:, request_options: nil) ⇒ Array<TrophyApiClient::Users::UsersMetricEventSummaryResponseItem>
Get a summary of metric events over time for a user.
-
#points(id:, key:, awards: nil, request_options: nil) ⇒ TrophyApiClient::GetUserPointsResponse
Get a user’s points for a specific points system.
-
#points_boosts(id:, key:, request_options: nil) ⇒ Array<TrophyApiClient::PointsBoost>
Get active points boosts for a user in a specific points system.
-
#points_event_summary(id:, key:, aggregation:, start_date:, end_date:, request_options: nil) ⇒ Array<TrophyApiClient::Users::UsersPointsEventSummaryResponseItem>
Get a summary of points awards over time for a user for a specific points system.
-
#single_metric(id:, key:, request_options: nil) ⇒ TrophyApiClient::MetricResponse
Get a user’s progress against a single active metric.
-
#streak(id:, history_periods: nil, request_options: nil) ⇒ TrophyApiClient::StreakResponse
Get a user’s streak data.
-
#update(id:, request:, request_options: nil) ⇒ TrophyApiClient::User
Update a user.
-
#update_preferences(id:, notifications: nil, request_options: nil) ⇒ TrophyApiClient::UserPreferencesResponse
Update a user’s notification preferences.
-
#wrapped(id:, year: nil, request_options: nil) ⇒ TrophyApiClient::WrappedResponse
Get a user’s year-in-review wrapped data.
Constructor Details
#initialize(request_client:) ⇒ TrophyApiClient::UsersClient
30 31 32 |
# File 'lib/trophy_api_client/users/client.rb', line 30 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ TrophyApiClient::RequestClient (readonly)
26 27 28 |
# File 'lib/trophy_api_client/users/client.rb', line 26 def request_client @request_client end |
Instance Method Details
#achievements(id:, include_incomplete: nil, request_options: nil) ⇒ Array<TrophyApiClient::UserAchievementWithStatsResponse>
Get a user’s achievements.
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/trophy_api_client/users/client.rb', line 390 def achievements(id:, include_incomplete: 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["Tenant-ID"] = .tenant_id unless &.tenant_id.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "includeIncomplete": include_incomplete }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: )}/users/#{id}/achievements" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::UserAchievementWithStatsResponse.from_json(json_object: item) end end |
#all_metrics(id:, request_options: nil) ⇒ Array<TrophyApiClient::MetricResponse>
Get a single user’s progress against all active metrics.
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/trophy_api_client/users/client.rb', line 262 def all_metrics(id:, 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["Tenant-ID"] = .tenant_id unless &.tenant_id.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: )}/users/#{id}/metrics" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::MetricResponse.from_json(json_object: item) end end |
#create(request:, request_options: nil) ⇒ TrophyApiClient::User
Create a new user.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/trophy_api_client/users/client.rb', line 53 def create(request:, request_options: nil) response = @request_client.conn.post 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["Tenant-ID"] = .tenant_id unless &.tenant_id.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 req.body = { **(request || {}), **(&.additional_body_parameters || {}) }.compact req.url "#{@request_client.get_url(environment: api, request_options: )}/users" end TrophyApiClient::User.from_json(json_object: response.body) end |
#get(id:, request_options: nil) ⇒ TrophyApiClient::User
Get a single user.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/trophy_api_client/users/client.rb', line 84 def get(id:, 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["Tenant-ID"] = .tenant_id unless &.tenant_id.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: )}/users/#{id}" end TrophyApiClient::User.from_json(json_object: response.body) end |
#get_preferences(id:, request_options: nil) ⇒ TrophyApiClient::UserPreferencesResponse
Get a user’s notification preferences.
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/trophy_api_client/users/client.rb', line 193 def get_preferences(id:, 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["Tenant-ID"] = .tenant_id unless &.tenant_id.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: )}/users/#{id}/preferences" end TrophyApiClient::UserPreferencesResponse.from_json(json_object: response.body) end |
#identify(id:, request:, request_options: nil) ⇒ TrophyApiClient::User
Identify a user.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/trophy_api_client/users/client.rb', line 124 def identify(id:, request:, request_options: nil) response = @request_client.conn.put 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["Tenant-ID"] = .tenant_id unless &.tenant_id.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 req.body = { **(request || {}), **(&.additional_body_parameters || {}) }.compact req.url "#{@request_client.get_url(environment: api, request_options: )}/users/#{id}" end TrophyApiClient::User.from_json(json_object: response.body) end |
#leaderboard(id:, key:, run: nil, num_events: nil, request_options: nil) ⇒ TrophyApiClient::UserLeaderboardResponseWithHistory
Get a user’s rank, value, and history for a specific leaderboard.
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 |
# File 'lib/trophy_api_client/users/client.rb', line 606 def leaderboard(id:, key:, run: nil, num_events: 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["Tenant-ID"] = .tenant_id unless &.tenant_id.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "run": run, "numEvents": num_events }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: )}/users/#{id}/leaderboards/#{key}" end TrophyApiClient::UserLeaderboardResponseWithHistory.from_json(json_object: response.body) end |
#metric_event_summary(id:, key:, aggregation:, start_date:, end_date:, request_options: nil) ⇒ Array<TrophyApiClient::Users::UsersMetricEventSummaryResponseItem>
Get a summary of metric events over time for a user.
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/trophy_api_client/users/client.rb', line 346 def metric_event_summary(id:, key:, aggregation:, start_date:, end_date:, 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["Tenant-ID"] = .tenant_id unless &.tenant_id.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "aggregation": aggregation, "startDate": start_date, "endDate": end_date }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: )}/users/#{id}/metrics/#{key}/event-summary" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::Users::UsersMetricEventSummaryResponseItem.from_json(json_object: item) end end |
#points(id:, key:, awards: nil, request_options: nil) ⇒ TrophyApiClient::GetUserPointsResponse
Get a user’s points for a specific points system.
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/trophy_api_client/users/client.rb', line 471 def points(id:, key:, awards: 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["Tenant-ID"] = .tenant_id unless &.tenant_id.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "awards": awards }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: )}/users/#{id}/points/#{key}" end TrophyApiClient::GetUserPointsResponse.from_json(json_object: response.body) end |
#points_boosts(id:, key:, request_options: nil) ⇒ Array<TrophyApiClient::PointsBoost>
Get active points boosts for a user in a specific points system. Returns both
global boosts the user is eligible for and user-specific boosts.
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
# File 'lib/trophy_api_client/users/client.rb', line 505 def points_boosts(id:, key:, 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["Tenant-ID"] = .tenant_id unless &.tenant_id.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: )}/users/#{id}/points/#{key}/boosts" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::PointsBoost.from_json(json_object: item) end end |
#points_event_summary(id:, key:, aggregation:, start_date:, end_date:, request_options: nil) ⇒ Array<TrophyApiClient::Users::UsersPointsEventSummaryResponseItem>
Get a summary of points awards over time for a user for a specific points
system.
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 |
# File 'lib/trophy_api_client/users/client.rb', line 556 def points_event_summary(id:, key:, aggregation:, start_date:, end_date:, 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["Tenant-ID"] = .tenant_id unless &.tenant_id.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "aggregation": aggregation, "startDate": start_date, "endDate": end_date }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: )}/users/#{id}/points/#{key}/event-summary" end parsed_json = JSON.parse(response.body) parsed_json&.map do |item| item = item.to_json TrophyApiClient::Users::UsersPointsEventSummaryResponseItem.from_json(json_object: item) end end |
#single_metric(id:, key:, request_options: nil) ⇒ TrophyApiClient::MetricResponse
Get a user’s progress against a single active metric.
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/trophy_api_client/users/client.rb', line 300 def single_metric(id:, key:, 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["Tenant-ID"] = .tenant_id unless &.tenant_id.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: )}/users/#{id}/metrics/#{key}" end TrophyApiClient::MetricResponse.from_json(json_object: response.body) end |
#streak(id:, history_periods: nil, request_options: nil) ⇒ TrophyApiClient::StreakResponse
Get a user’s streak data.
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/trophy_api_client/users/client.rb', line 431 def streak(id:, history_periods: 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["Tenant-ID"] = .tenant_id unless &.tenant_id.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "historyPeriods": history_periods }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: )}/users/#{id}/streak" end TrophyApiClient::StreakResponse.from_json(json_object: response.body) end |
#update(id:, request:, request_options: nil) ⇒ TrophyApiClient::User
Update a user.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/trophy_api_client/users/client.rb', line 162 def update(id:, request:, request_options: nil) response = @request_client.conn.patch 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["Tenant-ID"] = .tenant_id unless &.tenant_id.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 req.body = { **(request || {}), **(&.additional_body_parameters || {}) }.compact req.url "#{@request_client.get_url(environment: api, request_options: )}/users/#{id}" end TrophyApiClient::User.from_json(json_object: response.body) end |
#update_preferences(id:, notifications: nil, request_options: nil) ⇒ TrophyApiClient::UserPreferencesResponse
Update a user’s notification preferences.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/trophy_api_client/users/client.rb', line 231 def update_preferences(id:, notifications: nil, request_options: nil) response = @request_client.conn.patch 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["Tenant-ID"] = .tenant_id unless &.tenant_id.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 req.body = { **(&.additional_body_parameters || {}), notifications: notifications }.compact req.url "#{@request_client.get_url(environment: api, request_options: )}/users/#{id}/preferences" end TrophyApiClient::UserPreferencesResponse.from_json(json_object: response.body) end |
#wrapped(id:, year: nil, request_options: nil) ⇒ TrophyApiClient::WrappedResponse
Get a user’s year-in-review wrapped data.
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
# File 'lib/trophy_api_client/users/client.rb', line 644 def wrapped(id:, year: 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["Tenant-ID"] = .tenant_id unless &.tenant_id.nil? req.headers = { **(req.headers || {}), **@request_client.get_headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "year": year }.compact unless .nil? || &.additional_body_parameters.nil? req.body = { **(&.additional_body_parameters || {}) }.compact end req.url "#{@request_client.get_url(environment: api, request_options: )}/users/#{id}/wrapped" end TrophyApiClient::WrappedResponse.from_json(json_object: response.body) end |