Class: TrophyApiClient::AsyncPointsClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ TrophyApiClient::AsyncPointsClient

Parameters:



220
221
222
# File 'lib/trophy_api_client/points/client.rb', line 220

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientTrophyApiClient::AsyncRequestClient (readonly)



216
217
218
# File 'lib/trophy_api_client/points/client.rb', line 216

def request_client
  @request_client
end

Instance Method Details

#boosts(key:, include_finished: nil, request_options: nil) ⇒ Array<TrophyApiClient::PointsBoost>

Get all global boosts for a points system. Finished boosts are excluded by

default.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.points.boosts(key: "points-system-key", include_finished: true)

Parameters:

  • key (String)

    Key of the points system.

  • include_finished (Boolean) (defaults to: nil)

    When set to ‘true’, boosts that have finished (past their end date) will be included in the response. By default, finished boosts are excluded.

  • request_options (TrophyApiClient::RequestOptions) (defaults to: nil)

Returns:



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/trophy_api_client/points/client.rb', line 317

def boosts(key:, include_finished: nil, request_options: nil)
  Async do
    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["Tenant-ID"] = request_options.tenant_id unless request_options&.tenant_id.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      req.params = {
        **(request_options&.additional_query_parameters || {}),
        "includeFinished": include_finished
      }.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)}/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
end

#level_summary(key:, request_options: nil) ⇒ TrophyApiClient::POINTS_LEVEL_SUMMARY_RESPONSE

Get a breakdown of the number of users at each level in a points system.

Examples:

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

Parameters:

Returns:



396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/trophy_api_client/points/client.rb', line 396

def level_summary(key:, request_options: nil)
  Async do
    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["Tenant-ID"] = request_options.tenant_id unless request_options&.tenant_id.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)}/points/#{key}/level-summary"
    end
    parsed_json = JSON.parse(response.body)
    parsed_json&.map do |item|
      item = item.to_json
      TrophyApiClient::PointsLevelSummaryResponseItem.from_json(json_object: item)
    end
  end
end

#levels(key:, request_options: nil) ⇒ Array<TrophyApiClient::PointsLevel>

Get all levels for a points system.

Examples:

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

Parameters:

Returns:



357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/trophy_api_client/points/client.rb', line 357

def levels(key:, request_options: nil)
  Async do
    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["Tenant-ID"] = request_options.tenant_id unless request_options&.tenant_id.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)}/points/#{key}/levels"
    end
    parsed_json = JSON.parse(response.body)
    parsed_json&.map do |item|
      item = item.to_json
      TrophyApiClient::PointsLevel.from_json(json_object: item)
    end
  end
end

#summary(key:, user_attributes: nil, request_options: nil) ⇒ TrophyApiClient::POINTS_SUMMARY_RESPONSE

Get a breakdown of the number of users with points in each range.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.points.summary(key: "points-system-key", user_attributes: "plan-type:premium,region:us-east")

Parameters:

  • key (String)

    Key of the points system.

  • user_attributes (String) (defaults to: nil)

    Optional colon-delimited user attribute filters in the format attribute:value,attribute:value. Only users matching ALL specified attributes will be included in the points breakdown.

  • request_options (TrophyApiClient::RequestOptions) (defaults to: nil)

Returns:



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/trophy_api_client/points/client.rb', line 239

def summary(key:, user_attributes: nil, request_options: nil)
  Async do
    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["Tenant-ID"] = request_options.tenant_id unless request_options&.tenant_id.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      req.params = {
        **(request_options&.additional_query_parameters || {}),
        "userAttributes": user_attributes
      }.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)}/points/#{key}/summary"
    end
    parsed_json = JSON.parse(response.body)
    parsed_json&.map do |item|
      item = item.to_json
      TrophyApiClient::PointsRange.from_json(json_object: item)
    end
  end
end

#system(key:, request_options: nil) ⇒ TrophyApiClient::PointsSystemResponse

Get a points system with its triggers.

Examples:

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

Parameters:

Returns:



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/trophy_api_client/points/client.rb', line 279

def system(key:, request_options: nil)
  Async do
    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["Tenant-ID"] = request_options.tenant_id unless request_options&.tenant_id.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)}/points/#{key}"
    end
    TrophyApiClient::PointsSystemResponse.from_json(json_object: response.body)
  end
end