Class: TrophyApiClient::Admin::AsyncStreaksClient

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::AsyncStreaksClient

Parameters:



60
61
62
# File 'lib/trophy_api_client/admin/streaks/client.rb', line 60

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientTrophyApiClient::AsyncRequestClient (readonly)



56
57
58
# File 'lib/trophy_api_client/admin/streaks/client.rb', line 56

def request_client
  @request_client
end

Instance Method Details

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

Restore streaks for multiple users to the maximum length in the last 90 days (in

the case of daily streaks), one year (in the case of weekly streaks), or two
years (in the case of 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:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/trophy_api_client/admin/streaks/client.rb', line 79

def restore(users:, request_options: nil)
  Async do
    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
end