Class: Stigg::Resources::V1::Credits::Consumption

Inherits:
Object
  • Object
show all
Defined in:
lib/stigg/resources/v1/credits/consumption.rb,
sig/stigg/resources/v1/credits/consumption.rbs

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Consumption

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Consumption.

Parameters:



87
88
89
# File 'lib/stigg/resources/v1/credits/consumption.rb', line 87

def initialize(client:)
  @client = client
end

Instance Method Details

#consume(amount:, currency_id:, customer_id:, idempotency_key:, created_at: nil, dimensions: nil, resource_id: nil, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Credits::ConsumptionConsumeResponse

Some parameter documentations has been truncated, see Models::V1::Credits::ConsumptionConsumeParams for more details.

Consumes a specified amount of credits directly from a customer wallet, with no feature mapping. Returns the optimistic balance.

Parameters:

  • amount (Float)

    Body param: The amount of credits to consume

  • currency_id (String)

    Body param: The credit currency to consume from (required)

  • customer_id (String)

    Body param: The customer to consume credits from (required)

  • idempotency_key (String)

    Body param: A unique key used to deduplicate the consumption (required)

  • created_at (Time)

    Body param: Optional timestamp the consumption is attributed to

  • dimensions (Hash{Symbol=>String, Float, Boolean})

    Body param: Optional dimensions describing the consumption

  • resource_id (String)

    Body param: Optional resource the consumption is attributed to

  • x_account_id (String)

    Header param: Account ID — optional when authenticating with a user JWT (Bearer

  • x_environment_id (String)

    Header param: Environment ID — required when authenticating with a user JWT (Bea

  • request_options (Stigg::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/stigg/resources/v1/credits/consumption.rb', line 39

def consume(params)
  parsed, options = Stigg::V1::Credits::ConsumptionConsumeParams.dump_request(params)
  header_params = {x_account_id: "x-account-id", x_environment_id: "x-environment-id"}
  @client.request(
    method: :post,
    path: "api/v1/credits/consumption",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Stigg::Models::V1::Credits::ConsumptionConsumeResponse,
    options: options
  )
end

#consume_async(consumptions:, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Credits::ConsumptionConsumeAsyncResponse

Some parameter documentations has been truncated, see Models::V1::Credits::ConsumptionConsumeAsyncParams for more details.

Consumes credits directly from customer wallets asynchronously. Consumptions are reconciled asynchronously into the credit balances.

Parameters:

Returns:

See Also:



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/stigg/resources/v1/credits/consumption.rb', line 71

def consume_async(params)
  parsed, options = Stigg::V1::Credits::ConsumptionConsumeAsyncParams.dump_request(params)
  header_params = {x_account_id: "x-account-id", x_environment_id: "x-environment-id"}
  @client.request(
    method: :post,
    path: "api/v1/credits/consumption/async",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Stigg::Models::V1::Credits::ConsumptionConsumeAsyncResponse,
    options: options
  )
end