Class: TrophyApiClient::Admin::StreaksClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ TrophyApiClient::Admin::StreaksClient

Parameters:



16
17
18
# File 'lib/trophy_api_client/admin/streaks/client.rb', line 16

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientTrophyApiClient::RequestClient (readonly)



12
13
14
# File 'lib/trophy_api_client/admin/streaks/client.rb', line 12

def request_client
  @request_client
end

Instance Method Details

#restore(users:, request_options: nil) ⇒ TrophyApiClient::RestoreStreaksResponse

Restore streaks for multiple users to the maximum previously achieved streak

length found within the current restore window: the last 90 days for daily
streaks, weekly periods starting with the week containing the start of the
current calendar year for weekly streaks, and monthly periods starting at the
beginning of the previous calendar year for monthly streaks.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.admin.streaks.restore(users: [{ id: "user-123" }, { id: "user-456" }])

Parameters:

  • users (Array<Hash>)

    Array of users to restore streaks for. Maximum 100 users per request.Request of type Array<TrophyApiClient::Admin::Streaks::RestoreStreaksRequestUsersItem>, as a Hash

    • :id (String)

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

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/trophy_api_client/admin/streaks/client.rb', line 37

def restore(users:, 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_options&.additional_body_parameters || {}), users: users }.compact
    req.url "#{@request_client.get_url(environment: admin, request_options: request_options)}/streaks/restore"
  end
  TrophyApiClient::RestoreStreaksResponse.from_json(json_object: response.body)
end