Class: TrophyApiClient::Admin::Points::AsyncBoostsClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ TrophyApiClient::Admin::Points::AsyncBoostsClient

Parameters:



132
133
134
# File 'lib/trophy_api_client/admin/points/boosts/client.rb', line 132

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientTrophyApiClient::AsyncRequestClient (readonly)



128
129
130
# File 'lib/trophy_api_client/admin/points/boosts/client.rb', line 128

def request_client
  @request_client
end

Instance Method Details

#archive(id:, request_options: nil) ⇒ Void

Archive a points boost by ID.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.admin.points.boosts.archive(id: "id")

Parameters:

Returns:

  • (Void)


223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/trophy_api_client/admin/points/boosts/client.rb', line 223

def archive(id:, request_options: nil)
  Async do
    @request_client.conn.delete 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: admin,
                                         request_options: request_options)}/points/boosts/#{id}"
    end
  end
end

#batch_archive(ids: nil, request_options: nil) ⇒ TrophyApiClient::ArchivePointsBoostsResponse

Archive multiple points boosts by ID.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.admin.points.boosts.batch_archive

Parameters:

Returns:



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/trophy_api_client/admin/points/boosts/client.rb', line 191

def batch_archive(ids: nil, request_options: nil)
  Async do
    response = @request_client.conn.delete 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 || {}), "ids": ids }.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: admin, request_options: request_options)}/points/boosts"
    end
    TrophyApiClient::ArchivePointsBoostsResponse.from_json(json_object: response.body)
  end
end

#create(system_key:, boosts:, request_options: nil) ⇒ TrophyApiClient::CreatePointsBoostsResponse

Create points boosts for multiple users.

Examples:

api = TrophyApiClient::Client.new(
  base_url: "https://api.example.com",
  environment: TrophyApiClient::Environment::PRODUCTION,
  api_key: "YOUR_API_KEY"
)
api.admin.points.boosts.create(system_key: "xp", boosts: [{ user_id: "user-123", name: "Double XP Weekend", start: "2024-01-01", end_: "2024-01-03", multiplier: 2 }, { user_id: "user-456", name: "Holiday Bonus", start: "2024-12-25", multiplier: 1.5, rounding: UP }])

Parameters:

  • system_key (String)

    The key of the points system to create boosts for.

  • boosts (Array<Hash>)

    Array of boosts to create. Maximum 1,000 boosts per request.Request of type Array<TrophyApiClient::Admin::Points::Boosts::CreatePointsBoostsRequestBoostsItem>, as a Hash

    • :user_id (String)

    • :name (String)

    • :start (String)

    • :end_ (String)

    • :multiplier (Float)

    • :rounding (TrophyApiClient::Admin::Points::Boosts::CreatePointsBoostsRequestBoostsItemRounding)

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

Returns:



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/trophy_api_client/admin/points/boosts/client.rb', line 155

def create(system_key:, boosts:, 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 || {}),
        systemKey: system_key,
        boosts: boosts
      }.compact
      req.url "#{@request_client.get_url(environment: admin, request_options: request_options)}/points/boosts"
    end
    TrophyApiClient::CreatePointsBoostsResponse.from_json(json_object: response.body)
  end
end