Class: TrophyApiClient::UsersClient

Inherits:
Object
  • Object
show all
Defined in:
lib/trophy_api_client/users/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ TrophyApiClient::UsersClient

Parameters:



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_clientTrophyApiClient::RequestClient (readonly)

Returns:



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.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.achievements(id: "userId", include_incomplete: "true")

Parameters:

  • ID of the user.

  • (defaults to: nil)

    When set to ‘true’, returns both completed and incomplete achievements for the user. When omitted or set to any other value, returns only completed achievements.

  • (defaults to: nil)

Returns:



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/trophy_api_client/users/client.rb', line 381

def achievements(id:, include_incomplete: nil, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    req.params = {
      **(request_options&.additional_query_parameters || {}),
      "includeIncomplete": include_incomplete
    }.compact
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(environment: api,
                                       request_options: 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.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.all_metrics(id: "userId")

Parameters:

  • ID of the user

  • (defaults to: nil)

Returns:



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/trophy_api_client/users/client.rb', line 256

def all_metrics(id:, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(environment: api, request_options: 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.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.create(request: { id: "user-id" })

Parameters:

  • The user object.Request of type TrophyApiClient::UpsertedUser, as a Hash

    • :id (String)

    • :email (String)

    • :name (String)

    • :tz (String)

    • :device_tokens (Array<String>)

    • :subscribe_to_emails (Boolean)

    • :attributes (Hash=> String)

  • (defaults to: nil)

Returns:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/trophy_api_client/users/client.rb', line 53

def create(request:, request_options: nil)
  response = @request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
    req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users"
  end
  TrophyApiClient::User.from_json(json_object: response.body)
end

#get(id:, request_options: nil) ⇒ TrophyApiClient::User

Get a single user.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.get(id: "userId")

Parameters:

  • ID of the user to get.

  • (defaults to: nil)

Returns:



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/trophy_api_client/users/client.rb', line 83

def get(id:, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(environment: api, request_options: 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.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.get_preferences(id: "user-123")

Parameters:

  • The user’s ID in your database.

  • (defaults to: nil)

Returns:



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/trophy_api_client/users/client.rb', line 189

def get_preferences(id:, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(environment: api, request_options: 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.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.identify(id: "id", request: { email: "[email protected]", tz: "Europe/London", attributes: { "department": "engineering", "role": "developer" } })

Parameters:

  • ID of the user to identify.

  • The user object.Request of type TrophyApiClient::UpdatedUser, as a Hash

    • :email (String)

    • :name (String)

    • :tz (String)

    • :device_tokens (Array<String>)

    • :subscribe_to_emails (Boolean)

    • :attributes (Hash=> String)

  • (defaults to: nil)

Returns:



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/trophy_api_client/users/client.rb', line 122

def identify(id:, request:, request_options: nil)
  response = @request_client.conn.put do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
    req.url "#{@request_client.get_url(environment: api, request_options: 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.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.leaderboard(
  id: "user-123",
  key: "weekly-words",
  run: "2025-01-15",
  num_events: 1
)

Parameters:

  • The user’s ID in your database.

  • Unique key of the leaderboard as set when created.

  • (defaults to: nil)

    Specific run date in YYYY-MM-DD format. If not provided, returns the current run.

  • (defaults to: nil)

    The number of events to return in the history array.

  • (defaults to: nil)

Returns:



592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
# File 'lib/trophy_api_client/users/client.rb', line 592

def leaderboard(id:, key:, run: nil, num_events: nil, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    req.params = {
      **(request_options&.additional_query_parameters || {}),
      "run": run,
      "numEvents": num_events
    }.compact
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(environment: api,
                                       request_options: 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.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.metric_event_summary(
  id: "userId",
  key: "words-written",
  aggregation: DAILY,
  start_date: "2024-01-01",
  end_date: "2024-01-31"
)

Parameters:

  • ID of the user.

  • Unique key of the metric.

  • The time period over which to aggregate the event data.

  • The start date for the data range in YYYY-MM-DD format. The startDate must be before the endDate, and the date range must not exceed 400 days.

  • The end date for the data range in YYYY-MM-DD format. The endDate must be after the startDate, and the date range must not exceed 400 days.

  • (defaults to: nil)

Returns:



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/trophy_api_client/users/client.rb', line 338

def metric_event_summary(id:, key:, aggregation:, start_date:, end_date:, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    req.params = {
      **(request_options&.additional_query_parameters || {}),
      "aggregation": aggregation,
      "startDate": start_date,
      "endDate": end_date
    }.compact
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(environment: api,
                                       request_options: 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.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.points(
  id: "userId",
  key: "points-system-key",
  awards: 1
)

Parameters:

  • ID of the user.

  • Key of the points system.

  • (defaults to: nil)

    The number of recent point awards to return.

  • (defaults to: nil)

Returns:



460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'lib/trophy_api_client/users/client.rb', line 460

def points(id:, key:, awards: nil, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    req.params = { **(request_options&.additional_query_parameters || {}), "awards": awards }.compact
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(environment: api,
                                       request_options: 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.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.points_boosts(id: "userId", key: "points-system-key")

Parameters:

  • ID of the user.

  • Key of the points system.

  • (defaults to: nil)

Returns:



493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'lib/trophy_api_client/users/client.rb', line 493

def points_boosts(id:, key:, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(environment: api,
                                       request_options: 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.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.points_event_summary(
  id: "userId",
  key: "points-system-key",
  aggregation: DAILY,
  start_date: "2024-01-01",
  end_date: "2024-01-31"
)

Parameters:

  • ID of the user.

  • Key of the points system.

  • The time period over which to aggregate the event data.

  • The start date for the data range in YYYY-MM-DD format. The startDate must be before the endDate, and the date range must not exceed 400 days.

  • The end date for the data range in YYYY-MM-DD format. The endDate must be after the startDate, and the date range must not exceed 400 days.

  • (defaults to: nil)

Returns:



543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
# File 'lib/trophy_api_client/users/client.rb', line 543

def points_event_summary(id:, key:, aggregation:, start_date:, end_date:, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    req.params = {
      **(request_options&.additional_query_parameters || {}),
      "aggregation": aggregation,
      "startDate": start_date,
      "endDate": end_date
    }.compact
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(environment: api,
                                       request_options: 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.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.single_metric(id: "userId", key: "key")

Parameters:

  • ID of the user.

  • Unique key of the metric.

  • (defaults to: nil)

Returns:



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/trophy_api_client/users/client.rb', line 293

def single_metric(id:, key:, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(environment: api,
                                       request_options: 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.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.streak(id: "userId", history_periods: 1)

Parameters:

  • ID of the user.

  • (defaults to: nil)

    The number of past streak periods to include in the streakHistory field of the response.

  • (defaults to: nil)

Returns:



421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/trophy_api_client/users/client.rb', line 421

def streak(id:, history_periods: nil, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    req.params = {
      **(request_options&.additional_query_parameters || {}),
      "historyPeriods": history_periods
    }.compact
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(environment: api, request_options: 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.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.update(id: "id", request: { email: "[email protected]", tz: "Europe/London", attributes: { "department": "engineering", "role": "developer" } })

Parameters:

  • ID of the user to update.

  • The user object.Request of type TrophyApiClient::UpdatedUser, as a Hash

    • :email (String)

    • :name (String)

    • :tz (String)

    • :device_tokens (Array<String>)

    • :subscribe_to_emails (Boolean)

    • :attributes (Hash=> String)

  • (defaults to: nil)

Returns:



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/trophy_api_client/users/client.rb', line 159

def update(id:, request:, request_options: nil)
  response = @request_client.conn.patch do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
    req.url "#{@request_client.get_url(environment: api, request_options: 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.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.update_preferences(id: "user-123", notifications: { streak_reminder: [EMAIL] })

Parameters:

  • The user’s ID in your database.

  • (defaults to: nil)

    Request of type TrophyApiClient::NotificationPreferences, as a Hash

    • :achievement_completed (Array<TrophyApiClient::NotificationChannel>)

    • :recap (Array<TrophyApiClient::NotificationChannel>)

    • :reactivation (Array<TrophyApiClient::NotificationChannel>)

    • :streak_reminder (Array<TrophyApiClient::NotificationChannel>)

  • (defaults to: nil)

Returns:



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/trophy_api_client/users/client.rb', line 226

def update_preferences(id:, notifications: nil, request_options: nil)
  response = @request_client.conn.patch do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = { **(request_options&.additional_body_parameters || {}), notifications: notifications }.compact
    req.url "#{@request_client.get_url(environment: api, request_options: 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.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.users.wrapped(id: "user-123", year: 1)

Parameters:

  • The user’s ID in your database.

  • (defaults to: nil)

    The year to get wrapped data for. Defaults to the current year. Must be an integer between 1 and the current year.

  • (defaults to: nil)

Returns:



629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/trophy_api_client/users/client.rb', line 629

def wrapped(id:, year: nil, request_options: nil)
  response = @request_client.conn.get do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    req.params = { **(request_options&.additional_query_parameters || {}), "year": year }.compact
    unless request_options.nil? || request_options&.additional_body_parameters.nil?
      req.body = { **(request_options&.additional_body_parameters || {}) }.compact
    end
    req.url "#{@request_client.get_url(environment: api, request_options: request_options)}/users/#{id}/wrapped"
  end
  TrophyApiClient::WrappedResponse.from_json(json_object: response.body)
end