Class: TrophyApiClient::Admin::Points::BoostsClient

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

Parameters:



18
19
20
# File 'lib/trophy_api_client/admin/points/boosts/client.rb', line 18

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientTrophyApiClient::RequestClient (readonly)

Returns:



14
15
16
# File 'lib/trophy_api_client/admin/points/boosts/client.rb', line 14

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:

  • The UUID of the points boost to archive

  • (defaults to: nil)

Returns:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/trophy_api_client/admin/points/boosts/client.rb', line 105

def archive(id:, request_options: nil)
  @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

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

  • (defaults to: nil)

    A list of up to 100 boost IDs.

  • (defaults to: nil)

Returns:



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/trophy_api_client/admin/points/boosts/client.rb', line 75

def batch_archive(ids: nil, request_options: nil)
  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

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

  • The key of the points system to create boosts for.

  • 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)

  • (defaults to: nil)

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/trophy_api_client/admin/points/boosts/client.rb', line 41

def create(system_key:, boosts:, 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 || {}),
      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